24 #ifndef UCOMMON_SYSRUNTIME 25 #ifndef COMMONCPP_PERSIST_H_ 26 #define COMMONCPP_PERSIST_H_ 28 #ifndef COMMONCPP_CONFIG_H_ 29 #include <commoncpp/config.h> 41 typedef class PersistObject* (*NewPersistObjectFunction) (void);
43 class __EXPORT PersistException
46 PersistException(
const std::string& reason);
47 const std::string& getString()
const;
49 virtual ~PersistException() throw();
76 registration(
const char* name, NewPersistObjectFunction func);
87 static void add(
const char* name, NewPersistObjectFunction construction);
92 static void remove(
const char* name);
101 typedef std::map<std::string,NewPersistObjectFunction> StringFunctionMap;
109 #define DECLARE_PERSISTENCE(ClassType) \ 111 friend ucommon::PersistEngine& operator>>( ucommon::PersistEngine& ar, ClassType *&ob); \ 112 friend ucommon::PersistEngine& operator<<( ucommon::PersistEngine& ar, ClassType const &ob); \ 113 friend ucommon::PersistObject *createNew##ClassType(); \ 114 virtual const char* getPersistenceID() const; \ 115 static ucommon::TypeManager::Registration registrationFor##ClassType; 117 #define IMPLEMENT_PERSISTENCE(ClassType, FullyQualifiedName) \ 118 ucommon::PersistObject *createNew##ClassType() { return new ClassType; } \ 119 const char* ClassType::getPersistenceID() const {return FullyQualifiedName;} \ 120 ucommon::PersistEngine& operator>>(ucommon::PersistEngine& ar, ClassType &ob) \ 121 { ar >> (ucommon::PersistObject &) ob; return ar; } \ 122 ucommon::PersistEngine& operator>>(ucommon::PersistEngine& ar, ClassType *&ob) \ 123 { ar >> (ucommon::PersistObject *&) ob; return ar; } \ 124 ucommon::PersistEngine& operator<<(ucommon::PersistEngine& ar, ClassType const &ob) \ 125 { ar << (ucommon::PersistObject const *)&ob; return ar; } \ 126 ucommon::TypeManager::Registration \ 127 ClassType::registrationFor##ClassType(FullyQualifiedName, \ 128 createNew##ClassType); 169 virtual const char* getPersistenceID()
const;
213 PersistEngine(std::iostream& stream, EngineMode mode)
throw(PersistException);
228 void write(
const PersistObject *
object)
throw(PersistException);
232 #define CCXX_ENGINEWRITE_REF(valref) writeBinary((const uint8_t*)&valref,sizeof(valref)) 233 inline void write(int8_t i)
throw(PersistException) { CCXX_ENGINEWRITE_REF(i); }
234 inline void write(uint8_t i)
throw(PersistException) { CCXX_ENGINEWRITE_REF(i); }
235 inline void write(int16_t i)
throw(PersistException) { CCXX_ENGINEWRITE_REF(i); }
236 inline void write(uint16_t i)
throw(PersistException) { CCXX_ENGINEWRITE_REF(i); }
237 inline void write(int32_t i)
throw(PersistException) { CCXX_ENGINEWRITE_REF(i); }
238 inline void write(uint32_t i)
throw(PersistException) { CCXX_ENGINEWRITE_REF(i); }
239 inline void write(
float i)
throw(PersistException) { CCXX_ENGINEWRITE_REF(i); }
240 inline void write(
double i)
throw(PersistException) { CCXX_ENGINEWRITE_REF(i); }
241 inline void write(
bool i)
throw(PersistException) { CCXX_ENGINEWRITE_REF(i); }
242 #undef CCXX_ENGINEWRITE_REF 244 void write(
const std::string& str)
throw(PersistException);
247 void writeBinary(
const uint8_t* data,
const uint32_t size)
throw(PersistException);
254 void read(PersistObject &
object)
throw(PersistException);
259 void read(PersistObject *&
object)
throw(PersistException);
263 #define CCXX_ENGINEREAD_REF(valref) readBinary((uint8_t*)&valref,sizeof(valref)) 264 inline void read(int8_t& i)
throw(PersistException) { CCXX_ENGINEREAD_REF(i); }
265 inline void read(uint8_t& i)
throw(PersistException) { CCXX_ENGINEREAD_REF(i); }
266 inline void read(int16_t& i)
throw(PersistException) { CCXX_ENGINEREAD_REF(i); }
267 inline void read(uint16_t& i)
throw(PersistException) { CCXX_ENGINEREAD_REF(i); }
268 inline void read(int32_t& i)
throw(PersistException) { CCXX_ENGINEREAD_REF(i); }
269 inline void read(uint32_t& i)
throw(PersistException) { CCXX_ENGINEREAD_REF(i); }
270 inline void read(
float& i)
throw(PersistException) { CCXX_ENGINEREAD_REF(i); }
271 inline void read(
double& i)
throw(PersistException) { CCXX_ENGINEREAD_REF(i); }
272 inline void read(
bool &i)
throw(PersistException) { CCXX_ENGINEREAD_REF(i); }
273 #undef CCXX_ENGINEREAD_REF 275 void read(std::string& str)
throw(PersistException);
278 void readBinary(uint8_t* data, uint32_t size)
throw(PersistException);
285 void readObject(PersistObject*
object)
throw(PersistException);
290 const std::string readClass() throw(PersistException);
296 std::iostream& myUnderlyingStream;
301 EngineMode myOperationalMode;
306 typedef std::vector<PersistObject*> ArchiveVector;
307 typedef std::map<PersistObject const*, int32_t> ArchiveMap;
308 typedef std::vector<std::
string> ClassVector;
309 typedef std::map<std::
string, int32_t> ClassMap;
311 ArchiveVector myArchiveVector;
312 ArchiveMap myArchiveMap;
313 ClassVector myClassVector;
317 #define CCXX_RE(ar,ob) ar.read(ob); return ar 318 #define CCXX_WE(ar,ob) ar.write(ob); return ar 395 ar << (uint32_t)ob.size();
396 for(
unsigned int i=0; i < ob.size(); ++i)
413 for(uint32_t i=0; i < siz; ++i)
426 ar << (uint32_t)ob.size();
427 for(
typename std::deque<T>::const_iterator it=ob.begin(); it != ob.end(); ++it)
444 for(uint32_t i=0; i < siz; ++i) {
458 template<
class Key,
class Value>
461 ar << (uint32_t)ob.size();
462 for(
typename std::map<Key,Value>::const_iterator it = ob.begin();it != ob.end();++it)
463 ar << it->first << it->second;
472 template<
class Key,
class Value>
478 for(uint32_t i=0; i < siz; ++i) {
490 template<
class x,
class y>
493 ar << ob.first << ob.second;
501 template<
class x,
class y>
504 ar >> ob.first >> ob.second;
PersistEngine & operator >>(PersistEngine &ar, int16_t &ob)
PersistEngine & operator >>(PersistEngine &ar, uint16_t &ob)
This manages a registration to the typemanager - attempting to remove problems with the optimizers.
PersistEngine & operator >>(PersistEngine &ar, uint8_t &ob)
PersistEngine & operator >>(PersistEngine &ar, std::pair< x, y > &ob)
PersistEngine & operator >>(PersistEngine &ar, typename std::map< Key, Value > &ob)
Stream serialization of persistent classes.
PersistEngine & operator >>(PersistEngine &ar, PersistObject *&ob)
PersistEngine & operator >>(PersistEngine &ar, std::string &ob)
Type manager for persistence engine.
PersistEngine & operator >>(PersistEngine &ar, double &ob)
PersistEngine & operator >>(PersistEngine &ar, uint32_t &ob)
PersistEngine & operator >>(PersistEngine &ar, typename std::deque< T > &ob)
EngineMode
These are the modes the Persistence::Engine can work in.
PersistEngine & operator >>(PersistEngine &ar, PersistObject &ob)
PersistEngine & operator >>(PersistEngine &ar, int32_t &ob)
PersistEngine & operator >>(PersistEngine &ar, int8_t &ob)
PersistEngine & operator >>(PersistEngine &ar, bool &ob)
PersistEngine & operator >>(PersistEngine &ar, float &ob)
void write(const PersistObject &object)
writes a PersistObject from a reference.
PersistEngine & operator >>(PersistEngine &ar, typename std::vector< T > &ob)