]> jfr.im git - irc/gameservirc.git/blob - gameserv-2.0/libgameservgldl/include/GameServ/DataLayer/File/FilePlayerDAO.h
Made FilePlayerDAO::Insert() only append a line instead of writing the whole file...
[irc/gameservirc.git] / gameserv-2.0 / libgameservgldl / include / GameServ / DataLayer / File / FilePlayerDAO.h
1 #ifndef __GS__FilePlayerDAO_H__
2 #define __GS__FilePlayerDAO_H__
3
4 #include <GameServ/GameLayer/GameObjects/PlayerGO.h>
5 #include <GameServ/DataLayer/IPlayerDAO.h>
6 using GameServ::GameLayer::GameObjects::PlayerGO;
7 using GameServ::DataLayer::DataAccessObjects::IPlayerDAO;
8
9 #include <boost/shared_ptr.hpp>
10 using boost::shared_ptr;
11
12 #include <string>
13 using std::string;
14
15 #include <list>
16 using std::list;
17
18 #include <map>
19 using std::map;
20
21 namespace GameServ { namespace DataLayer { namespace File
22 {
23 //! File implementation of IPlayerDAO interface
24 /*!
25 If you're using an File datasource, you will be using this
26 DAO to access Players.
27 */
28 class FilePlayerDAO : public IPlayerDAO
29 {
30 public:
31 // Ctors, Dtors ///////////////////////////////////////////////////////
32 FilePlayerDAO(void);
33 FilePlayerDAO(const string &filename);
34 virtual ~FilePlayerDAO();
35
36 // Methods ////////////////////////////////////////////////////////////
37 virtual shared_ptr<PlayerGO> GetById(const string &Id) const;
38
39 virtual list<string> GetIdsByName(const string &Name) const;
40
41 virtual bool IdExists(const string &Id) const;
42
43 virtual void Insert(shared_ptr<PlayerGO> spPlayer);
44 virtual void Update(shared_ptr<PlayerGO> spPlayer);
45
46 virtual void SetFlags(shared_ptr<PlayerGO> spPlayer, const int &flags) const;
47 virtual int GetFlags(shared_ptr<PlayerGO> spPlayer) const;
48
49 private:
50 //! Data file
51 string mFilename;
52
53 // Helper Methods /////////////////////////////////////////////////////
54 //! Get control sector information
55 void GetControlInfo(void);
56
57 //! Creates the PlayerGO found at iterator position
58 shared_ptr<PlayerGO> CreatePlayerFromLine(const string &line) const;
59 string CreateLineFromPlayer(shared_ptr<PlayerGO> spPlayer) const;
60
61 //! Get the Player database file path
62 string GetPlayerFilePath(void) const;
63
64 void Initialize(const string &filename);
65 void LoadPlayerCache();
66 void WritePlayerCache();
67
68 //! string is the id and the shared_ptr<PlayerGO> is the player object
69 map<string, shared_ptr<PlayerGO> > spPlayerCache;
70
71 };
72 } } } // GameServ.DataLayer.DataAccessObjects.File
73
74 #endif // __GS__FilePlayerDAO_H__