diff --git a/src/oastat.cpp b/src/oastat.cpp index 9e29ad3..aadd1a3 100644 --- a/src/oastat.cpp +++ b/src/oastat.cpp @@ -66,7 +66,7 @@ https://github.com/sago007/oastat/ std::vector clientIdMap; -static int processStdIn(std::istream &in_p,std::vector > &commands); +static int processStdIn(std::istream &in_p,std::vector > &commands); @@ -76,28 +76,28 @@ static int processStdIn(std::istream &in_p,std::vector &db,std::vector > &commands) +static void addCommands(std::shared_ptr &db,std::vector > &commands) { if (!db) { throw std::runtime_error("db was uninizialized in addCommands"); } //Add new commands here - commands.push_back(boost::shared_ptr(new Kill2Db() ) ); - commands.push_back(boost::shared_ptr(new Init2Db() ) ); - commands.push_back(boost::shared_ptr(new Shutdown2Db() ) ); - commands.push_back(boost::shared_ptr(new Userinfo2Db()) ); - commands.push_back(boost::shared_ptr(new Disconnect2Db()) ); - commands.push_back(boost::shared_ptr(new Award2Db()) ); - commands.push_back(boost::shared_ptr(new Ctf2Db()) ); - commands.push_back(boost::shared_ptr(new Point2Db()) ); - commands.push_back(boost::shared_ptr(new Ctf1f2Db()) ); - commands.push_back(boost::shared_ptr(new Elimination2Db()) ); - commands.push_back(boost::shared_ptr(new CtfElimination2Db()) ); - commands.push_back(boost::shared_ptr(new Harvester2Db()) ); - commands.push_back(boost::shared_ptr(new Challenge2Db()) ); - commands.push_back(boost::shared_ptr(new Warmup2Db()) ); - commands.push_back(boost::shared_ptr(new Accuracy2Db()) ); + commands.push_back(std::shared_ptr(new Kill2Db() ) ); + commands.push_back(std::shared_ptr(new Init2Db() ) ); + commands.push_back(std::shared_ptr(new Shutdown2Db() ) ); + commands.push_back(std::shared_ptr(new Userinfo2Db()) ); + commands.push_back(std::shared_ptr(new Disconnect2Db()) ); + commands.push_back(std::shared_ptr(new Award2Db()) ); + commands.push_back(std::shared_ptr(new Ctf2Db()) ); + commands.push_back(std::shared_ptr(new Point2Db()) ); + commands.push_back(std::shared_ptr(new Ctf1f2Db()) ); + commands.push_back(std::shared_ptr(new Elimination2Db()) ); + commands.push_back(std::shared_ptr(new CtfElimination2Db()) ); + commands.push_back(std::shared_ptr(new Harvester2Db()) ); + commands.push_back(std::shared_ptr(new Challenge2Db()) ); + commands.push_back(std::shared_ptr(new Warmup2Db()) ); + commands.push_back(std::shared_ptr(new Accuracy2Db()) ); //Add more commands just above here for (unsigned int i=0; i &db,std::vector > &commands) +static int processStdIn(std::istream &in_p, std::vector > &commands) { bool done = true; OaStatStruct *startstruct; @@ -135,20 +135,10 @@ static int processStdIn(std::istream &in_p, std::vectorgetCommand() << endl; if(commands.at(i)->canProcess(oss)) { - //cout << "Execturedg by " << commands.at(i)->getCommand(); commands.at(i)->process(oss); } - /*} catch (exception &e) - { - cerr << "oastat: Sql_error at line: \"" << line << "\"" << endl << - "oastat: Error is: " << e.what() << - "oastat: Last error will be ignored" << endl; - }*/ } - //cout << "returned" << endl; } startstruct = NULL; } @@ -198,7 +188,7 @@ int main (int argc, const char* argv[]) std::string backend = "Xml"; bool useTail = false; bool doIntegrationTest = false; - std::vector > commands; + std::vector > commands; ///////////// //dbargs = "mysql dbname oastat"; boost::format f("%1%/.openarena/baseoa/games.log"); @@ -252,15 +242,15 @@ int main (int argc, const char* argv[]) if (vm.count("integration-test")) { doIntegrationTest = true; } - boost::shared_ptr db; + std::shared_ptr db; #if USEDBIXX if (backend == "DbiXX") { cout << "Using DBI" << endl; if (dbargs.length()<1) { - db = boost::shared_ptr(new Db2DbiXX() ); + db = std::shared_ptr(new Db2DbiXX() ); } else { - db = boost::shared_ptr(new Db2DbiXX(dbargs) ); + db = std::shared_ptr(new Db2DbiXX(dbargs) ); } } #endif @@ -268,18 +258,18 @@ int main (int argc, const char* argv[]) if (backend == "CppDb") { std::cout << "Using CppDb\n"; if (dbargs.length()<1) { - db = boost::shared_ptr(new Db2CppDb() ); + db = std::shared_ptr(new Db2CppDb() ); } else { - db = boost::shared_ptr(new Db2CppDb(dbargs) ); + db = std::shared_ptr(new Db2CppDb(dbargs) ); } } #endif if (backend == "Xml") { std::cout << "Using XML\n"; if (dbargs.length()<1) { - db = boost::shared_ptr(new Db2Xml() ); + db = std::shared_ptr(new Db2Xml() ); } else { - db = boost::shared_ptr(new Db2Xml(dbargs) ); + db = std::shared_ptr(new Db2Xml(dbargs) ); } } diff --git a/src/oastatstruct.cpp b/src/oastatstruct.cpp index 0e6856d..d912a6f 100644 --- a/src/oastatstruct.cpp +++ b/src/oastatstruct.cpp @@ -21,20 +21,13 @@ https://github.com/sago007/oastat/ =========================================================================== */ -using namespace std; - #include "oastatstruct.h" #include #include #include #include -using namespace std; - -namespace -{ - -void makeLower(string &x) +static void makeLower(std::string &x) { for (unsigned int i=0; i= 'A' && x[i] <= 'X') { @@ -43,8 +36,6 @@ void makeLower(string &x) } } -} - //tm OaStatStruct::_datetime; OaStatStruct::OaStatStruct() @@ -76,12 +67,12 @@ void OaStatStruct::clear() restOfLine = ""; } -void OaStatStruct::parseLine(string line) +void OaStatStruct::parseLine(std::string line) { //Parse time //cout << line << endl; //try{ - string tempTimeString = line.substr(0,7); + std::string tempTimeString = line.substr(0,7); int posColon = tempTimeString.find(":"); int minute = atoi(tempTimeString.substr(0,posColon).c_str()); /*time_t thetime = time(NULL); @@ -97,7 +88,7 @@ void OaStatStruct::parseLine(string line) line = line.substr(posColon+2,line.length()); //Also remove the colon and the first space after it (+2) posColon = line.find_first_not_of(" -0123456789"); //First non-number or space - stringstream ss; + std::stringstream ss; ss << line.substr(0,posColon); int counter = 0; //to ensure that we don't go on forever while (ss && counter++<10) { @@ -114,7 +105,7 @@ void OaStatStruct::parseLine(string line) } } line = line.substr(posColon,line.length()); - } catch (exception &e) { + } catch (std::exception &e) { //The last part does not always exist... ignore it restOfLine = ""; return; @@ -125,13 +116,13 @@ void OaStatStruct::parseLine(string line) } -map OaStatStruct::GetInfostring(string restOfLine) const +std::map OaStatStruct::GetInfostring(const std::string& restOfLine) const { - map list; + std::map list; int curPos = 0; unsigned int lastPos = 0; bool iskey = true; - string key, value; + std::string key, value; if (restOfLine[0] == '\\') { lastPos++; } @@ -155,7 +146,7 @@ map OaStatStruct::GetInfostring(string restOfLine) const return list; } -map OaStatStruct::GetInfostring() const +std::map OaStatStruct::GetInfostring() const { return GetInfostring(restOfLine); } @@ -165,27 +156,27 @@ const tm OaStatStruct::getDateTime() const return _datetime; } -string ZeroPadNumber(int num, int size = 2) +std::string ZeroPadNumber(int num, int size = 2) { std::ostringstream ss; ss.clear(); - ss << setw( size ) << setfill( '0' ) << num; + ss << std::setw( size ) << std::setfill( '0' ) << num; return ss.str(); } -string OaStatStruct::getTimeStamp() const +std::string OaStatStruct::getTimeStamp() const { - string s; + std::string s; s = "TIMESTAMP \'" + ZeroPadNumber(_datetime.tm_year+1900,4) + "-" + ZeroPadNumber(_datetime.tm_mon+1) + "-" + ZeroPadNumber(_datetime.tm_mday) + " " + ZeroPadNumber(_datetime.tm_hour) + ":" + ZeroPadNumber(_datetime.tm_min) + ":" + ZeroPadNumber(_datetime.tm_sec) + "\'"; return s; } -void OaStatStruct::setTimeStamp(const string ×tring) +void OaStatStruct::setTimeStamp(const std::string ×tring) { std::stringstream ss(timestring); - string tmp; + std::string tmp; getline(ss,tmp,'-'); _datetime.tm_year = atoi(tmp.c_str())-1900; getline(ss,tmp,'-'); diff --git a/src/oastatstruct.h b/src/oastatstruct.h index 5887458..8824feb 100644 --- a/src/oastatstruct.h +++ b/src/oastatstruct.h @@ -54,7 +54,7 @@ public: /* *Parses the rest of the line to an info string */ - std::map GetInfostring(std::string restOfLine) const; + std::map GetInfostring(const std::string& restOfLine) const; /* *Same but uses this.restOfLine diff --git a/src/oss2db/init2db.cpp b/src/oss2db/init2db.cpp index 845ea8a..008c8e2 100644 --- a/src/oss2db/init2db.cpp +++ b/src/oss2db/init2db.cpp @@ -52,17 +52,16 @@ void Init2Db::process(const OaStatStruct &oss) oss_copy.setTimeStamp(arguments["g_timestamp"]); dp->startGame(gametype,mapname,basegame,servername,oss_copy); - std::map::iterator it; - for (it = arguments.begin(); it != arguments.end(); it++) { + for (std::pair it : arguments) { if( - it->first == "g_gametype" || - it->first == "gamename" || - it->first == "mapname" || - it->first == "sv_hostname" /*|| - it->first == "g_timestamp" do not skip this one*/ + it.first == "g_gametype" || + it.first == "gamename" || + it.first == "mapname" || + it.first == "sv_hostname" /*|| + it.first == "g_timestamp" do not skip this one*/ ) { continue; //Skip the ones on the games-table } - dp->addGameCvar(it->first,it->second); + dp->addGameCvar(it.first,it.second); } } diff --git a/src/oss2db/struct2db.h b/src/oss2db/struct2db.h index 6562c3c..0b8c343 100644 --- a/src/oss2db/struct2db.h +++ b/src/oss2db/struct2db.h @@ -38,7 +38,7 @@ public: /* * The object will need a database interface to cummunicate to. This is given here */ - void setDb(boost::shared_ptr &d) + void setDb(std::shared_ptr &d) { dp = d; } @@ -69,7 +69,7 @@ public: }; protected: - boost::shared_ptr dp; //Pointer to the used db + std::shared_ptr dp; //Pointer to the used db };