commit 55d13e30
C++11 changes: User std::shared_ptr and new for loop.
Changed files
| M | src/oastat.cpp before |
| M | src/oastatstruct.cpp before |
| M | src/oastatstruct.h before |
| M | src/oss2db/init2db.cpp before |
| M | src/oss2db/struct2db.h before |
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<std::string> clientIdMap;
-static int processStdIn(std::istream &in_p,std::vector<boost::shared_ptr<Struct2Db> > &commands);
+static int processStdIn(std::istream &in_p,std::vector<std::shared_ptr<Struct2Db> > &commands);
@@ -76,28 +76,28 @@ static int processStdIn(std::istream &in_p,std::vector<boost::shared_ptr<Struct2
*
* @param[in] db The database object. May not be freed once given as an argument to this function
*/
-static void addCommands(boost::shared_ptr<Database> &db,std::vector<boost::shared_ptr<Struct2Db> > &commands)
+static void addCommands(std::shared_ptr<Database> &db,std::vector<std::shared_ptr<Struct2Db> > &commands)
{
if (!db) {
throw std::runtime_error("db was uninizialized in addCommands");
}
//Add new commands here
- commands.push_back(boost::shared_ptr<Struct2Db>(new Kill2Db() ) );
- commands.push_back(boost::shared_ptr<Struct2Db>(new Init2Db() ) );
- commands.push_back(boost::shared_ptr<Struct2Db>(new Shutdown2Db() ) );
- commands.push_back(boost::shared_ptr<Struct2Db>(new Userinfo2Db()) );
- commands.push_back(boost::shared_ptr<Struct2Db>(new Disconnect2Db()) );
- commands.push_back(boost::shared_ptr<Struct2Db>(new Award2Db()) );
- commands.push_back(boost::shared_ptr<Struct2Db>(new Ctf2Db()) );
- commands.push_back(boost::shared_ptr<Struct2Db>(new Point2Db()) );
- commands.push_back(boost::shared_ptr<Struct2Db>(new Ctf1f2Db()) );
- commands.push_back(boost::shared_ptr<Struct2Db>(new Elimination2Db()) );
- commands.push_back(boost::shared_ptr<Struct2Db>(new CtfElimination2Db()) );
- commands.push_back(boost::shared_ptr<Struct2Db>(new Harvester2Db()) );
- commands.push_back(boost::shared_ptr<Struct2Db>(new Challenge2Db()) );
- commands.push_back(boost::shared_ptr<Struct2Db>(new Warmup2Db()) );
- commands.push_back(boost::shared_ptr<Struct2Db>(new Accuracy2Db()) );
+ commands.push_back(std::shared_ptr<Struct2Db>(new Kill2Db() ) );
+ commands.push_back(std::shared_ptr<Struct2Db>(new Init2Db() ) );
+ commands.push_back(std::shared_ptr<Struct2Db>(new Shutdown2Db() ) );
+ commands.push_back(std::shared_ptr<Struct2Db>(new Userinfo2Db()) );
+ commands.push_back(std::shared_ptr<Struct2Db>(new Disconnect2Db()) );
+ commands.push_back(std::shared_ptr<Struct2Db>(new Award2Db()) );
+ commands.push_back(std::shared_ptr<Struct2Db>(new Ctf2Db()) );
+ commands.push_back(std::shared_ptr<Struct2Db>(new Point2Db()) );
+ commands.push_back(std::shared_ptr<Struct2Db>(new Ctf1f2Db()) );
+ commands.push_back(std::shared_ptr<Struct2Db>(new Elimination2Db()) );
+ commands.push_back(std::shared_ptr<Struct2Db>(new CtfElimination2Db()) );
+ commands.push_back(std::shared_ptr<Struct2Db>(new Harvester2Db()) );
+ commands.push_back(std::shared_ptr<Struct2Db>(new Challenge2Db()) );
+ commands.push_back(std::shared_ptr<Struct2Db>(new Warmup2Db()) );
+ commands.push_back(std::shared_ptr<Struct2Db>(new Accuracy2Db()) );
//Add more commands just above here
for (unsigned int i=0; i<commands.size(); i++) {
@@ -107,7 +107,7 @@ static void addCommands(boost::shared_ptr<Database> &db,std::vector<boost::share
-static int processStdIn(std::istream &in_p, std::vector<boost::shared_ptr<Struct2Db> > &commands)
+static int processStdIn(std::istream &in_p, std::vector<std::shared_ptr<Struct2Db> > &commands)
{
bool done = true;
OaStatStruct *startstruct;
@@ -135,20 +135,10 @@ static int processStdIn(std::istream &in_p, std::vector<boost::shared_ptr<Struct
oss = osslist.front();
osslist.pop_front();
for(unsigned int i=0; i<commands.size(); i++) {
- //try {
- //cout << "checking " << commands.at(i)->getCommand() << 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<boost::shared_ptr<Struct2Db> > commands;
+ std::vector<std::shared_ptr<Struct2Db> > 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<Database> db;
+ std::shared_ptr<Database> db;
#if USEDBIXX
if (backend == "DbiXX") {
cout << "Using DBI" << endl;
if (dbargs.length()<1) {
- db = boost::shared_ptr<Database>(new Db2DbiXX() );
+ db = std::shared_ptr<Database>(new Db2DbiXX() );
} else {
- db = boost::shared_ptr<Database>(new Db2DbiXX(dbargs) );
+ db = std::shared_ptr<Database>(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<Database>(new Db2CppDb() );
+ db = std::shared_ptr<Database>(new Db2CppDb() );
} else {
- db = boost::shared_ptr<Database>(new Db2CppDb(dbargs) );
+ db = std::shared_ptr<Database>(new Db2CppDb(dbargs) );
}
}
#endif
if (backend == "Xml") {
std::cout << "Using XML\n";
if (dbargs.length()<1) {
- db = boost::shared_ptr<Database>(new Db2Xml() );
+ db = std::shared_ptr<Database>(new Db2Xml() );
} else {
- db = boost::shared_ptr<Database>(new Db2Xml(dbargs) );
+ db = std::shared_ptr<Database>(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 <stdlib.h>
#include <sstream>
#include <iostream>
#include <iomanip>
-using namespace std;
-
-namespace
-{
-
-void makeLower(string &x)
+static void makeLower(std::string &x)
{
for (unsigned int i=0; i<x.length(); i++) {
if (x[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<string,string> OaStatStruct::GetInfostring(string restOfLine) const
+std::map<std::string,std::string> OaStatStruct::GetInfostring(const std::string& restOfLine) const
{
- map<string,string> list;
+ std::map<std::string,std::string> 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<string,string> OaStatStruct::GetInfostring(string restOfLine) const
return list;
}
-map<string,string> OaStatStruct::GetInfostring() const
+std::map<std::string,std::string> 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<std::string,std::string> GetInfostring(std::string restOfLine) const;
+ std::map<std::string,std::string> 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<std::string,std::string>::iterator it;
- for (it = arguments.begin(); it != arguments.end(); it++) {
+ for (std::pair<std::string, std::string> 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<Database> &d)
+ void setDb(std::shared_ptr<Database> &d)
{
dp = d;
}
@@ -69,7 +69,7 @@ public:
};
protected:
- boost::shared_ptr<Database> dp; //Pointer to the used db
+ std::shared_ptr<Database> dp; //Pointer to the used db
};