44 #ifndef CCXX_PERSIST_H_
45 #define CCXX_PERSIST_H_
47 #ifndef CCXX_CONFIG_H_
48 #include <cc++/config.h>
51 #ifndef CCXX_EXCEPTIONS_H_
55 #ifndef CCXX_MISSING_H_
59 #ifndef CCXX_STRING_H_
64 #ifndef NO_COMPRESSION
68 #define NO_COMPRESSION
77 #ifdef CCXX_NAMESPACES
79 #define NS_PREFIX ost::
84 #ifdef CCXX_EXCEPTIONS
85 #ifdef COMMON_STD_EXCEPTION
87 class __EXPORT PersistException :
public Exception
90 PersistException(
const String &what) : Exception(what) {};
98 PersistException(
const String& reason);
99 inline const String& getString()
const
100 {
return Exception::getString();};
102 virtual ~PersistException() {}
throw();
146 static void remove(
const char* name);
153 static BaseObject* createInstanceOf(
const char* name);
164 #define DECLARE_PERSISTENCE(ClassType) \
166 friend NS_PREFIX Engine& operator>>( NS_PREFIX Engine& ar, ClassType *&ob); \
167 friend NS_PREFIX Engine& operator<<( NS_PREFIX Engine& ar, ClassType const &ob); \
168 friend NS_PREFIX BaseObject *createNew##ClassType(); \
169 virtual const char* getPersistenceID() const; \
170 static NS_PREFIX TypeManager::Registration registrationFor##ClassType;
172 #define IMPLEMENT_PERSISTENCE(ClassType, FullyQualifiedName) \
173 NS_PREFIX BaseObject *createNew##ClassType() { return new ClassType; } \
174 const char* ClassType::getPersistenceID() const {return FullyQualifiedName;} \
175 NS_PREFIX Engine& operator>>(NS_PREFIX Engine& ar, ClassType &ob) \
176 { ar >> (NS_PREFIX BaseObject &) ob; return ar; } \
177 NS_PREFIX Engine& operator>>(NS_PREFIX Engine& ar, ClassType *&ob) \
178 { ar >> (NS_PREFIX BaseObject *&) ob; return ar; } \
179 NS_PREFIX Engine& operator<<(NS_PREFIX Engine& ar, ClassType const &ob) \
180 { ar << (NS_PREFIX BaseObject const *)&ob; return ar; } \
181 NS_PREFIX TypeManager::Registration \
182 ClassType::registrationFor##ClassType(FullyQualifiedName, \
183 createNew##ClassType);
224 virtual const char* getPersistenceID()
const;
231 virtual bool write(
Engine& archive)
const;
238 virtual bool read(
Engine& archive);
269 Engine(std::iostream& stream, EngineMode mode,
bool compress=
true) THROWS (PersistException);
290 void write(const
BaseObject &
object) THROWS (PersistException)
296 void write(
const BaseObject *
object) THROWS (PersistException);
300 #define CCXX_ENGINEWRITE_REF(valref) writeBinary((const uint8*)&valref,sizeof(valref))
313 #undef CCXX_ENGINEWRITE_REF
315 void write(
const String& str) THROWS (PersistException);
316 void write(
const std::string& str) THROWS (PersistException);
319 void writeBinary(
const uint8* data,
const uint32 size) THROWS (PersistException);
327 void read(
BaseObject &
object) THROWS (PersistException);
332 void read(
BaseObject *&
object) THROWS (PersistException);
336 #define CCXX_ENGINEREAD_REF(valref) readBinary((uint8*)&valref,sizeof(valref))
349 #undef CCXX_ENGINEREAD_REF
351 void read(
String& str) THROWS (PersistException);
352 void read(std::string& str) THROWS (PersistException);
355 void readBinary(uint8* data, uint32 size) THROWS (PersistException);
362 void readObject(
BaseObject*
object) THROWS (PersistException);
367 const String readClass() THROWS (PersistException);
373 std::iostream& myUnderlyingStream;
388 ArchiveVector myArchiveVector;
389 ArchiveMap myArchiveMap;
390 ClassVector myClassVector;
394 bool use_compression;
395 #ifndef NO_COMPRESSION
397 uint8* myCompressedDataBuffer;
398 uint8* myUncompressedDataBuffer;
399 uint8* myLastUncompressedDataRead;
490 Engine& operator <<( Engine& ar, typename std::vector<T>
const& ob) THROWS (PersistException)
492 ar << (uint32)ob.size();
493 for(
unsigned int i=0; i < ob.size(); ++i)
504 Engine& operator >>(
Engine& ar,
typename std::vector<T>& ob) THROWS (PersistException)
510 for(uint32 i=0; i < siz; ++i)
521 Engine& operator <<( Engine& ar, typename std::deque<T>
const& ob) THROWS (PersistException)
523 ar << (uint32)ob.size();
524 for(
typename std::deque<T>::const_iterator it=ob.begin(); it != ob.end(); ++it)
535 Engine& operator >>(
Engine& ar,
typename std::deque<T>& ob) THROWS (PersistException)
541 for(uint32 i=0; i < siz; ++i) {
555 template<
class Key,
class Value>
556 Engine& operator <<( Engine& ar, typename std::map<Key,Value>
const & ob) THROWS (PersistException)
558 ar << (uint32)ob.size();
559 for(
typename std::map<Key,Value>::const_iterator it = ob.begin();it != ob.end();++it)
560 ar << it->first << it->second;
569 template<
class Key,
class Value>
570 Engine& operator >>(
Engine& ar,
typename std::map<Key,Value>& ob) THROWS (PersistException)
575 for(uint32 i=0; i < siz; ++i) {
587 template<
class x,
class y>
588 Engine& operator <<( Engine& ar, std::pair<x,y> &ob) THROWS (PersistException)
590 ar << ob.first << ob.second;
598 template<
class x,
class y>
599 Engine& operator >>(
Engine& ar, std::pair<x, y> &ob) THROWS (PersistException)
601 ar >> ob.first >> ob.second;
605 #ifdef CCXX_NAMESPACES
void write(int8 i) THROWS(PersistException)
void write(uint32 i) THROWS(PersistException)
void read(uint8 &i) THROWS(PersistException)
Common C++ generic string class.
std::map< BaseObject const *, int32 > ArchiveMap
void read(double &i) THROWS(PersistException)
substitute functions which may be missing in target platform libc.
void write(int32 i) THROWS(PersistException)
std::vector< BaseObject * > ArchiveVector
Typedefs for the Persistence::BaseObject support.
This manages a registration to the typemanager - attempting to remove problems with the optimisers...
This is a generic and portable string class.
EngineMode
These are the modes the Persistence::Engine can work in.
GNU Common C++ exception model base classes.
class BaseObject *(* NewBaseObjectFunction)(void)
void write(double i) THROWS(PersistException)
__EXPORT std::ostream & operator<<(std::ostream &os, const IPV4Address &ia)
void write(uint8 i) THROWS(PersistException)
void read(float &i) THROWS(PersistException)
std::map< String, int32 > ClassMap
void write(int16 i) THROWS(PersistException)
#define CCXX_ENGINEREAD_REF(valref)
This class manages the types for generation of the persistent objects.
void read(uint16 &i) THROWS(PersistException)
void read(int32 &i) THROWS(PersistException)
void read(int16 &i) THROWS(PersistException)
void write(uint16 i) THROWS(PersistException)
#define CCXX_ENGINEWRITE_REF(valref)
void read(uint32 &i) THROWS(PersistException)
void read(int8 &i) THROWS(PersistException)
std::vector< String > ClassVector
std::map< String, NewBaseObjectFunction > StringFunctionMap
void write(float i) THROWS(PersistException)