23 #if defined(OLD_STDCPP) || defined(NEW_STDCPP)
24 #if !defined(_MSC_VER) || _MSC_VER >= 1400
25 #ifndef _UCOMMON_PERSIST_H_
26 #define _UCOMMON_PERSIST_H_
28 #ifndef _UCOMMON_PLATFORM_H_
39 #define NS_PREFIX ucc::
42 typedef class PersistObject* (*NewPersistObjectFunction) (void);
44 class __EXPORT PersistException
47 PersistException(
const std::string& reason);
48 const std::string& getString()
const;
50 virtual ~PersistException() throw();
74 registration(
const char* name, NewPersistObjectFunction func);
83 static void add(
const char* name, NewPersistObjectFunction construction);
88 static void remove(
const char* name);
97 typedef std::map<std::string,NewPersistObjectFunction> StringFunctionMap;
105 #define DECLARE_PERSISTENCE(ClassType) \
107 friend NS_PREFIX PersistEngine& operator>>( NS_PREFIX PersistEngine& ar, ClassType *&ob); \
108 friend NS_PREFIX PersistEngine& operator<<( NS_PREFIX PersistEngine& ar, ClassType const &ob); \
109 friend NS_PREFIX PersistObject *createNew##ClassType(); \
110 virtual const char* getPersistenceID() const; \
111 static NS_PREFIX TypeManager::Registration registrationFor##ClassType;
113 #define IMPLEMENT_PERSISTENCE(ClassType, FullyQualifiedName) \
114 NS_PREFIX PersistObject *createNew##ClassType() { return new ClassType; } \
115 const char* ClassType::getPersistenceID() const {return FullyQualifiedName;} \
116 NS_PREFIX PersistEngine& operator>>(NS_PREFIX PersistEngine& ar, ClassType &ob) \
117 { ar >> (NS_PREFIX PersistObject &) ob; return ar; } \
118 NS_PREFIX PersistEngine& operator>>(NS_PREFIX PersistEngine& ar, ClassType *&ob) \
119 { ar >> (NS_PREFIX PersistObject *&) ob; return ar; } \
120 NS_PREFIX PersistEngine& operator<<(NS_PREFIX PersistEngine& ar, ClassType const &ob) \
121 { ar << (NS_PREFIX PersistObject const *)&ob; return ar; } \
122 NS_PREFIX TypeManager::Registration \
123 ClassType::registrationFor##ClassType(FullyQualifiedName, \
124 createNew##ClassType);
165 virtual const char* getPersistenceID()
const;
206 PersistEngine(std::iostream& stream, EngineMode mode)
throw(PersistException);
221 void write(
const PersistObject *
object)
throw(PersistException);
225 #define CCXX_ENGINEWRITE_REF(valref) writeBinary((const uint8_t*)&valref,sizeof(valref))
226 inline void write(int8_t i)
throw(PersistException) { CCXX_ENGINEWRITE_REF(i); }
227 inline void write(uint8_t i)
throw(PersistException) { CCXX_ENGINEWRITE_REF(i); }
228 inline void write(int16_t i)
throw(PersistException) { CCXX_ENGINEWRITE_REF(i); }
229 inline void write(uint16_t i)
throw(PersistException) { CCXX_ENGINEWRITE_REF(i); }
230 inline void write(int32_t i)
throw(PersistException) { CCXX_ENGINEWRITE_REF(i); }
231 inline void write(uint32_t i)
throw(PersistException) { CCXX_ENGINEWRITE_REF(i); }
232 inline void write(
float i)
throw(PersistException) { CCXX_ENGINEWRITE_REF(i); }
233 inline void write(
double i)
throw(PersistException) { CCXX_ENGINEWRITE_REF(i); }
234 inline void write(
bool i)
throw(PersistException) { CCXX_ENGINEWRITE_REF(i); }
235 #undef CCXX_ENGINEWRITE_REF
237 void write(
const std::string& str)
throw(PersistException);
240 void writeBinary(
const uint8_t* data,
const uint32_t size)
throw(PersistException);
247 void read(PersistObject &
object)
throw(PersistException);
252 void read(PersistObject *&
object)
throw(PersistException);
256 #define CCXX_ENGINEREAD_REF(valref) readBinary((uint8_t*)&valref,sizeof(valref))
257 inline void read(int8_t& i)
throw(PersistException) { CCXX_ENGINEREAD_REF(i); }
258 inline void read(uint8_t& i)
throw(PersistException) { CCXX_ENGINEREAD_REF(i); }
259 inline void read(int16_t& i)
throw(PersistException) { CCXX_ENGINEREAD_REF(i); }
260 inline void read(uint16_t& i)
throw(PersistException) { CCXX_ENGINEREAD_REF(i); }
261 inline void read(int32_t& i)
throw(PersistException) { CCXX_ENGINEREAD_REF(i); }
262 inline void read(uint32_t& i)
throw(PersistException) { CCXX_ENGINEREAD_REF(i); }
263 inline void read(
float& i)
throw(PersistException) { CCXX_ENGINEREAD_REF(i); }
264 inline void read(
double& i)
throw(PersistException) { CCXX_ENGINEREAD_REF(i); }
265 inline void read(
bool &i)
throw(PersistException) { CCXX_ENGINEREAD_REF(i); }
266 #undef CCXX_ENGINEREAD_REF
268 void read(std::string& str)
throw(PersistException);
271 void readBinary(uint8_t* data, uint32_t size)
throw(PersistException);
278 void readObject(PersistObject*
object)
throw(PersistException);
283 const std::string readClass() throw(PersistException);
289 std::iostream& myUnderlyingStream;
294 EngineMode myOperationalMode;
299 typedef std::vector<PersistObject*> ArchiveVector;
300 typedef std::map<PersistObject const*, int32_t> ArchiveMap;
301 typedef std::vector<std::
string> ClassVector;
302 typedef std::map<std::
string, int32_t> ClassMap;
304 ArchiveVector myArchiveVector;
305 ArchiveMap myArchiveMap;
306 ClassVector myClassVector;
310 #define CCXX_RE(ar,ob) ar.read(ob); return ar
311 #define CCXX_WE(ar,ob) ar.write(ob); return ar
386 PersistEngine& operator <<( PersistEngine& ar, typename std::vector<T>
const& ob)
throw(PersistException)
388 ar << (uint32_t)ob.size();
389 for(
unsigned int i=0; i < ob.size(); ++i)
406 for(uint32_t i=0; i < siz; ++i)
417 PersistEngine& operator <<( PersistEngine& ar, typename std::deque<T>
const& ob)
throw(PersistException)
419 ar << (uint32_t)ob.size();
420 for(
typename std::deque<T>::const_iterator it=ob.begin(); it != ob.end(); ++it)
437 for(uint32_t i=0; i < siz; ++i) {
451 template<
class Key,
class Value>
452 PersistEngine& operator <<( PersistEngine& ar, typename std::map<Key,Value>
const & ob)
throw(PersistException)
454 ar << (uint32_t)ob.size();
455 for(
typename std::map<Key,Value>::const_iterator it = ob.begin();it != ob.end();++it)
456 ar << it->first << it->second;
465 template<
class Key,
class Value>
471 for(uint32_t i=0; i < siz; ++i) {
483 template<
class x,
class y>
484 PersistEngine& operator <<( PersistEngine& ar, std::pair<x,y> &ob)
throw(PersistException)
486 ar << ob.first << ob.second;
494 template<
class x,
class y>
497 ar >> ob.first >> ob.second;
Various miscellaneous platform specific headers and defines.
This manages a registration to the typemanager - attempting to remove problems with the optimizers...
EngineMode
These are the modes the Persistence::Engine can work in.
void write(const PersistObject &object)
writes a PersistObject from a reference.
Type manager for persistence engine.
Stream serialization of persistent classes.