43 #ifndef CCXX_PERSIST_H_
44 #define CCXX_PERSIST_H_
46 #ifndef CCXX_CONFIG_H_
50 #ifndef CCXX_EXCEPTIONS_H_
54 #ifndef CCXX_MISSING_H_
58 #ifndef CCXX_STRING_H_
63 #ifndef NO_COMPRESSION
67 #define NO_COMPRESSION
76 #ifdef CCXX_NAMESPACES
78 #define NS_PREFIX ost::
83 #ifdef CCXX_EXCEPTIONS
84 #ifdef COMMON_STD_EXCEPTION
86 class __EXPORT PersistException :
public Exception
89 PersistException(
const String &what) : Exception(what) {};
97 PersistException(
const String& reason);
98 inline const String& getString()
const
99 {
return Exception::getString();};
101 virtual ~PersistException() {}
throw();
145 static void remove(
const char* name);
152 static BaseObject* createInstanceOf(
const char* name);
163 #define DECLARE_PERSISTENCE(ClassType) \
165 friend NS_PREFIX Engine& operator>>( NS_PREFIX Engine& ar, ClassType *&ob); \
166 friend NS_PREFIX Engine& operator<<( NS_PREFIX Engine& ar, ClassType const &ob); \
167 friend NS_PREFIX BaseObject *createNew##ClassType(); \
168 virtual const char* getPersistenceID() const; \
169 static NS_PREFIX TypeManager::Registration registrationFor##ClassType;
171 #define IMPLEMENT_PERSISTENCE(ClassType, FullyQualifiedName) \
172 NS_PREFIX BaseObject *createNew##ClassType() { return new ClassType; } \
173 const char* ClassType::getPersistenceID() const {return FullyQualifiedName;} \
174 NS_PREFIX Engine& operator>>(NS_PREFIX Engine& ar, ClassType &ob) \
175 { ar >> (NS_PREFIX BaseObject &) ob; return ar; } \
176 NS_PREFIX Engine& operator>>(NS_PREFIX Engine& ar, ClassType *&ob) \
177 { ar >> (NS_PREFIX BaseObject *&) ob; return ar; } \
178 NS_PREFIX Engine& operator<<(NS_PREFIX Engine& ar, ClassType const &ob) \
179 { ar << (NS_PREFIX BaseObject const *)&ob; return ar; } \
180 NS_PREFIX TypeManager::Registration \
181 ClassType::registrationFor##ClassType(FullyQualifiedName, \
182 createNew##ClassType);
223 virtual const char* getPersistenceID()
const;
230 virtual bool write(
Engine& archive)
const;
237 virtual bool read(
Engine& archive);
267 Engine(std::iostream& stream, EngineMode mode)
THROWS (PersistException);
293 #define CCXX_ENGINEWRITE_REF(valref) writeBinary((const uint8*)&valref,sizeof(valref))
306 #undef CCXX_ENGINEWRITE_REF
308 void write(
const String& str)
THROWS (PersistException);
309 void write(
const std::string& str)
THROWS (PersistException);
312 void writeBinary(
const uint8* data,
const uint32 size)
THROWS (PersistException);
329 #define CCXX_ENGINEREAD_REF(valref) readBinary((uint8*)&valref,sizeof(valref))
342 #undef CCXX_ENGINEREAD_REF
345 void read(std::string& str)
THROWS (PersistException);
366 std::iostream& myUnderlyingStream;
371 EngineMode myOperationalMode;
376 typedef std::vector<
BaseObject*> ArchiveVector;
378 typedef std::vector<
String> ClassVector;
381 ArchiveVector myArchiveVector;
382 ArchiveMap myArchiveMap;
383 ClassVector myClassVector;
387 #ifndef NO_COMPRESSION
389 uint8* myCompressedDataBuffer;
390 uint8* myUncompressedDataBuffer;
391 uint8* myLastUncompressedDataRead;
397 __EXPORT Engine& operator >>( Engine& ar, BaseObject &ob)
THROWS (PersistException);
399 __EXPORT Engine& operator >>( Engine& ar, BaseObject *&ob)
THROWS (PersistException);
448 __EXPORT Engine& operator >>( Engine& ar,
float& ob)
THROWS (PersistException);
453 __EXPORT Engine& operator >>( Engine& ar,
double& ob)
THROWS (PersistException);
458 __EXPORT Engine& operator >>( Engine& ar, String& ob)
THROWS (PersistException);
463 __EXPORT Engine& operator >>( Engine& ar, std::string& ob)
THROWS (PersistException);
468 __EXPORT Engine& operator >>( Engine& ar,
bool& ob)
THROWS (PersistException);
482 Engine& operator <<( Engine& ar, typename std::vector<T>
const& ob)
THROWS (PersistException)
485 for(
unsigned int i=0; i < ob.size(); ++i)
502 for(
uint32 i=0; i < siz; ++i)
513 Engine& operator <<( Engine& ar, typename std::deque<T>
const& ob)
THROWS (PersistException)
516 for(
typename std::deque<T>::const_iterator it=ob.begin(); it != ob.end(); ++it)
533 for(
uint32 i=0; i < siz; ++i) {
547 template<
class Key,
class Value>
548 Engine& operator <<( Engine& ar, typename std::map<Key,Value>
const & ob)
THROWS (PersistException)
551 for(
typename std::map<Key,Value>::const_iterator it = ob.begin();it != ob.end();++it)
552 ar << it->first << it->second;
561 template<
class Key,
class Value>
567 for(
uint32 i=0; i < siz; ++i) {
579 template<
class x,
class y>
580 Engine& operator <<( Engine& ar, std::pair<x,y> &ob)
THROWS (PersistException)
582 ar << ob.first << ob.second;
590 template<
class x,
class y>
593 ar >> ob.first >> ob.second;
597 #ifdef CCXX_NAMESPACES