1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef CDB_SYNCHRONISED_H
24 #define CDB_SYNCHRONISED_H
27 #include "nel/misc/cdb.h"
28 #include "nel/misc/cdb_branch.h"
29 #include "nel/misc/cdb_manager.h"
32 * Class to manage a database of properties
33 * \author Stephane Coutelas
34 * \author Nevrax France
37 class CCDBSynchronised
: public NLMISC::CCDBManager
39 /// string associations
40 std::map
<uint32
,std::string
> _Strings
;
42 /// True while the first database packet has not been completely processed (including branch observers)
45 /// The number of "init database packet" received
46 uint8 _InitDeltaReceived
;
50 /// exception thrown when database is not initialized
51 struct EDBNotInit
: public NLMISC::Exception
53 EDBNotInit() : Exception ("Property Database not initialized") {}
62 * Return a ptr on the node
63 * \return ptr on the node
65 NLMISC::CCDBNodeBranch
* getNodePtr() { return _Database
; }
68 * Build the structure of the database from a file
69 * \param fileName is the name of file containing the database structure
71 void init( const std::string
&fileName
, class NLMISC::IProgressCallback
&progressCallBack
);
74 * Load a backup of the database
75 * \param fileName is the name of the backup file
77 void read( const std::string
&fileName
);
80 * Save a backup of the database
81 * \param fileName is the name of the backup file
83 void write( const std::string
&fileName
);
86 * Update the database from a stream coming from the FE
89 void readDelta( NLMISC::TGameCycle gc
, NLMISC::CBitMemStream
& s
, uint bank
);
92 * Return the value of a property (the update flag is set to false)
93 * \param name is the name of the property
94 * \return the value of the property
96 sint64
getProp( const std::string
&name
);
99 * Set the value of a property (the update flag is set to true)
100 * \param name is the name of the property
101 * \param value is the value of the property
102 * \return bool : 'true' if the property was found.
104 bool setProp(const std::string
&name
, sint64 value
);
107 * Return the string associated with id
108 * \param id is the string id
111 std::string
getString( uint32 id
);
114 * Set a new string association
115 * \param id is the string id
116 * \param str is the new string
118 void setString( uint32 id
, const std::string
&);
128 ~CCDBSynchronised() { clear(); }
130 /// Return true while the first database packet has not been completely received
131 bool initInProgress() const { return _InitInProgress
; }
136 /// Reset the init state (if you relauch the game from scratch)
137 void resetInitState() { _InitDeltaReceived
= 0; _InitInProgress
= true; writeInitInProgressIntoUIDB(); }
139 /// Called after flushObserversCalls() as it calls the observers for branches
140 void setChangesProcessed()
142 if ( allInitPacketReceived() )
144 _InitInProgress
= false;
145 writeInitInProgressIntoUIDB(); // replaced by DECLARE_INTERFACE_USER_FCT(isDBInitInProgress)
151 friend void impulseDatabaseInitPlayer( NLMISC::CBitMemStream
&impulse
);
152 friend void impulseInitInventory( NLMISC::CBitMemStream
&impulse
);
154 void setInitPacketReceived() { ++_InitDeltaReceived
; }
155 bool allInitPacketReceived() const { return _InitDeltaReceived
== 2; } // Classic database + inventory
157 void writeInitInProgressIntoUIDB();
159 NLMISC::CRefPtr
<NLMISC::CCDBNodeLeaf
> m_CDBInitInProgressDB
;
163 #endif // CDB_SYNCHRONISED_H