/[svn]/libgig/trunk/src/Serialization.h
ViewVC logotype

Diff of /libgig/trunk/src/Serialization.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3146 by schoenebeck, Wed May 3 19:54:08 2017 UTC revision 3156 by schoenebeck, Mon May 8 17:18:07 2017 UTC
# Line 34  Line 34 
34  #include <string>  #include <string>
35  #include <vector>  #include <vector>
36  #include <map>  #include <map>
37    #include <time.h>
38    
39  /** @brief Serialization / deserialization framework.  /** @brief Serialization / deserialization framework.
40   *   *
# Line 102  namespace Serialization { Line 103  namespace Serialization {
103          OPERATION_DESERIALIZE          OPERATION_DESERIALIZE
104      };      };
105    
106        enum time_base_t {
107            LOCAL_TIME,
108            UTC_TIME
109        };
110    
111      template<typename T>      template<typename T>
112      bool IsEnum(const T& data) {      bool IsEnum(const T& data) {
113          return __is_enum(T);          return __is_enum(T);
# Line 178  namespace Serialization { Line 184  namespace Serialization {
184      typedef std::vector<UID> UIDChain;      typedef std::vector<UID> UIDChain;
185    
186      // prototyping of private internal friend functions      // prototyping of private internal friend functions
187        static String _encodePrimitiveValue(const Object& obj);
188      static DataType _popDataTypeBlob(const char*& p, const char* end);      static DataType _popDataTypeBlob(const char*& p, const char* end);
189      static Member _popMemberBlob(const char*& p, const char* end);      static Member _popMemberBlob(const char*& p, const char* end);
190      static Object _popObjectBlob(const char*& p, const char* end);      static Object _popObjectBlob(const char*& p, const char* end);
191      static void _popPrimitiveValue(const char*& p, const char* end, Object& obj);      static void _popPrimitiveValue(const char*& p, const char* end, Object& obj);
192        static String _primitiveObjectValueToString(const Object& obj);
193    
194      /** @brief Abstract reflection of a native C++ data type.      /** @brief Abstract reflection of a native C++ data type.
195       *       *
# Line 286  namespace Serialization { Line 294  namespace Serialization {
294          bool m_isPointer;          bool m_isPointer;
295    
296          friend DataType _popDataTypeBlob(const char*& p, const char* end);          friend DataType _popDataTypeBlob(const char*& p, const char* end);
297            friend class Archive;
298      };      };
299    
300      /** @brief Abstract reflection of a native C++ class/struct's member variable.      /** @brief Abstract reflection of a native C++ class/struct's member variable.
# Line 359  namespace Serialization { Line 368  namespace Serialization {
368          std::vector<Member>& members() { return m_members; }          std::vector<Member>& members() { return m_members; }
369          const std::vector<Member>& members() const { return m_members; }          const std::vector<Member>& members() const { return m_members; }
370          Member memberNamed(String name) const;          Member memberNamed(String name) const;
371          void remove(const Member& member);          Member memberByUID(const UID& uid) const;
372          std::vector<Member> membersOfType(const DataType& type) const;          std::vector<Member> membersOfType(const DataType& type) const;
373          int sequenceIndexOf(const Member& member) const;          int sequenceIndexOf(const Member& member) const;
374          bool isValid() const;          bool isValid() const;
# Line 370  namespace Serialization { Line 379  namespace Serialization {
379          bool operator<(const Object& other) const;          bool operator<(const Object& other) const;
380          bool operator>(const Object& other) const;          bool operator>(const Object& other) const;
381    
382        protected:
383            void remove(const Member& member);
384    
385      private:      private:
386          DataType m_type;          DataType m_type;
387          UIDChain m_uid;          UIDChain m_uid;
# Line 378  namespace Serialization { Line 390  namespace Serialization {
390          RawData m_data;          RawData m_data;
391          std::vector<Member> m_members;          std::vector<Member> m_members;
392    
393            friend String _encodePrimitiveValue(const Object& obj);
394          friend Object _popObjectBlob(const char*& p, const char* end);          friend Object _popObjectBlob(const char*& p, const char* end);
395          friend void _popPrimitiveValue(const char*& p, const char* end, Object& obj);          friend void _popPrimitiveValue(const char*& p, const char* end, Object& obj);
396            friend String _primitiveObjectValueToString(const Object& obj);
397            friend class Archive;
398      };      };
399    
400      /** @brief Destination container for serialization, and source container for deserialization.      /** @brief Destination container for serialization, and source container for deserialization.
# Line 533  namespace Serialization { Line 548  namespace Serialization {
548              deserialize(&obj);              deserialize(&obj);
549          }          }
550    
551          const RawData& rawData() const { return m_rawData; }          const RawData& rawData();
552          virtual String rawDataFormat() const;          virtual String rawDataFormat() const;
553    
554          template<typename T_classType, typename T_memberType>          template<typename T_classType, typename T_memberType>
# Line 567  namespace Serialization { Line 582  namespace Serialization {
582          virtual void decode(const RawData& data);          virtual void decode(const RawData& data);
583          virtual void decode(const uint8_t* data, size_t size);          virtual void decode(const uint8_t* data, size_t size);
584          void clear();          void clear();
585            bool isModified() const;
586            void removeMember(Object& parent, const Member& member);
587          void remove(const Object& obj);          void remove(const Object& obj);
588          Object& rootObject();          Object& rootObject();
589          Object& objectByUID(const UID& uid);          Object& objectByUID(const UID& uid);
590            void setAutoValue(Object& object, String value);
591            void setIntValue(Object& object, int64_t value);
592            void setRealValue(Object& object, double value);
593            void setBoolValue(Object& object, bool value);
594            void setEnumValue(Object& object, uint64_t value);
595            String valueAsString(const Object& object);
596            String name() const;
597            void setName(String name);
598            String comment() const;
599            void setComment(String comment);
600            time_t timeStampCreated() const;
601            time_t timeStampModified() const;
602            tm dateTimeCreated(time_base_t base = LOCAL_TIME) const;
603            tm dateTimeModified(time_base_t base = LOCAL_TIME) const;
604    
605      protected:      protected:
606          // UID resolver for non-pointer types          // UID resolver for non-pointer types
# Line 676  namespace Serialization { Line 707  namespace Serialization {
707          operation_t m_operation;          operation_t m_operation;
708          UID m_root;          UID m_root;
709          RawData m_rawData;          RawData m_rawData;
710            bool m_isModified;
711            String m_name;
712            String m_comment;
713            time_t m_timeCreated;
714            time_t m_timeModified;
715      };      };
716    
717      /**      /**

Legend:
Removed from v.3146  
changed lines
  Added in v.3156

  ViewVC Help
Powered by ViewVC