/[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 3163 by schoenebeck, Tue May 9 14:52:02 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    #if __cplusplus < 201103L
39    # include <tr1/type_traits>
40    #endif
41    
42  /** @brief Serialization / deserialization framework.  /** @brief Serialization / deserialization framework.
43   *   *
# Line 102  namespace Serialization { Line 106  namespace Serialization {
106          OPERATION_DESERIALIZE          OPERATION_DESERIALIZE
107      };      };
108    
109        enum time_base_t {
110            LOCAL_TIME,
111            UTC_TIME
112        };
113    
114      template<typename T>      template<typename T>
115      bool IsEnum(const T& data) {      bool IsEnum(const T& data) {
116          return __is_enum(T);          return __is_enum(T);
# Line 178  namespace Serialization { Line 187  namespace Serialization {
187      typedef std::vector<UID> UIDChain;      typedef std::vector<UID> UIDChain;
188    
189      // prototyping of private internal friend functions      // prototyping of private internal friend functions
190        static String _encodePrimitiveValue(const Object& obj);
191      static DataType _popDataTypeBlob(const char*& p, const char* end);      static DataType _popDataTypeBlob(const char*& p, const char* end);
192      static Member _popMemberBlob(const char*& p, const char* end);      static Member _popMemberBlob(const char*& p, const char* end);
193      static Object _popObjectBlob(const char*& p, const char* end);      static Object _popObjectBlob(const char*& p, const char* end);
194      static void _popPrimitiveValue(const char*& p, const char* end, Object& obj);      static void _popPrimitiveValue(const char*& p, const char* end, Object& obj);
195        static String _primitiveObjectValueToString(const Object& obj);
196    
197      /** @brief Abstract reflection of a native C++ data type.      /** @brief Abstract reflection of a native C++ data type.
198       *       *
# Line 286  namespace Serialization { Line 297  namespace Serialization {
297          bool m_isPointer;          bool m_isPointer;
298    
299          friend DataType _popDataTypeBlob(const char*& p, const char* end);          friend DataType _popDataTypeBlob(const char*& p, const char* end);
300            friend class Archive;
301      };      };
302    
303      /** @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 371  namespace Serialization {
371          std::vector<Member>& members() { return m_members; }          std::vector<Member>& members() { return m_members; }
372          const std::vector<Member>& members() const { return m_members; }          const std::vector<Member>& members() const { return m_members; }
373          Member memberNamed(String name) const;          Member memberNamed(String name) const;
374          void remove(const Member& member);          Member memberByUID(const UID& uid) const;
375          std::vector<Member> membersOfType(const DataType& type) const;          std::vector<Member> membersOfType(const DataType& type) const;
376          int sequenceIndexOf(const Member& member) const;          int sequenceIndexOf(const Member& member) const;
377          bool isValid() const;          bool isValid() const;
# Line 370  namespace Serialization { Line 382  namespace Serialization {
382          bool operator<(const Object& other) const;          bool operator<(const Object& other) const;
383          bool operator>(const Object& other) const;          bool operator>(const Object& other) const;
384    
385        protected:
386            void remove(const Member& member);
387    
388      private:      private:
389          DataType m_type;          DataType m_type;
390          UIDChain m_uid;          UIDChain m_uid;
# Line 378  namespace Serialization { Line 393  namespace Serialization {
393          RawData m_data;          RawData m_data;
394          std::vector<Member> m_members;          std::vector<Member> m_members;
395    
396            friend String _encodePrimitiveValue(const Object& obj);
397          friend Object _popObjectBlob(const char*& p, const char* end);          friend Object _popObjectBlob(const char*& p, const char* end);
398          friend void _popPrimitiveValue(const char*& p, const char* end, Object& obj);          friend void _popPrimitiveValue(const char*& p, const char* end, Object& obj);
399            friend String _primitiveObjectValueToString(const Object& obj);
400            friend class Archive;
401      };      };
402    
403      /** @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 551  namespace Serialization {
551              deserialize(&obj);              deserialize(&obj);
552          }          }
553    
554          const RawData& rawData() const { return m_rawData; }          const RawData& rawData();
555          virtual String rawDataFormat() const;          virtual String rawDataFormat() const;
556    
557          template<typename T_classType, typename T_memberType>          template<typename T_classType, typename T_memberType>
# Line 567  namespace Serialization { Line 585  namespace Serialization {
585          virtual void decode(const RawData& data);          virtual void decode(const RawData& data);
586          virtual void decode(const uint8_t* data, size_t size);          virtual void decode(const uint8_t* data, size_t size);
587          void clear();          void clear();
588            bool isModified() const;
589            void removeMember(Object& parent, const Member& member);
590          void remove(const Object& obj);          void remove(const Object& obj);
591          Object& rootObject();          Object& rootObject();
592          Object& objectByUID(const UID& uid);          Object& objectByUID(const UID& uid);
593            void setAutoValue(Object& object, String value);
594            void setIntValue(Object& object, int64_t value);
595            void setRealValue(Object& object, double value);
596            void setBoolValue(Object& object, bool value);
597            void setEnumValue(Object& object, uint64_t value);
598            String valueAsString(const Object& object);
599            String name() const;
600            void setName(String name);
601            String comment() const;
602            void setComment(String comment);
603            time_t timeStampCreated() const;
604            time_t timeStampModified() const;
605            tm dateTimeCreated(time_base_t base = LOCAL_TIME) const;
606            tm dateTimeModified(time_base_t base = LOCAL_TIME) const;
607    
608      protected:      protected:
609          // UID resolver for non-pointer types          // UID resolver for non-pointer types
# Line 676  namespace Serialization { Line 710  namespace Serialization {
710          operation_t m_operation;          operation_t m_operation;
711          UID m_root;          UID m_root;
712          RawData m_rawData;          RawData m_rawData;
713            bool m_isModified;
714            String m_name;
715            String m_comment;
716            time_t m_timeCreated;
717            time_t m_timeModified;
718      };      };
719    
720      /**      /**

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

  ViewVC Help
Powered by ViewVC