📄 persist.h
字号:
#undef CCXX_ENGINEWRITE_REF void write(const String& str) THROWS (PersistException); void write(const std::string& str) THROWS (PersistException); // Every write operation boils down to one or more of these void writeBinary(const uint8* data, const uint32 size) THROWS (PersistException); // Read Operations /** * reads a BaseObject into a reference overwriting the object. */ void read(BaseObject &object) THROWS (PersistException); /** * reads a BaseObject into a pointer allocating memory for the object if necessary. */ void read(BaseObject *&object) THROWS (PersistException); // reads supported primitive types // shortcut, to make the following more readable#define CCXX_ENGINEREAD_REF(valref) readBinary((uint8*)&valref,sizeof(valref)) void read(int8& i) THROWS (PersistException) { CCXX_ENGINEREAD_REF(i); } void read(uint8& i) THROWS (PersistException) { CCXX_ENGINEREAD_REF(i); } void read(int16& i) THROWS (PersistException) { CCXX_ENGINEREAD_REF(i); } void read(uint16& i) THROWS (PersistException) { CCXX_ENGINEREAD_REF(i); } void read(int32& i) THROWS (PersistException) { CCXX_ENGINEREAD_REF(i); } void read(uint32& i) THROWS (PersistException) { CCXX_ENGINEREAD_REF(i); }#ifdef HAVE_64_BITS void read(int64& i) THROWS (PersistException) { CCXX_ENGINEREAD_REF(i); } void read(uint64& i) THROWS (PersistException) { CCXX_ENGINEREAD_REF(i); }#endif void read(float& i) THROWS (PersistException) { CCXX_ENGINEREAD_REF(i); } void read(double& i) THROWS (PersistException) { CCXX_ENGINEREAD_REF(i); }#undef CCXX_ENGINEREAD_REF void read(String& str) THROWS (PersistException); void read(std::string& str) THROWS (PersistException); // Every read operation boild down to one or more of these void readBinary(uint8* data, uint32 size) THROWS (PersistException);private: /** * reads the actual object data into a pre-instantiated object pointer * by calling the read function of the derived class. */ void readObject(BaseObject* object) THROWS (PersistException); /** * reads in a class name, and caches it into the ClassMap. */ const String readClass() THROWS (PersistException); /** * The underlying stream */ std::iostream& myUnderlyingStream; /** * The mode of the engine. read or write */ EngineMode myOperationalMode; /** * Typedefs for the Persistence::BaseObject support */ typedef std::vector<BaseObject*> ArchiveVector; typedef std::map<BaseObject const*, int32> ArchiveMap; typedef std::vector<String> ClassVector; typedef std::map<String, int32> ClassMap; ArchiveVector myArchiveVector; ArchiveMap myArchiveMap; ClassVector myClassVector; ClassMap myClassMap; // Compression support#ifndef NO_COMPRESSION z_stream myZStream; uint8* myCompressedDataBuffer; uint8* myUncompressedDataBuffer; uint8* myLastUncompressedDataRead;#endif};// Standard >> and << stream operators for BaseObject/** @relates Engine */__EXPORT Engine& operator >>( Engine& ar, BaseObject &ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator >>( Engine& ar, BaseObject *&ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator <<( Engine& ar, BaseObject const &ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator <<( Engine& ar, BaseObject const *ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator >>( Engine& ar, int8& ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator <<( Engine& ar, int8 ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator >>( Engine& ar, uint8& ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator <<( Engine& ar, uint8 ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator >>( Engine& ar, int16& ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator <<( Engine& ar, int16 ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator >>( Engine& ar, uint16& ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator <<( Engine& ar, uint16 ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator >>( Engine& ar, int32& ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator <<( Engine& ar, int32 ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator >>( Engine& ar, uint32& ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator <<( Engine& ar, uint32 ob) THROWS (PersistException);#ifdef HAVE_64_BITS/** @relates Engine */__EXPORT Engine& operator >>( Engine& ar, int64& ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator <<( Engine& ar, int64 ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator >>( Engine& ar, uint64& ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator <<( Engine& ar, uint64 ob) THROWS (PersistException);#endif/** @relates Engine */__EXPORT Engine& operator >>( Engine& ar, float& ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator <<( Engine& ar, float ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator >>( Engine& ar, double& ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator <<( Engine& ar, double ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator >>( Engine& ar, String& ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator <<( Engine& ar, String ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator >>( Engine& ar, std::string& ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator <<( Engine& ar, std::string ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator >>( Engine& ar, bool& ob) THROWS (PersistException);/** @relates Engine */__EXPORT Engine& operator <<( Engine& ar, bool ob) THROWS (PersistException);/** * The following are templated classes *//** * @relates Engine * serialize a vector of some serializable content to * the engine */template<class T>Engine& operator <<( Engine& ar, typename std::vector<T> const& ob) THROWS (PersistException){ ar << (uint32)ob.size(); for(unsigned int i=0; i < ob.size(); ++i) ar << ob[i]; return ar;}/** * @relates Engine * deserialize a vector of deserializable content from * an engine. */template<class T>Engine& operator >>( Engine& ar, typename std::vector<T>& ob) THROWS (PersistException){ ob.clear(); uint32 siz; ar >> siz; ob.resize(siz); for(uint32 i=0; i < siz; ++i) ar >> ob[i]; return ar;}/** * @relates Engine * serialize a deque of some serializable content to * the engine */template<class T>Engine& operator <<( Engine& ar, typename std::deque<T> const& ob) THROWS (PersistException){ ar << (uint32)ob.size(); for(typename std::deque<T>::const_iterator it=ob.begin(); it != ob.end(); ++it) ar << *it; return ar;}/** * @relates Engine * deserialize a deque of deserializable content from * an engine. */template<class T>Engine& operator >>( Engine& ar, typename std::deque<T>& ob) THROWS (PersistException){ ob.clear(); uint32 siz; ar >> siz; //ob.resize(siz); for(uint32 i=0; i < siz; ++i) { T node; ar >> node; ob.push_back(node); //ar >> ob[i]; } return ar;}/** * @relates Engine * serialize a map with keys/values which both are serializeable * to an engine. */template<class Key, class Value>Engine& operator <<( Engine& ar, typename std::map<Key,Value> const & ob) THROWS (PersistException){ ar << (uint32)ob.size(); for(typename std::map<Key,Value>::const_iterator it = ob.begin();it != ob.end();++it) ar << it->first << it->second; return ar;}/** * @relates Engine * deserialize a map with keys/values which both are serializeable * from an engine. */template<class Key, class Value>Engine& operator >>( Engine& ar, typename std::map<Key,Value>& ob) THROWS (PersistException){ ob.clear(); uint32 siz; ar >> siz; for(uint32 i=0; i < siz; ++i) { Key a; ar >> a; ar >> ob[a]; } return ar;}/** * @relates Engine * serialize a pair of some serializable content to the engine. */template<class x, class y>Engine& operator <<( Engine& ar, std::pair<x,y> &ob) THROWS (PersistException){ ar << ob.first << ob.second; return ar;}/** * @relates Engine * deserialize a pair of some serializable content to the engine. */template<class x, class y>Engine& operator >>(Engine& ar, std::pair<x, y> &ob) THROWS (PersistException){ ar >> ob.first >> ob.second; return ar;}#ifdef CCXX_NAMESPACES}#endif#endif/** EMACS ** * Local variables: * mode: c++ * c-basic-offset: 8 * End: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -