git repos / oastat

commit 3db11b68

sago007 · 2012-12-01 22:20
3db11b68847ac15c649f71e881c40dac734cc3ea patch · browse files
parent c4a3cf29206d190fcec54528a7e4f6f1c72e1473

Now uses smart pointers instead of stupid pointers. Also uses runtime_error for exceptions.

Changed files

M src/db/Db2DbiXX.cpp before
M src/oastat.cpp before
M src/oastatstruct.cpp before
M src/oss2db/Accuracy2Db.cpp before
M src/oss2db/Accuracy2Db.hpp before
M src/oss2db/Award2Db.cpp before
M src/oss2db/Award2Db.h before
M src/oss2db/Challenge2Db.cpp before
M src/oss2db/Challenge2Db.hpp before
M src/oss2db/Ctf1f2Db.cpp before
M src/oss2db/Ctf1f2Db.hpp before
M src/oss2db/Ctf2Db.cpp before
M src/oss2db/Ctf2Db.hpp before
M src/oss2db/CtfElimination2Db.cpp before
M src/oss2db/CtfElimination2Db.hpp before
M src/oss2db/Disconnect2Db.cpp before
M src/oss2db/Disconnect2Db.h before
M src/oss2db/Elimination2Db.cpp before
M src/oss2db/Elimination2Db.hpp before
M src/oss2db/Harvester2Db.cpp before
M src/oss2db/Harvester2Db.hpp before
M src/oss2db/Point2Db.cpp before
M src/oss2db/Point2Db.hpp before
M src/oss2db/Warmup2Db.cpp before
M src/oss2db/Warmup2Db.hpp before
M src/oss2db/init2db.cpp before
M src/oss2db/init2db.h before
M src/oss2db/kill2db.cpp before
M src/oss2db/kill2db.h before
M src/oss2db/shutdown2db.cpp before
M src/oss2db/shutdown2db.h before
M src/oss2db/struct2db.h before
M src/oss2db/userinfo2db.cpp before
M src/oss2db/userinfo2db.h before
diff --git a/src/db/Db2DbiXX.cpp b/src/db/Db2DbiXX.cpp index 1e75672..237708e 100644 --- a/src/db/Db2DbiXX.cpp +++ b/src/db/Db2DbiXX.cpp
@@ -21,6 +21,8 @@ http://code.google.com/p/oastat/
===========================================================================
*/
+#include <c++/4.6/stdexcept>
+
#include "Db2DbiXX.hpp"
void Db2DbiXX::InitStrings(const string &backend)
@@ -104,7 +106,7 @@ Db2DbiXX::Db2DbiXX(const string &dbargs)
Db2DbiXX::Db2DbiXX(const Db2DbiXX& orig)
{
- throw "May not make copy of Db2DbiXX";
+ throw runtime_error("May not make copy of Db2DbiXX");
}
Db2DbiXX::~Db2DbiXX()
@@ -319,7 +321,7 @@ int Db2DbiXX::getNextGameNumber()
}
else
{
- throw "Could not get next gamenumber";
+ throw runtime_error("Could not get next gamenumber");
}
}
@@ -340,7 +342,7 @@ int Db2DbiXX::getLastGameNumber()
}
else
{
- throw "Could not get last gamenumber";
+ throw runtime_error("Could not get last gamenumber");
}
}
diff --git a/src/oastat.cpp b/src/oastat.cpp index bfbd9a4..fefd80a 100644 --- a/src/oastat.cpp +++ b/src/oastat.cpp
@@ -64,19 +64,23 @@ using namespace boost;
vector<string> clientIdMap;
-static int processStdIn(istream* in_p);
+static int processStdIn(istream &in_p,vector<shared_ptr<Struct2Db> > &commands);
-static Database *db;
-
-static vector<shared_ptr<Struct2Db> > commands;
/**
* This function adds objects that are inherited from the Struct2Db class
* to the vector commands.
+ *
+ * @param[in] db The database object. May not be freed once given as an argument to this function
*/
-void addCommands()
+static void addCommands(shared_ptr<Database> &db,vector<shared_ptr<Struct2Db> > &commands)
{
+ if(!db)
+ {
+ throw runtime_error("db was uninizialized in addCommands");
+ }
+
//Add new commands here
commands.push_back(shared_ptr<Struct2Db>(new Kill2Db() ) );
commands.push_back(shared_ptr<Struct2Db>(new Init2Db() ) );
@@ -103,7 +107,7 @@ void addCommands()
-int processStdIn(istream* in_p)
+static int processStdIn(istream &in_p,vector<shared_ptr<Struct2Db> > &commands)
{
bool done = true;
OaStatStruct *startstruct;
@@ -115,24 +119,26 @@ int processStdIn(istream* in_p)
list<OaStatStruct> osslist;
try
{
- while( getline(*in_p,line) )
+ while( getline(in_p,line) )
{
oss.clear();
oss.parseLine(line);
osslist.push_back(oss);
if(oss.command=="InitGame")
startstruct = &osslist.back();
- if(oss.command=="Warmup" && startstruct)
- startstruct->restOfLine += "\\isWarmup\\1"; //Workaround to stop warmup
+ if(oss.command=="Warmup" && startstruct)
+ {
+ //Workaround to stop warmup
+ //If we spot a warmup command we add a cvar to the start struct
+ //Warmup is a attribute that affect he whole game
+ startstruct->restOfLine += "\\isWarmup\\1";
+ }
if(oss.command=="ShutdownGame")
{
while(!osslist.empty())
{
- //cout << "next: " << oss.command << endl;
oss = osslist.front();
- //cout << "gotten, now popping" << endl;
osslist.pop_front();
- //cout << "popping complete" << endl;
for(unsigned int i=0; i<commands.size(); i++)
{
//try {
@@ -203,6 +209,7 @@ int main (int argc, const char* argv[])
string filename = "";
string backend = "Xml";
bool useTail = false;
+ vector<shared_ptr<Struct2Db> > commands;
/////////////
//dbargs = "mysql dbname oastat";
boost::format f("%1%/.openarena/baseoa/games.log");
@@ -234,58 +241,67 @@ int main (int argc, const char* argv[])
}
try
{
- db = NULL;
-
+ shared_ptr<Database> db;
#if USEDBIXX
if(backend == "DbiXX")
{
cout << "Using DBI" << endl;
if(dbargs.length()<1)
- db = new Db2DbiXX();
+ {
+ db = shared_ptr<Database>(new Db2DbiXX() );
+ }
else
- db = new Db2DbiXX(dbargs);
+ {
+ db = shared_ptr<Database>(new Db2DbiXX(dbargs) );
+ }
}
#endif
if(backend == "Xml")
{
cout << "Using XML" << endl;
if(dbargs.length()<1)
- db = new Db2Xml();
+ {
+ db = shared_ptr<Database>(new Db2Xml() );
+ }
else
- db = new Db2Xml(dbargs);
+ {
+ db = shared_ptr<Database>(new Db2Xml(dbargs) );
+ }
}
if(!db)
{
string error("Failed to find backend: ");
error += backend;
- throw error.c_str();
+ throw runtime_error(error);
}
- addCommands();
+ addCommands(db,commands);
if(filename.length()>0)
{
if(useTail)
{
redi::ipstream in("tail -s 1 -f "+filename);
- processStdIn(&in);
+ processStdIn(in,commands);
}
else
{
ifstream in(filename.c_str(),ifstream::in);
- processStdIn(&in);
+ processStdIn(in,commands);
}
}
else
- processStdIn(&cin);
+ {
+ processStdIn(cin,commands);
+ }
}
- catch (const char *s)
+ catch (std::exception &e)
{
- cout << "Crashed: " << s << endl;
- return -1;
+ cout << "Crashed: " << e.what() << endl;
+ return 2;
}
return 0;
diff --git a/src/oastatstruct.cpp b/src/oastatstruct.cpp index fe9ab8a..43c82c7 100644 --- a/src/oastatstruct.cpp +++ b/src/oastatstruct.cpp
@@ -116,7 +116,7 @@ void OaStatStruct::parseLine(string line)
}
line = line.substr(posColon,line.length());
}
- catch(...)
+ catch(exception &e)
{
//The last part does not always exist... ignore it
restOfLine = "";
diff --git a/src/oss2db/Accuracy2Db.cpp b/src/oss2db/Accuracy2Db.cpp index a7c9003..4e49e71 100644 --- a/src/oss2db/Accuracy2Db.cpp +++ b/src/oss2db/Accuracy2Db.cpp
@@ -25,12 +25,12 @@ http://code.google.com/p/oastat/
#include <boost/format.hpp>
-string Accuracy2Db::getCommand()
+string Accuracy2Db::getCommand() const
{
return "Accuracy";
}
-bool Accuracy2Db::canProcess(const OaStatStruct &oss)
+bool Accuracy2Db::canProcess(const OaStatStruct &oss) const
{
if(oss.command != getCommand())
return false;
diff --git a/src/oss2db/Accuracy2Db.hpp b/src/oss2db/Accuracy2Db.hpp index 409bf0c..ccb214d 100644 --- a/src/oss2db/Accuracy2Db.hpp +++ b/src/oss2db/Accuracy2Db.hpp
@@ -29,8 +29,8 @@ http://code.google.com/p/oastat/
class Accuracy2Db : public Struct2Db {
public:
- string getCommand();
- bool canProcess(const OaStatStruct &oss);
+ string getCommand() const;
+ bool canProcess(const OaStatStruct &oss) const;
void process(const OaStatStruct &oss);
private:
diff --git a/src/oss2db/Award2Db.cpp b/src/oss2db/Award2Db.cpp index 7deab6c..e3ae3b9 100644 --- a/src/oss2db/Award2Db.cpp +++ b/src/oss2db/Award2Db.cpp
@@ -25,12 +25,12 @@ http://code.google.com/p/oastat/
-string Award2Db::getCommand()
+string Award2Db::getCommand() const
{
return "Award";
}
-bool Award2Db::canProcess(const OaStatStruct &oss)
+bool Award2Db::canProcess(const OaStatStruct &oss) const
{
if(oss.command != getCommand() || oss.parameters.size()<2 || oss.parameters.at(0)<0)
return false;
diff --git a/src/oss2db/Award2Db.h b/src/oss2db/Award2Db.h index 1b3a470..0b67797 100644 --- a/src/oss2db/Award2Db.h +++ b/src/oss2db/Award2Db.h
@@ -31,8 +31,8 @@ class Award2Db : public Struct2Db
{
public:
- string getCommand();
- bool canProcess(const OaStatStruct &oss);
+ string getCommand() const;
+ bool canProcess(const OaStatStruct &oss) const;
void process(const OaStatStruct &oss);
private:
diff --git a/src/oss2db/Challenge2Db.cpp b/src/oss2db/Challenge2Db.cpp index a84b987..326881a 100644 --- a/src/oss2db/Challenge2Db.cpp +++ b/src/oss2db/Challenge2Db.cpp
@@ -23,13 +23,13 @@ http://code.google.com/p/oastat/
#include "Challenge2Db.hpp"
-string Challenge2Db::getCommand()
+string Challenge2Db::getCommand() const
{
return "Challenge";
}
-bool Challenge2Db::canProcess(const OaStatStruct &oss)
+bool Challenge2Db::canProcess(const OaStatStruct &oss) const
{
if(oss.command != getCommand() || oss.parameters.size()<3)
return false;
diff --git a/src/oss2db/Challenge2Db.hpp b/src/oss2db/Challenge2Db.hpp index 78eee34..295a0e0 100644 --- a/src/oss2db/Challenge2Db.hpp +++ b/src/oss2db/Challenge2Db.hpp
@@ -30,8 +30,8 @@ http://code.google.com/p/oastat/
class Challenge2Db : public Struct2Db
{
public:
- string getCommand();
- bool canProcess(const OaStatStruct &oss);
+ string getCommand() const;
+ bool canProcess(const OaStatStruct &oss) const;
void process(const OaStatStruct &oss);
private:
diff --git a/src/oss2db/Ctf1f2Db.cpp b/src/oss2db/Ctf1f2Db.cpp index e1c5b81..cde002a 100644 --- a/src/oss2db/Ctf1f2Db.cpp +++ b/src/oss2db/Ctf1f2Db.cpp
@@ -24,12 +24,12 @@ http://code.google.com/p/oastat/
#include "Ctf1f2Db.hpp"
-string Ctf1f2Db::getCommand()
+string Ctf1f2Db::getCommand() const
{
return "1FCTF";
}
-bool Ctf1f2Db::canProcess(const OaStatStruct &oss)
+bool Ctf1f2Db::canProcess(const OaStatStruct &oss) const
{
if(oss.command != getCommand() || oss.parameters.size()<3)
return false;
diff --git a/src/oss2db/Ctf1f2Db.hpp b/src/oss2db/Ctf1f2Db.hpp index bf6bdc0..50a594d 100644 --- a/src/oss2db/Ctf1f2Db.hpp +++ b/src/oss2db/Ctf1f2Db.hpp
@@ -31,8 +31,8 @@ class Ctf1f2Db : public Struct2Db
{
public:
- string getCommand();
- bool canProcess(const OaStatStruct &oss);
+ string getCommand() const;
+ bool canProcess(const OaStatStruct &oss) const;
void process(const OaStatStruct &oss);
private:
diff --git a/src/oss2db/Ctf2Db.cpp b/src/oss2db/Ctf2Db.cpp index 39c2c48..0252617 100644 --- a/src/oss2db/Ctf2Db.cpp +++ b/src/oss2db/Ctf2Db.cpp
@@ -24,12 +24,12 @@ http://code.google.com/p/oastat/
#include "Ctf2Db.hpp"
-string Ctf2Db::getCommand()
+string Ctf2Db::getCommand() const
{
return "CTF";
}
-bool Ctf2Db::canProcess(const OaStatStruct &oss)
+bool Ctf2Db::canProcess(const OaStatStruct &oss) const
{
if(oss.command != getCommand() || oss.parameters.size()<3)
return false;
diff --git a/src/oss2db/Ctf2Db.hpp b/src/oss2db/Ctf2Db.hpp index fd1bc66..88ebf05 100644 --- a/src/oss2db/Ctf2Db.hpp +++ b/src/oss2db/Ctf2Db.hpp
@@ -31,8 +31,8 @@ class Ctf2Db : public Struct2Db
{
public:
- string getCommand();
- bool canProcess(const OaStatStruct &oss);
+ string getCommand() const;
+ bool canProcess(const OaStatStruct &oss) const;
void process(const OaStatStruct &oss);
private:
diff --git a/src/oss2db/CtfElimination2Db.cpp b/src/oss2db/CtfElimination2Db.cpp index b732f1c..7eedda8 100644 --- a/src/oss2db/CtfElimination2Db.cpp +++ b/src/oss2db/CtfElimination2Db.cpp
@@ -23,12 +23,12 @@ http://code.google.com/p/oastat/
#include "CtfElimination2Db.hpp"
-string CtfElimination2Db::getCommand()
+string CtfElimination2Db::getCommand() const
{
return "ELIMINATION";
}
-bool CtfElimination2Db::canProcess(const OaStatStruct &oss)
+bool CtfElimination2Db::canProcess(const OaStatStruct &oss) const
{
if(oss.command != getCommand() || oss.parameters.size()<3 )
return false;
diff --git a/src/oss2db/CtfElimination2Db.hpp b/src/oss2db/CtfElimination2Db.hpp index 539f005..9c48089 100644 --- a/src/oss2db/CtfElimination2Db.hpp +++ b/src/oss2db/CtfElimination2Db.hpp
@@ -31,8 +31,8 @@ http://code.google.com/p/oastat/
class CtfElimination2Db : public Struct2Db
{
public:
- string getCommand();
- bool canProcess(const OaStatStruct &oss);
+ string getCommand() const;
+ bool canProcess(const OaStatStruct &oss) const;
void process(const OaStatStruct &oss);
diff --git a/src/oss2db/Disconnect2Db.cpp b/src/oss2db/Disconnect2Db.cpp index 2f078dd..d69af61 100644 --- a/src/oss2db/Disconnect2Db.cpp +++ b/src/oss2db/Disconnect2Db.cpp
@@ -24,12 +24,12 @@ http://code.google.com/p/oastat/
#include "Disconnect2Db.h"
-string Disconnect2Db::getCommand()
+string Disconnect2Db::getCommand() const
{
return "ClientDisconnect";
}
-bool Disconnect2Db::canProcess(const OaStatStruct &oss)
+bool Disconnect2Db::canProcess(const OaStatStruct &oss) const
{
if(oss.command != getCommand() || oss.parameters.size()<1)
return false;
diff --git a/src/oss2db/Disconnect2Db.h b/src/oss2db/Disconnect2Db.h index 2f9649a..842e5dc 100644 --- a/src/oss2db/Disconnect2Db.h +++ b/src/oss2db/Disconnect2Db.h
@@ -31,8 +31,8 @@ class Disconnect2Db : public Struct2Db
{
public:
- string getCommand();
- bool canProcess(const OaStatStruct &oss);
+ string getCommand() const;
+ bool canProcess(const OaStatStruct &oss) const;
void process(const OaStatStruct &oss);
private:
diff --git a/src/oss2db/Elimination2Db.cpp b/src/oss2db/Elimination2Db.cpp index 190918b..cb88d18 100644 --- a/src/oss2db/Elimination2Db.cpp +++ b/src/oss2db/Elimination2Db.cpp
@@ -24,12 +24,12 @@ http://code.google.com/p/oastat/
#include "Elimination2Db.hpp"
-string Elimination2Db::getCommand()
+string Elimination2Db::getCommand() const
{
return "ELIMINATION";
}
-bool Elimination2Db::canProcess(const OaStatStruct &oss)
+bool Elimination2Db::canProcess(const OaStatStruct &oss) const
{
if(oss.command != getCommand() || oss.parameters.size()<3 )
return false;
diff --git a/src/oss2db/Elimination2Db.hpp b/src/oss2db/Elimination2Db.hpp index d6af478..28f7058 100644 --- a/src/oss2db/Elimination2Db.hpp +++ b/src/oss2db/Elimination2Db.hpp
@@ -30,8 +30,8 @@ http://code.google.com/p/oastat/
class Elimination2Db : public Struct2Db
{
public:
- string getCommand();
- bool canProcess(const OaStatStruct &oss);
+ string getCommand() const;
+ bool canProcess(const OaStatStruct &oss) const;
void process(const OaStatStruct &oss);
private:
diff --git a/src/oss2db/Harvester2Db.cpp b/src/oss2db/Harvester2Db.cpp index 558a8c6..0747a6a 100644 --- a/src/oss2db/Harvester2Db.cpp +++ b/src/oss2db/Harvester2Db.cpp
@@ -23,12 +23,12 @@ http://code.google.com/p/oastat/
#include "Harvester2Db.hpp"
-string Harvester2Db::getCommand()
+string Harvester2Db::getCommand() const
{
return "HARVESTER";
}
-bool Harvester2Db::canProcess(const OaStatStruct &oss)
+bool Harvester2Db::canProcess(const OaStatStruct &oss) const
{
if(oss.command != getCommand() || oss.parameters.size()<5 )
return false;
diff --git a/src/oss2db/Harvester2Db.hpp b/src/oss2db/Harvester2Db.hpp index 38858e1..4455ea6 100644 --- a/src/oss2db/Harvester2Db.hpp +++ b/src/oss2db/Harvester2Db.hpp
@@ -30,8 +30,8 @@ http://code.google.com/p/oastat/
class Harvester2Db : public Struct2Db
{
public:
- string getCommand();
- bool canProcess(const OaStatStruct &oss);
+ string getCommand() const;
+ bool canProcess(const OaStatStruct &oss) const;
void process(const OaStatStruct &oss);
private:
diff --git a/src/oss2db/Point2Db.cpp b/src/oss2db/Point2Db.cpp index bc70174..7a0e46a 100644 --- a/src/oss2db/Point2Db.cpp +++ b/src/oss2db/Point2Db.cpp
@@ -24,12 +24,12 @@ http://code.google.com/p/oastat/
#include "Point2Db.hpp"
-string Point2Db::getCommand()
+string Point2Db::getCommand() const
{
return "PlayerScore";
}
-bool Point2Db::canProcess(const OaStatStruct &oss)
+bool Point2Db::canProcess(const OaStatStruct &oss) const
{
if(oss.command != getCommand() || oss.parameters.size()<2 || oss.parameters.at(0)<0)
return false;
diff --git a/src/oss2db/Point2Db.hpp b/src/oss2db/Point2Db.hpp index 20ac659..8304781 100644 --- a/src/oss2db/Point2Db.hpp +++ b/src/oss2db/Point2Db.hpp
@@ -30,8 +30,8 @@ http://code.google.com/p/oastat/
class Point2Db : public Struct2Db
{
public:
- string getCommand();
- bool canProcess(const OaStatStruct &oss);
+ string getCommand() const;
+ bool canProcess(const OaStatStruct &oss) const;
void process(const OaStatStruct &oss);
private:
diff --git a/src/oss2db/Warmup2Db.cpp b/src/oss2db/Warmup2Db.cpp index b81a71e..25c1fe0 100644 --- a/src/oss2db/Warmup2Db.cpp +++ b/src/oss2db/Warmup2Db.cpp
@@ -23,12 +23,12 @@ http://code.google.com/p/oastat/
#include "Warmup2Db.hpp"
-string Warmup2Db::getCommand()
+string Warmup2Db::getCommand() const
{
return "Warmup";
}
-bool Warmup2Db::canProcess(const OaStatStruct &oss)
+bool Warmup2Db::canProcess(const OaStatStruct &oss) const
{
if(oss.command != getCommand())
return false;
diff --git a/src/oss2db/Warmup2Db.hpp b/src/oss2db/Warmup2Db.hpp index 29e8911..8d53243 100644 --- a/src/oss2db/Warmup2Db.hpp +++ b/src/oss2db/Warmup2Db.hpp
@@ -30,8 +30,8 @@ http://code.google.com/p/oastat/
class Warmup2Db : public Struct2Db
{
public:
- string getCommand();
- bool canProcess(const OaStatStruct &oss);
+ string getCommand() const;
+ bool canProcess(const OaStatStruct &oss) const;
void process(const OaStatStruct &oss);
private:
diff --git a/src/oss2db/init2db.cpp b/src/oss2db/init2db.cpp index 8f6241d..d645b87 100644 --- a/src/oss2db/init2db.cpp +++ b/src/oss2db/init2db.cpp
@@ -25,12 +25,12 @@ http://code.google.com/p/oastat/
#include <stdlib.h>
-string Init2Db::getCommand()
+string Init2Db::getCommand() const
{
return "InitGame";
}
-bool Init2Db::canProcess(const OaStatStruct &oss)
+bool Init2Db::canProcess(const OaStatStruct &oss) const
{
if(oss.command != getCommand())
return false;
diff --git a/src/oss2db/init2db.h b/src/oss2db/init2db.h index 0b078d6..eecdaaf 100644 --- a/src/oss2db/init2db.h +++ b/src/oss2db/init2db.h
@@ -31,8 +31,8 @@ class Init2Db : public Struct2Db
{
public:
- string getCommand();
- bool canProcess(const OaStatStruct &oss);
+ string getCommand() const;
+ bool canProcess(const OaStatStruct &oss) const;
void process(const OaStatStruct &oss);
private:
diff --git a/src/oss2db/kill2db.cpp b/src/oss2db/kill2db.cpp index 8288b18..5ee6f51 100644 --- a/src/oss2db/kill2db.cpp +++ b/src/oss2db/kill2db.cpp
@@ -24,12 +24,12 @@ http://code.google.com/p/oastat/
#include "kill2db.h"
-string Kill2Db::getCommand()
+string Kill2Db::getCommand() const
{
return "Kill";
}
-bool Kill2Db::canProcess(const OaStatStruct &oss)
+bool Kill2Db::canProcess(const OaStatStruct &oss) const
{
if(oss.command != getCommand() || oss.parameters.size()<=3)
return false;
diff --git a/src/oss2db/kill2db.h b/src/oss2db/kill2db.h index 08cd0d2..85ddac9 100644 --- a/src/oss2db/kill2db.h +++ b/src/oss2db/kill2db.h
@@ -30,8 +30,8 @@ http://code.google.com/p/oastat/
class Kill2Db : public Struct2Db
{
- string getCommand();
- bool canProcess(const OaStatStruct &oss);
+ string getCommand() const;
+ bool canProcess(const OaStatStruct &oss) const;
void process(const OaStatStruct &oss);
diff --git a/src/oss2db/shutdown2db.cpp b/src/oss2db/shutdown2db.cpp index 37598d6..20879c1 100644 --- a/src/oss2db/shutdown2db.cpp +++ b/src/oss2db/shutdown2db.cpp
@@ -25,12 +25,12 @@ http://code.google.com/p/oastat/
-string Shutdown2Db::getCommand()
+string Shutdown2Db::getCommand() const
{
return "ShutdownGame";
}
-bool Shutdown2Db::canProcess(const OaStatStruct &oss)
+bool Shutdown2Db::canProcess(const OaStatStruct &oss) const
{
if(oss.command != getCommand())
return false;
diff --git a/src/oss2db/shutdown2db.h b/src/oss2db/shutdown2db.h index 5ca5fc5..dc69f01 100644 --- a/src/oss2db/shutdown2db.h +++ b/src/oss2db/shutdown2db.h
@@ -31,8 +31,8 @@ class Shutdown2Db : public Struct2Db
{
public:
- string getCommand();
- bool canProcess(const OaStatStruct &oss);
+ string getCommand() const;
+ bool canProcess(const OaStatStruct &oss) const;
void process(const OaStatStruct &oss);
diff --git a/src/oss2db/struct2db.h b/src/oss2db/struct2db.h index 9fb16d9..7920dc6 100644 --- a/src/oss2db/struct2db.h +++ b/src/oss2db/struct2db.h
@@ -27,6 +27,7 @@ http://code.google.com/p/oastat/
#include "../oastatstruct.h"
#include "../db/database.hpp"
#include <string>
+#include <boost/shared_ptr.hpp>
using namespace std;
@@ -39,7 +40,7 @@ public:
/*
* The object will need a database interface to cummunicate to. This is given here
*/
- void setDb(Database *d)
+ void setDb(boost::shared_ptr<Database> &d)
{
dp = d;
}
@@ -49,7 +50,7 @@ public:
*
* @returns The command the object can process
*/
- virtual string getCommand() = 0;
+ virtual std::string getCommand() const = 0;
/*
* The object needs a way to tell if it can process a command.
@@ -57,7 +58,7 @@ public:
* This is better than the last getCommand, because it can check for multiple commands at once, and can
* discard subevents for supported commands.
*/
- virtual bool canProcess(const OaStatStruct &oss) = 0;
+ virtual bool canProcess(const OaStatStruct &oss) const = 0;
/*
* Parses s OaStatStruct to the object to process
@@ -70,7 +71,7 @@ public:
};
protected:
- Database *dp; //Pointer to the used db
+ boost::shared_ptr<Database> dp; //Pointer to the used db
};
diff --git a/src/oss2db/userinfo2db.cpp b/src/oss2db/userinfo2db.cpp index 41601ac..7bcb209 100644 --- a/src/oss2db/userinfo2db.cpp +++ b/src/oss2db/userinfo2db.cpp
@@ -27,12 +27,12 @@ http://code.google.com/p/oastat/
#include <boost/format.hpp>
-string Userinfo2Db::getCommand()
+string Userinfo2Db::getCommand() const
{
return "ClientUserinfoChanged";
}
-bool Userinfo2Db::canProcess(const OaStatStruct &oss)
+bool Userinfo2Db::canProcess(const OaStatStruct &oss) const
{
if(oss.command != getCommand() || oss.parameters.size()<1)
return false;
diff --git a/src/oss2db/userinfo2db.h b/src/oss2db/userinfo2db.h index b8baec7..51abffe 100644 --- a/src/oss2db/userinfo2db.h +++ b/src/oss2db/userinfo2db.h
@@ -31,9 +31,9 @@ class Userinfo2Db : public Struct2Db
{
public:
- string getCommand();
+ string getCommand() const;
- bool canProcess(const OaStatStruct &oss);
+ bool canProcess(const OaStatStruct &oss) const;
void process(const OaStatStruct &oss);
private: