/** * Parses the name and separates out the stuff before the brace, * the stuff inside it, and if present, the index which is also in a * brace. * Assume order is foo[index][insideBrace] */ void findBraceContent( const string& path, string& beforeBrace, string& insideBrace, unsigned int& index ) { beforeBrace = ""; insideBrace = ""; index = NOINDEX; if ( path.length() == 0 ) return; vector< string > names; separateString( path, names, "[" ); if ( names.size() == 0 ) return; if ( names.size() >= 1 ) beforeBrace = names[0]; if ( names.size() >= 2 ) { if ( names[1].find_first_not_of( " ]" ) == string::npos ) { index = Id::AnyIndex; } else { string n1 = names[1].substr( 0, names[1].length() - 1 ); if ( n1[0] >= '0' && n1[0] <= '9' ) { // An index index = atoi( n1.c_str() ); } else { // Some wildcard conditionals insideBrace = n1; } } } if ( names.size() >= 3 ) { insideBrace = names[2].substr( 0, names[2].length() - 1 ); } }
template<> bool str2val< vector< string > >( const string& s, vector< string >& ret ) { // cerr << "in str2val< double >\n"; separateString( s, ret, "," ); return 1; }
NobracketString::NobracketString(string expression) { // TODO Auto-generated constructor stub this->expression=expression; separateString(); simplifynumbers(); calculating(); formFinalAnser(); }
/** * Does the wildcard find on a single path */ static int innerFind( const string& path, vector< Id >& ret) { if ( path == "/" || path == "/root") { ret.push_back( Id() ); return 1; } vector< string > names; Id start; // set to root id. if ( path[0] == '/' ) { // separateString puts in a blank first entry if the first char // is a separator. separateString( path.substr( 1 ) , names, "/" ); } else { separateString( path, names, "/" ); bool ret = get( Id::shellId().eref(), "cwe", start ); assert( ret ); } return wildcardRelativeFind( start, names, 0, ret ); }
template<> bool str2val< vector<unsigned int> >( const string& s, vector<unsigned int>& ret ) { // cerr << "in str2val< vector<int> >\n"; vector<string> dims; separateString(s, dims, "]["); for (vector<string>::iterator ii = dims.begin(); ii != dims.end(); ++ii){ unsigned int index = strtol((*ii).c_str(), NULL, 0); ret.push_back(index); } return 1; }
/** * This is the basic wildcardFind function, working on a single * tree. It adds entries into the vector 'ret' with Ids found according * to the path string. It preserves the order of the returned Ids * as the order of elements traversed in the search. It does NOT * eliminate duplicates. This is a depth-first search. * Note that it does the dumb but backward compatible thing with * Ids of arrays: it lists every entry. * * It returns the number of Ids found here. */ int simpleWildcardFind( const string& path, vector<Id>& ret) { if ( path.length() == 0 ) return 0; unsigned int n = ret.size(); vector< string > wildcards; separateString( path, wildcards, "," ); vector< string >::iterator i; for ( i = wildcards.begin(); i != wildcards.end(); ++i ) innerFind( *i, ret ); return ret.size() - n; }
///////////////////////////////////////////////////////////////////////// // ProcInfo conversions ///////////////////////////////////////////////////////////////////////// template<> bool str2val< ProcInfo >( const string& s, ProcInfo &ret) { static ProcInfoBase pb; // thread-unsafe hack, but it should never be used anyway. vector< string > svec; separateString( s, svec, " " ); if ( svec.size() == 2 ) { pb.dt_ = atof( svec[0].c_str() ); pb.currTime_ = atof( svec[1].c_str() ); } else { pb.dt_ = 1.0; pb.currTime_ = 0.0; } ret = &pb; return 1; }
void EventDataManager::readDB() { string strFullPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("config/luckycat.sqlite"); CppSQLite3DB db; db.open(strFullPath.c_str()); if (!db.isOpen()) { return; } // CppSQLite3Query result = db.execQuery("select * from dict_event;"); // // std::vector<stEvent *> tEventVector; // while(!result.eof()) // { // stEvent *tEvent = new stEvent(); // tEvent->id = result.getIntField("id"); // tEvent->type = (LEventType)result.getIntField("type"); // tEvent->targetId = atoi(result.getStringField("target")); // std::string strBonus = result.getStringField("bonus"); // std::vector<int> tmpBonusList = separateStringToNumberVector(strBonus, ","); // // if (tmpBonusList.size() > 0) // CCAssert( tmpBonusList[0]*2 == tmpBonusList.size()-1, "Something error in sql field\n"); // for (int i = 1; tmpBonusList[0] != 0 && i+1 < tmpBonusList.size(); i+=2) { // stGood _good; // _good.id = tmpBonusList[i]; // _good.count = tmpBonusList[i+1]; // tEvent->bonus.push_back(_good); // } // // tEvent->bonusRepeat = result.getIntField("bonus_repeat"); // tEvent->nextEventId = result.getIntField("next_event_id"); // tEvent->box_id = result.getIntField("box_id"); // // tEventVector.push_back(tEvent); // // result.nextRow(); // } // // this->setEventMap(tEventVector); CppSQLite3Query result_1 = db.execQuery("select * from dict_npc_talk;"); std::vector<stTalk *> tTalkVector; while(!result_1.eof()) { stTalk *tTalk = new stTalk(); tTalk->id = result_1.getIntField("id"); tTalk->eventId = result_1.getIntField("event_id"); std::string _dialog= result_1.getStringField("content"); tTalk->dialogList = separateString(_dialog,"||"); tTalk->npcId = result_1.getIntField("npc_id"); tTalk->npcName = result_1.getStringField("npc_name"); tTalkVector.push_back(tTalk); result_1.nextRow(); } this->setTalkMap(tTalkVector); db.close(); }
void NobracketString::simplifynumbers(){ //maybe need to delete the object I create here. for(int i = 0; i<somenumbs.size();i++){ string tempnumb = somenumbs[i]; if(tempnumb.find("^")<100 && tempnumb.find("log")>100){ /////this lines needs to go into Exponent* power = new Exponent(somenumbs[i]); somenumbs[i]=power->getAnswer(); if(power->canSimplifyToInt()){ type.push_back("int"); }else if(power->canSimplifyToFrac()){ type.push_back("frac"); }else{ type.push_back("exp"); } } else if(tempnumb.find("rt")<100){ nthRoot* power = new nthRoot(somenumbs[i]); //will do the simplification in constructor. somenumbs[i]=power->getSimp(); //get a string type if(power->canSimplifytoInt()){ type.push_back("int"); } else if(power->canSimpifytoFrac()){ type.push_back("frac"); }else{ type.push_back("root"); } } else if(tempnumb.find("/")<100 && tempnumb.find("p")>100){ //im each value, if it contains /, Fraction* fra = new Fraction(somenumbs[i]); somenumbs[i]=fra->getAnswer(); //change the vector number to the simplify number. tempnumb = fra->getAnswer(); if(fra->canSimplifytoInteger()) { //if it simplifies to int type.push_back("int"); } // put "int" in the vector type; else{ type.push_back("frac"); } } else if(tempnumb.find("log")<100){ Logs* lg = new Logs(somenumbs[i]); somenumbs[i]=lg->getSimplify(); if(somenumbs[i]==expression){ //if user enter a log only and it cannot be simplify // expression = lg->FinalSplit(); //try split it; if(somenumbs[i]==expression){ //if the log cannot be split, do nothing. }else{ somenumbs.erase(somenumbs.begin()); type.clear(); separateString(); simplifynumbers(); } } if(lg->canSimplifytoInt()){ //check if it can be simplified type.push_back("int"); //if it simplifies to int, put "int" to vector type; } else if(lg->canSimplifytoFra()){ type.push_back("frac"); //else if it simplifies to fraction, put "fra" to vector type; }else{ type.push_back("log"); ////cout<<"in the log to log here"<<endl; } } else if(tempnumb.find("Pi")<100||tempnumb.find("pi")<100){ type.push_back("pi"); } else if(tempnumb.find("e")<100){ type.push_back("e"); }else{ type.push_back("int"); } } }