| |
| |
| #ifndef TPERSIST_INCLUDED |
| #define TPERSIST_INCLUDED |
| |
| |
| |
| |
| #include "tcommon.h" |
| |
| #undef DVAPI |
| #undef DVVAR |
| #ifdef TSTREAM_EXPORTS |
| #define DVAPI DV_EXPORT_API |
| #define DVVAR DV_EXPORT_VAR |
| #else |
| #define DVAPI DV_IMPORT_API |
| #define DVVAR DV_IMPORT_VAR |
| #endif |
| |
| |
| |
| class TPersistDeclaration; |
| class TIStream; |
| class TOStream; |
| |
| |
| |
| class DVAPI TPersist |
| { |
| public: |
| virtual ~TPersist(){}; |
| |
| |
| |
| |
| |
| |
| |
| virtual void loadData(TIStream &is) = 0; |
| |
| |
| |
| |
| |
| |
| |
| virtual void saveData(TOStream &os) = 0; |
| |
| |
| |
| |
| inline string getStreamTag() const; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| virtual const TPersistDeclaration *getDeclaration() const = 0; |
| |
| typedef TPersist *CreateProc(); |
| static void declare(CreateProc *); |
| |
| |
| |
| |
| |
| static TPersist *create(const string &name); |
| }; |
| |
| |
| |
| |
| |
| |
| |
| class DVAPI TPersistDeclaration |
| { |
| string m_id; |
| |
| public: |
| TPersistDeclaration(const string &id); |
| virtual ~TPersistDeclaration() {} |
| string getId() const { return m_id; }; |
| virtual TPersist *create() const = 0; |
| }; |
| |
| |
| |
| inline string TPersist::getStreamTag() const { return getDeclaration()->getId(); } |
| |
| |
| |
| |
| |
| template <class T> |
| class TPersistDeclarationT : public TPersistDeclaration |
| { |
| public: |
| |
| |
| |
| |
| TPersistDeclarationT(const string &id) : TPersistDeclaration(id) {} |
| |
| |
| |
| |
| |
| TPersist *create() const { return new T; }; |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #define PERSIST_DECLARATION(T) \ |
| private: \ |
| static TPersistDeclarationT<T> m_declaration; \ |
| \ |
| public: \ |
| const TPersistDeclaration *getDeclaration() const \ |
| { \ |
| return &m_declaration; \ |
| } |
| |
| #define PERSIST_IDENTIFIER(T, I) \ |
| TPersistDeclarationT<T> T::m_declaration(I); |
| |
| |
| |
| #endif |
| |