| #pragma once |
| |
| #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 std::string getStreamTag() const; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| virtual const TPersistDeclaration *getDeclaration() const = 0; |
| |
| typedef TPersist *CreateProc(); |
| static void declare(CreateProc *); |
| |
| |
| |
| |
| |
| static TPersist *create(const std::string &name); |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| class DVAPI TPersistDeclaration { |
| std::string m_id; |
| |
| public: |
| TPersistDeclaration(const std::string &id); |
| virtual ~TPersistDeclaration() {} |
| std::string getId() const { return m_id; }; |
| virtual TPersist *create() const = 0; |
| }; |
| |
| |
| |
| inline std::string TPersist::getStreamTag() const { |
| return getDeclaration()->getId(); |
| } |
| |
| |
| |
| |
| |
| |
| template <class T> |
| class TPersistDeclarationT final : public TPersistDeclaration { |
| public: |
| |
| |
| |
| |
| TPersistDeclarationT(const std::string &id) : TPersistDeclaration(id) {} |
| |
| |
| |
| |
| |
| TPersist *create() const override { return new T; }; |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #define PERSIST_DECLARATION(T) \ |
| \ |
| private: \ |
| static TPersistDeclarationT<T> m_declaration; \ |
| \ |
| public: \ |
| const TPersistDeclaration *getDeclaration() const override { \ |
| return &m_declaration; \ |
| } |
| |
| #define PERSIST_IDENTIFIER(T, I) TPersistDeclarationT<T> T::m_declaration(I); |
| |
| |
| |
| #endif |