//Fileoutput int Gene::SaveGene(string InFilename) { if (InFilename.length() == 0) { InFilename = GetData("FILENAME",STRING); if (InFilename.length() == 0) { InFilename = GetData("DATABASE",STRING); if (InFilename.length() == 0) { return FAIL; } } } if (InFilename.substr(1,1).compare(":") != 0 && InFilename.substr(0,1).compare("/") != 0) { InFilename = GetDatabaseDirectory(GetParameter("database"),"new gene directory")+InFilename; } ofstream Output; if (!OpenOutput(Output,InFilename)) { return FAIL; } //First I check to see if the user specified that the input headers be printed in the output file vector<string>* FileHeader = StringToStrings(GetParameter("gene data to print"),";"); vector<string> InputHeaders; for (int i=0; i < int(FileHeader->size()); i++) { if ((*FileHeader)[i].compare("INPUT_HEADER") == 0) { InputHeaders = GetAllData("INPUT_HEADER",STRING); break; } } for (int i=0; i < int(InputHeaders.size()); i++) { string Data; Interpreter(InputHeaders[i],Data,false); Output << InputHeaders[i] << "\t" << Data << endl; } for (int i=0; i < int(FileHeader->size()); i++) { //I check to see if the current file header has already been printed to file if ((*FileHeader)[i].compare("INPUT_HEADER") != 0) { int j =0; for (j=0; j < int(InputHeaders.size()); j++) { if (InputHeaders[j].compare((*FileHeader)[i]) == 0) { break; } } if (j == int(InputHeaders.size())) { //If the current file header has not already been printed to file, it is printed now string Data; Interpreter((*FileHeader)[i],Data,false); if (Data.length() > 0) { Output << (*FileHeader)[i] << "\t" << Data << endl; } } } } Output.close(); return SUCCESS; }
ValuePtr UserFunction::exec (AgentPtr agent, TablePtr params) { switch (agent->getType()) { case Type::TURTLE: return TurtleInterpreter().interpret(*manager, agent, tree, params); case Type::WORLD: return WorldInterpreter().interpret(*manager, agent, tree, params); default: return Interpreter().interpret(*manager, agent, tree, params); } }
int Gene::LoadGene(string InFilename) { if (InFilename.length() == 0) { InFilename = GetData("FILENAME",STRING); if (InFilename.length() == 0) { InFilename = GetData("DATABASE",STRING); if (InFilename.length() == 0) { return FAIL; } } } if (InFilename.length() == 0) { return FAIL; } SetData("FILENAME",InFilename.data(),STRING); if (!FileExists(InFilename)) { InFilename = GetDatabaseDirectory(GetParameter("database"),"gene directory")+InFilename; if (!FileExists(InFilename)) { return FAIL; } } ifstream Input; if (!OpenInput(Input,InFilename)) { SetKill(true); return FAIL; } do { vector<string>* Strings = GetStringsFileline(Input,"\t"); if (Strings->size() >= 2) { //I save the input headings so I can print out the same headings when it's time to save the file AddData("INPUT_HEADER",(*Strings)[0].data(),STRING); for (int i=1; i < int(Strings->size()); i++) { Interpreter((*Strings)[0],(*Strings)[i],true); } } delete Strings; } while(!Input.eof()); if (GetData("DATABASE",STRING).length() == 0) { AddData("DATABASE",InFilename.data(),STRING); } if (MainData != NULL && MainData->GetData("DATABASE",STRING).length() > 0 && GetData("DATABASE",STRING).length() > 0) { AddData(MainData->GetData("DATABASE",STRING).data(),GetData("DATABASE",STRING).data(),DATABASE_LINK); } Input.close(); return SUCCESS; }
Data DebugSession::debugPrepare(const Data& data) { Data replyData; if (!data.hasKey("xml") && !data.hasKey("url")) { replyData.compound["status"] = Data("failure", Data::VERBATIM); replyData.compound["reason"] = Data("No XML or URL given", Data::VERBATIM); return replyData; } debugStop(data); _isAttached = false; try { if (data.hasKey("xml")) { _interpreter = Interpreter::fromXML(data.at("xml").atom, (data.hasKey("url") ? data.at("url").atom : "")); } else if (data.hasKey("url")) { _interpreter = Interpreter::fromURL(data.at("url").atom); } else { _interpreter = Interpreter(); } } catch(ErrorEvent e) { std::cerr << e; } catch(...) {} if (_interpreter) { // register ourself as a monitor _interpreter.addMonitor(_debugger); _debugger->attachSession(_interpreter.getImpl().get(), shared_from_this()); replyData.compound["status"] = Data("success", Data::VERBATIM); } else { replyData.compound["status"] = Data("failure", Data::VERBATIM); } return replyData; }
Data DebugSession::debugStop(const Data& data) { Data replyData; if (_interpreter) { // detach from old intepreter _debugger->detachSession(_interpreter.getImpl().get()); } if (_isRunning && _interpreterThread != NULL) { _isRunning = false; _interpreterThread->join(); delete(_interpreterThread); } // unblock _resumeCond.notify_all(); _skipTo = Breakpoint(); replyData.compound["status"] = Data("success", Data::VERBATIM); // calls destructor _interpreter = Interpreter(); return replyData; }