//********************************************************* SetType SetSquad(ifstream & fin, VecPlayerType & pVec,int num, MapSquadType & squadMap){ char type; string pName= ""; int pRow; int pCol; char direction; SetType squad; Player * p; BoardClass * bd= BoardClass::GetBd(); fin>> type; while(type != 'q' && fin){ fin>> pName; fin>> pRow; fin>> pCol; fin>> direction; p= CreaterPlayer(pName, type); bd->BoardClass::PlacePlayer(p, pRow, pCol); p->Active(); p->ResetMomentum(); p->DropWeapon(); p->SetDir(direction); pVec.push_back(p); squad.insert(pName); squadMap.insert(make_pair(p->Name(), SquadType(num))); fin>> type; } return squad; }
bool overwriteInSet(SetType& m, const typename SetType::value_type& v) { std::pair<typename SetType::iterator, bool> result = m.insert(v); if (!result.second) { typename SetType::value_type& theIt = const_cast<typename SetType::value_type&>(*(result.first)); theIt = v; } return result.second; }
SetType& prompt_set(std::string preface, std::string message = " Enter element for s2") { static SetType s2; s2.clear(); for (;;) { std::string e = ics::prompt_string(preface + message + "(QUIT to quit)"); if (e == "QUIT") break; s2.insert(e); } return s2; }
// if we ghave already fetched the rows because we recieved a // size message, return one of those rows. otherwise try to // get a unique row anf fail noisily if that seems not possible Row DSUnique :: Get() { if ( mPos >= 0 ) { Row r = mRows[ mPos++]; mPos %= mRows.size(); return Order( r ); } else { int n = mRetry; while( n-- ) { Row r = CompositeDataSource::Get(); if ( mUniqueRows.find( r ) == mUniqueRows.end() ) { mUniqueRows.insert( r ); return Order( r ); } } throw Exception( "cannot find enough unique values" ); } }
void process_tile_log(const char* filename) { ifstream infile(filename); char line[1024]; SetType uniqueSet; RetType ret; int repeatHitCounter = 0; int totalCounter = 0; cout << "==========================\n"; while ( infile.getline(line, 1024) ) { char* ptr = line; for (; *ptr != 'm' && *ptr != '\0'; ptr++) ; // cout << ptr << endl; if (*ptr) { totalCounter++; ret = uniqueSet.insert( string(ptr) ); if (!ret.second) { repeatHitCounter++; cout << "ERROR\t" << ptr << endl; } } if (totalCounter >= 100) { break; } // µ×ͼÍßƬÎÆÀí»º´æ×î¶à100¸ö£¡ } float rate = totalCounter > 0 ? (repeatHitCounter*1.0f / totalCounter) : 0; cout << "repeat hit rate = " << rate << endl; cout << "total hit = " << totalCounter << "\t" << "repeat hit = " << repeatHitCounter << endl; cout << "==========================\n"; infile.close(); uniqueSet.clear(); }
// if we receive size message read rows from kids discarding dupes // and use those rows to fufill future requests int DSUnique :: Size() { if ( mPos >= 0 ) { // already have size return mRows.size(); } int n = CompositeDataSource::Size(); while( n-- ) { Row r = CompositeDataSource::Get(); if ( mUniqueRows.find( r ) == mUniqueRows.end() ) { mUniqueRows.insert( r ); mRows.push_back( r ); } } //ALib::Dump( std::cout, mRows ); mPos = 0; if ( mRows.size() == 0 ) { throw Exception( "Empty result set" ); } return mRows.size(); }
void process_commands(std::string preface) { for (;;) try { std::string command = menu_prompt(preface); if (command == "i") { std::string e = ics::prompt_string(preface+" Enter element to add"); std::cout << preface+" insert = " << s.insert(e) << std::endl; } else if (command == "I") { SetType s2(prompt_set(preface)); std::cout << " insert = " << s.insert(s2.abegin(),s2.aend()) << std::endl;; } else if (command == "e") { std::string e = ics::prompt_string(preface+" Enter element to erase"); std::cout << preface+" erase = " << s.erase(e) << std::endl; } else if (command == "E") { SetType s2(prompt_set(preface)); std::cout << " erase = " << s.erase(s2.abegin(),s2.aend()) << std::endl;; } else if (command == "x") s.clear(); else if (command == "R") { SetType s2(prompt_set(preface)); std::cout << " retain = " << s.retain(s2.abegin(),s2.aend()) << std::endl; } else if (command == "=") { SetType s2(prompt_set(preface)); s = s2; std::cout << " s now = " << s << std::endl; } else if (command == "m") std::cout << preface+" empty = " << s.empty(); else if (command == "s") std::cout << preface+" size = " << s.size() << std::endl; else if (command == "c") { std::string e = ics::prompt_string(preface+" Enter element to erase"); std::cout << preface+" contains = " << s.contains(e) << std::endl; } else if (command == "C") { SetType s2(prompt_set(preface)); std::cout << " contains = " << s.contains(s2.abegin(),s2.aend()) << std::endl; } else if (command == "<") std::cout << preface+" << = " << s.str() << std::endl; else if (command == "r") { std::cout << preface+" s == s = " << (s == s) << std::endl; std::cout << preface+" s != s = " << (s != s) << std::endl; std::cout << preface+" s <= s = " << (s <= s) << std::endl; std::cout << preface+" s < s = " << (s < s) << std::endl; std::cout << preface+" s > s = " << (s > s) << std::endl; std::cout << preface+" s >= s = " << (s >= s) << std::endl; SetType s2(prompt_set(preface)); std::cout << preface+" s = " << s << " ?? s2 = " << s2 << std::endl; std::cout << preface+" s == s2 = " << (s == s2) << std::endl; std::cout << preface+" s != s2 = " << (s != s2) << std::endl; std::cout << preface+" s <= s2 = " << (s <= s2) << std::endl; std::cout << preface+" s < s2 = " << (s < s2) << std::endl; std::cout << preface+" s > s2 = " << (s > s2) << std::endl; std::cout << preface+" s >= s2 = " << (s >= s2) << std::endl; } else if (command == "l") { std::ifstream in_set; ics::safe_open(in_set,preface+" Enter file name to read", "load.txt"); std::string e; while (getline(in_set,e)) s.insert(e); in_set.close(); } else if (command == "it") process_iterator_commands(s, "it: "+preface); else if (command == "q") break; else std::cout << preface+"\""+command+"\" is unknown command" << std::endl; } catch (ics::IcsError& e) { std::cout << preface+" " << e.what() << std::endl; } };