/[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 3167 by schoenebeck, Tue May 9 16:32:07 2017 UTC revision 3178 by schoenebeck, Thu May 11 23:06:40 2017 UTC
# Line 35  Line 35 
35  #include <vector>  #include <vector>
36  #include <map>  #include <map>
37  #include <time.h>  #include <time.h>
38  #if __cplusplus < 201103L  
39    #ifndef __has_extension
40    # define __has_extension(x) 0
41    #endif
42    
43    #ifndef HAS_BUILTIN_TYPE_TRAITS
44    # if __cplusplus >= 201103L
45    #  define HAS_BUILTIN_TYPE_TRAITS 1
46    # elif ( __has_extension(is_class) && __has_extension(is_enum) )
47    #  define HAS_BUILTIN_TYPE_TRAITS 1
48    # elif ( __GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 3 ) )
49    #  define HAS_BUILTIN_TYPE_TRAITS 1
50    # elif _MSC_VER >= 1400 /* MS Visual C++ 8.0 (Visual Studio 2005) */
51    #  define HAS_BUILTIN_TYPE_TRAITS 1
52    # elif __INTEL_COMPILER >= 1100
53    #  define HAS_BUILTIN_TYPE_TRAITS 1
54    # else
55    #  define HAS_BUILTIN_TYPE_TRAITS 0
56    # endif
57    #endif
58    
59    #if !HAS_BUILTIN_TYPE_TRAITS
60  # include <tr1/type_traits>  # include <tr1/type_traits>
61  # define LIBGIG_IS_CLASS(type) std::tr1::__is_union_or_class<type>::value //NOTE: without compiler support we cannot distinguish union from class  # define LIBGIG_IS_CLASS(type) std::tr1::__is_union_or_class<type>::value //NOTE: without compiler support we cannot distinguish union from class
62  #else  #else
# Line 116  namespace Serialization { Line 137  namespace Serialization {
137    
138      template<typename T>      template<typename T>
139      bool IsEnum(const T& data) {      bool IsEnum(const T& data) {
140          #if __cplusplus < 201103L          #if !HAS_BUILTIN_TYPE_TRAITS
141          return std::tr1::is_enum<T>::value;          return std::tr1::is_enum<T>::value;
142          #else          #else
143          return __is_enum(T);          return __is_enum(T);
# Line 125  namespace Serialization { Line 146  namespace Serialization {
146    
147      template<typename T>      template<typename T>
148      bool IsUnion(const T& data) {      bool IsUnion(const T& data) {
149          #if __cplusplus < 201103L          #if !HAS_BUILTIN_TYPE_TRAITS
150          return false; // without compiler support we cannot distinguish union from class          return false; // without compiler support we cannot distinguish union from class
151          #else          #else
152          return __is_union(T);          return __is_union(T);
# Line 134  namespace Serialization { Line 155  namespace Serialization {
155    
156      template<typename T>      template<typename T>
157      bool IsClass(const T& data) {      bool IsClass(const T& data) {
158          #if __cplusplus < 201103L          #if !HAS_BUILTIN_TYPE_TRAITS
159          return std::tr1::__is_union_or_class<T>::value; // without compiler support we cannot distinguish union from class          return std::tr1::__is_union_or_class<T>::value; // without compiler support we cannot distinguish union from class
160          #else          #else
161          return __is_class(T);          return __is_class(T);
# Line 180  namespace Serialization { Line 201  namespace Serialization {
201          template<typename T>          template<typename T>
202          struct Resolver {          struct Resolver {
203              static UID resolve(const T& obj) {              static UID resolve(const T& obj) {
204                  return UID { (ID) &obj, sizeof(obj) };                  const UID uid = { (ID) &obj, sizeof(obj) };
205                    return uid;
206              }              }
207          };          };
208    
# Line 188  namespace Serialization { Line 210  namespace Serialization {
210          template<typename T>          template<typename T>
211          struct Resolver<T*> {          struct Resolver<T*> {
212              static UID resolve(const T* const & obj) {              static UID resolve(const T* const & obj) {
213                  return UID { (ID) obj, sizeof(*obj) };                  const UID uid = { (ID) obj, sizeof(*obj) };
214                    return uid;
215              }              }
216          };          };
217      };      };
# Line 208  namespace Serialization { Line 231  namespace Serialization {
231      static Object _popObjectBlob(const char*& p, const char* end);      static Object _popObjectBlob(const char*& p, const char* end);
232      static void _popPrimitiveValue(const char*& p, const char* end, Object& obj);      static void _popPrimitiveValue(const char*& p, const char* end, Object& obj);
233      static String _primitiveObjectValueToString(const Object& obj);      static String _primitiveObjectValueToString(const Object& obj);
234        //  |
235        template<typename T>
236        static T _primitiveObjectValueToNumber(const Object& obj);
237    
238      /** @brief Abstract reflection of a native C++ data type.      /** @brief Abstract reflection of a native C++ data type.
239       *       *
# Line 237  namespace Serialization { Line 263  namespace Serialization {
263          bool operator>(const DataType& other) const;          bool operator>(const DataType& other) const;
264          String asLongDescr() const;          String asLongDescr() const;
265          String baseTypeName() const { return m_baseTypeName; }          String baseTypeName() const { return m_baseTypeName; }
266          String customTypeName() const { return m_customTypeName; }          String customTypeName(bool demangle = false) const;
267    
268          template<typename T>          template<typename T>
269          static DataType dataTypeOf(const T& data) {          static DataType dataTypeOf(const T& data) {
# Line 412  namespace Serialization { Line 438  namespace Serialization {
438          friend Object _popObjectBlob(const char*& p, const char* end);          friend Object _popObjectBlob(const char*& p, const char* end);
439          friend void _popPrimitiveValue(const char*& p, const char* end, Object& obj);          friend void _popPrimitiveValue(const char*& p, const char* end, Object& obj);
440          friend String _primitiveObjectValueToString(const Object& obj);          friend String _primitiveObjectValueToString(const Object& obj);
441    
442            template<typename T>
443            friend T _primitiveObjectValueToNumber(const Object& obj);
444    
445          friend class Archive;          friend class Archive;
446      };      };
447    
# Line 611  namespace Serialization { Line 641  namespace Serialization {
641          void setBoolValue(Object& object, bool value);          void setBoolValue(Object& object, bool value);
642          void setEnumValue(Object& object, uint64_t value);          void setEnumValue(Object& object, uint64_t value);
643          String valueAsString(const Object& object);          String valueAsString(const Object& object);
644            int64_t valueAsInt(const Object& object);
645            double valueAsReal(const Object& object);
646            bool valueAsBool(const Object& object);
647          String name() const;          String name() const;
648          void setName(String name);          void setName(String name);
649          String comment() const;          String comment() const;
# Line 640  namespace Serialization { Line 673  namespace Serialization {
673          class UIDChainResolver<T*> {          class UIDChainResolver<T*> {
674          public:          public:
675              UIDChainResolver(const T*& data) {              UIDChainResolver(const T*& data) {
676                  m_uid.push_back(UID { &data, sizeof(data) });                  const UID uids[2] = {
677                  m_uid.push_back(UID { data, sizeof(*data) });                      { &data, sizeof(data) },
678                        { data, sizeof(*data) }
679                    };
680                    m_uid.push_back(uids[0]);
681                    m_uid.push_back(uids[1]);
682              }              }
683    
684              operator UIDChain() const { return m_uid; }              operator UIDChain() const { return m_uid; }

Legend:
Removed from v.3167  
changed lines
  Added in v.3178

  ViewVC Help
Powered by ViewVC