/[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 3138 by schoenebeck, Wed May 3 14:41:58 2017 UTC revision 3153 by schoenebeck, Sat May 6 13:43:43 2017 UTC
# Line 80  Line 80 
80   */   */
81  namespace Serialization {  namespace Serialization {
82    
83        // just symbol prototyping
84        class DataType;
85        class Object;
86        class Member;
87      class Archive;      class Archive;
88        class ObjectPool;
89      class Exception;      class Exception;
90    
91      typedef std::string String;      typedef std::string String;
# Line 172  namespace Serialization { Line 177  namespace Serialization {
177    
178      typedef std::vector<UID> UIDChain;      typedef std::vector<UID> UIDChain;
179    
180        // prototyping of private internal friend functions
181        static String _encodePrimitiveValue(const Object& obj);
182        static DataType _popDataTypeBlob(const char*& p, const char* end);
183        static Member _popMemberBlob(const char*& p, const char* end);
184        static Object _popObjectBlob(const char*& p, const char* end);
185        static void _popPrimitiveValue(const char*& p, const char* end, Object& obj);
186        static String _primitiveObjectValueToString(const Object& obj);
187    
188      /** @brief Abstract reflection of a native C++ data type.      /** @brief Abstract reflection of a native C++ data type.
189       *       *
190       * Provides detailed information about a C++ data type, whether it is a       * Provides detailed information about a C++ data type, whether it is a
# Line 275  namespace Serialization { Line 288  namespace Serialization {
288          bool m_isPointer;          bool m_isPointer;
289    
290          friend DataType _popDataTypeBlob(const char*& p, const char* end);          friend DataType _popDataTypeBlob(const char*& p, const char* end);
291            friend class Archive;
292      };      };
293    
294      /** @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 348  namespace Serialization { Line 362  namespace Serialization {
362          std::vector<Member>& members() { return m_members; }          std::vector<Member>& members() { return m_members; }
363          const std::vector<Member>& members() const { return m_members; }          const std::vector<Member>& members() const { return m_members; }
364          Member memberNamed(String name) const;          Member memberNamed(String name) const;
365          void remove(const Member& member);          Member memberByUID(const UID& uid) const;
366          std::vector<Member> membersOfType(const DataType& type) const;          std::vector<Member> membersOfType(const DataType& type) const;
367          int sequenceIndexOf(const Member& member) const;          int sequenceIndexOf(const Member& member) const;
368          bool isValid() const;          bool isValid() const;
# Line 359  namespace Serialization { Line 373  namespace Serialization {
373          bool operator<(const Object& other) const;          bool operator<(const Object& other) const;
374          bool operator>(const Object& other) const;          bool operator>(const Object& other) const;
375    
376        protected:
377            void remove(const Member& member);
378    
379      private:      private:
380          DataType m_type;          DataType m_type;
381          UIDChain m_uid;          UIDChain m_uid;
# Line 367  namespace Serialization { Line 384  namespace Serialization {
384          RawData m_data;          RawData m_data;
385          std::vector<Member> m_members;          std::vector<Member> m_members;
386    
387            friend String _encodePrimitiveValue(const Object& obj);
388          friend Object _popObjectBlob(const char*& p, const char* end);          friend Object _popObjectBlob(const char*& p, const char* end);
389          friend void _popPrimitiveValue(const char*& p, const char* end, Object& obj);          friend void _popPrimitiveValue(const char*& p, const char* end, Object& obj);
390            friend String _primitiveObjectValueToString(const Object& obj);
391            friend class Archive;
392      };      };
393    
394      /** @brief Destination container for serialization, and source container for deserialization.      /** @brief Destination container for serialization, and source container for deserialization.
# Line 382  namespace Serialization { Line 402  namespace Serialization {
402       * @code       * @code
403       * Archive a;       * Archive a;
404       * a.serialize(&myRootObject);       * a.serialize(&myRootObject);
405       * @encode       * @endcode
406       * Or if you prefer the look of operator based code:       * Or if you prefer the look of operator based code:
407       * @code       * @code
408       * Archive a;       * Archive a;
409       * a << myRootObject;       * a << myRootObject;
410       * @encode       * @endcode
411       * The Archive object will then serialize all members of the passed C++       * The Archive object will then serialize all members of the passed C++
412       * object, and will recursively serialize all other C++ objects which it       * object, and will recursively serialize all other C++ objects which it
413       * contains or points to. So the root object is the starting point for the       * contains or points to. So the root object is the starting point for the
# Line 402  namespace Serialization { Line 422  namespace Serialization {
422       * @code       * @code
423       * Archive a(rawDataStream);       * Archive a(rawDataStream);
424       * a.deserialize(&myRootObject);       * a.deserialize(&myRootObject);
425       * @encode       * @endcode
426       * Or with operator instead:       * Or with operator instead:
427       * @code       * @code
428       * Archive a(rawDataStream);       * Archive a(rawDataStream);
429       * a >> myRootObject;       * a >> myRootObject;
430       * @encode       * @endcode
431       * Now this framework automatically handles serialization and       * Now this framework automatically handles serialization and
432       * deserialization of fundamental data types automatically for you (like       * deserialization of fundamental data types automatically for you (like
433       * i.e. char, int, long int, float, double, etc.). However for your own       * i.e. char, int, long int, float, double, etc.). However for your own
# Line 522  namespace Serialization { Line 542  namespace Serialization {
542              deserialize(&obj);              deserialize(&obj);
543          }          }
544    
545          const RawData& rawData() const { return m_rawData; }          const RawData& rawData();
546          virtual String rawDataFormat() const;          virtual String rawDataFormat() const;
547    
548          template<typename T_classType, typename T_memberType>          template<typename T_classType, typename T_memberType>
# Line 556  namespace Serialization { Line 576  namespace Serialization {
576          virtual void decode(const RawData& data);          virtual void decode(const RawData& data);
577          virtual void decode(const uint8_t* data, size_t size);          virtual void decode(const uint8_t* data, size_t size);
578          void clear();          void clear();
579            bool isModified() const;
580            void removeMember(Object& parent, const Member& member);
581          void remove(const Object& obj);          void remove(const Object& obj);
582          Object& rootObject();          Object& rootObject();
583          Object& objectByUID(const UID& uid);          Object& objectByUID(const UID& uid);
584            void setAutoValue(Object& object, String value);
585            void setIntValue(Object& object, int64_t value);
586            void setRealValue(Object& object, double value);
587            void setBoolValue(Object& object, bool value);
588            void setEnumValue(Object& object, uint64_t value);
589            String valueAsString(const Object& object);
590    
591      protected:      protected:
592          // UID resolver for non-pointer types          // UID resolver for non-pointer types
# Line 665  namespace Serialization { Line 693  namespace Serialization {
693          operation_t m_operation;          operation_t m_operation;
694          UID m_root;          UID m_root;
695          RawData m_rawData;          RawData m_rawData;
696            bool m_isModified;
697      };      };
698    
699      /**      /**

Legend:
Removed from v.3138  
changed lines
  Added in v.3153

  ViewVC Help
Powered by ViewVC