/*************************************************************************** zeta_mod.cpp - description ------------------- begin : Sat Mar 22 07:05:16 2003 copyright : (C) 2002 by Cavalli Andrea email : cavalli@bioc.unizh.ch **************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include ZETATOSTRING(vector::iterator); ZETATOSTRING(vector::iterator); ZETATOSTRING(vector::iterator); ZETATOSTRING(vector::iterator); ZETATOSTRING(vector::iterator); ZETATOSTRING(set::iterator); ZETATOSTRING(set::iterator); ZETATOSTRING(set::iterator); ZETATOSTRING(set::iterator); ZETATOSTRING(set::iterator); template to cast(from f){ return f;} string istr(int i){ return to_string(i); } double stof(string s){ return atof(s.c_str()); } int stoi(string s){ return atoi(s.c_str()); } string dstr(double d){ return to_string(d); } string modules(){ return SymbolTable::instance().modules(); } string types(){ return SymbolTable::instance().types(); } string type(ZObj * z){ return z->class_name(); } int counter(){ return ZObj::counter(); } int gc(){ return ZObj::counter(); } void help(string mod){ if(SymbolTable::instance().is_modulename(mod)){ ZModule * m = (ZModule *)SymbolTable::current()[mod]; m->print_symbols(); } else { cout< modules_list(){ vector res; SymbolTable::ZSymMap::iterator iter = SymbolTable::current().begin(), end = SymbolTable::current().end(); while(iter!=end){ if(SymbolTable::instance().is_modulename(iter->first)) res.push_back(iter->first); ++iter; } return res; } vector symbolic_constants(string mod){ vector res; if(SymbolTable::instance().is_modulename(mod)){ ZModule * m = (ZModule *)SymbolTable::current()[mod]; return m->symbolic_constants(); } return res; } vector functions(string mod){ vector res; if(SymbolTable::instance().is_modulename(mod)){ ZModule * m = (ZModule *)SymbolTable::current()[mod]; return m->functions(); } return res; } vector classes(string mod){ vector res; if(SymbolTable::instance().is_modulename(mod)){ ZModule * m = (ZModule *)SymbolTable::current()[mod]; return m->classes(); } return res; } string symbol_desc(string mod, string name){ string res; if(SymbolTable::instance().is_modulename(mod)){ ZModule * m = (ZModule *)SymbolTable::current()[mod]; return m->symbol_desc(name); } return res; } string symbol_doc(string mod, string name){ string res; if(SymbolTable::instance().is_modulename(mod)){ ZModule * m = (ZModule *)SymbolTable::current()[mod]; return m->symbol_doc(name); } return res; } void set_symbol_doc(string mod, string name, string doc){ if(SymbolTable::instance().is_modulename(mod)){ ZModule * m = (ZModule *)SymbolTable::current()[mod]; m->module_doc[name] = doc; } } string title(string mod){ string res; if(SymbolTable::instance().is_modulename(mod)){ ZModule * m = (ZModule *)SymbolTable::current()[mod]; return m->title; } return res; } string description(string mod){ string res; if(SymbolTable::instance().is_modulename(mod)){ ZModule * m = (ZModule *)SymbolTable::current()[mod]; map::iterator iter = m->module_desc.find("%desc"); if(iter!= m->module_desc.end()) return iter->second; } return res; } void set_description(string mod, string desc){ if(SymbolTable::instance().is_modulename(mod)){ ZModule * m = (ZModule *)SymbolTable::current()[mod]; m->module_desc["%desc"] = desc; } } void latex_index(string mod){ if(SymbolTable::instance().is_modulename(mod)){ ZModule * m = (ZModule *)SymbolTable::current()[mod]; m->print_index_latex(); } else { cout<first<<"\t"<second->class_name()<<"\n"; ++iter; } } ZObj * string_index(ZObj * o1, ZObj * o2){ int data2 = Data(o2); if(o1->is_reference()){ ZType *cl = dynamic_cast *>(o1); if(cl==NULL){ cout<<"Can't cast "<data.begin()+data2, cl->data.begin()+data2+1); return new ZType(tmp); } ZType *cl = dynamic_cast *>(o1); if(cl==NULL){ cout<<"Can't cast "<data.begin()+data2, cl->data.begin()+data2+1); return new ZType(tmp); } string load_file(std::string f ){ string s; ifstream is; is.open(f.c_str()); if(is.bad()) return s; s.reserve(is.rdbuf()->in_avail()); char c; while(is.get(c)) { if(s.capacity() == s.size()) s.reserve(s.capacity() * 3); s.append(1, c); } return s; } extern "C" { void init_zeta(){ Module("zeta","Built-in types and functions") .def_function("istr", "The istr() function converts an integer to a string", istr) .def_function("dstr", "The dstr() function converts double to a string", dstr) .def_function("atof","The atof() function converts a string to a double.",stof) .def_function("atoi","The atoi() function converts a string to an interger.",stoi) .def_function("modules", "The modules() function return a vector of string of loaded modules.", modules_list) .def_function("types", "The types() function return a vector of string of known types.", types) .def_function("type","The type(zobj) function returns the type of an object." ,type) .def_function("counter","The counter() function return the number of allocated zobjects.",counter) // .def_function("gc","The gc() function latches the garbage collector.", // gc) .def_function("help","Prints help for the specified modules.",help) .def_function("print_symbol_table", "Prints symbol table.",print_symbol_table) .def_function("print_index_latex", "Prints modules index in Latex format.", latex_index) .def_function("dtoi","Casts a double in an int",cast) .def_function("symbolic_constants","",symbolic_constants) .def_function("functions","",functions) .def_function("classes","",classes) .def_function("symbol_desc","",symbol_desc) .def_function("set_symbol_doc","",set_symbol_doc) .def_function("symbol_doc","",symbol_doc) .def_function("title","Return module title",title) .def_function("description","Resturns the module description string",description) .def_function("set_description","Sets the module description to the specified string", set_description) .def_function("load_file","Loads the content of a file to a string",load_file) ; ; //Base types Class("int"); Class("long"); Class("bool"); Class("double"); Class("float"); Class("string") .def_method("size",&string::size) ; ZObj::BinaryOperator::add_ifndef (string_index); Class >("file") .def_method("is_ok",&ZFile::is_ok) .def_method("eof",&ZFile::eof) .def_method("read",&ZFile::read) .def_method("getline",&ZFile::getline) .def_method("flush",&ZFile::flush) .def_method("close",&ZFile::close); // cout<<"Type id of double is "<::type_id()<("intvect"); init_vector_class("longvect"); init_vector_class("floatvect"); init_vector_class("doublevect"); init_vector_class("stringvect"); init_set_class("intset"); init_set_class("longset"); init_set_class("floatset"); init_set_class("doubleset"); init_set_class("stringset"); //Maps Class >("stringstringmap") .def_method("size",&map::size) .def_method("clear",&map::clear) ; ZObj::BinaryOperator::add_ifndef,string> (index_operator ,string,string &>); Class >("stringdoublemap") .def_method("size",&map::size) .def_method("clear",&map::clear) ; ZObj::BinaryOperator::add_ifndef,string> (index_operator ,string,double &>); Class >("stringfloatmap") .def_method("size",&map::size) .def_method("clear",&map::clear) ; ZObj::BinaryOperator::add_ifndef,string> (index_operator ,string,float &>); Class >("stringintmap") .def_method("size",&map::size) .def_method("clear",&map::clear) ; ZObj::BinaryOperator::add_ifndef,string> (index_operator ,string,int &>); } }