libgig  4.2.0
Serialization.h
1 /***************************************************************************
2  * *
3  * Copyright (C) 2017-2019 Christian Schoenebeck *
4  * <cuse@users.sourceforge.net> *
5  * *
6  * This library is part of libgig. *
7  * *
8  * This library is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This library is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this library; if not, write to the Free Software *
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21  * MA 02111-1307 USA *
22  ***************************************************************************/
23 
24 #ifndef LIBGIG_SERIALIZATION_H
25 #define LIBGIG_SERIALIZATION_H
26 
27 #ifdef HAVE_CONFIG_H
28 # include <config.h>
29 #endif
30 
31 #include <stdint.h>
32 #include <stdio.h>
33 #include <typeinfo>
34 #include <string>
35 #include <vector>
36 #include <map>
37 #include <time.h>
38 #include <stdarg.h>
39 
40 #ifndef __has_extension
41 # define __has_extension(x) 0
42 #endif
43 
44 #ifndef HAS_BUILTIN_TYPE_TRAITS
45 # if __cplusplus >= 201103L
46 # define HAS_BUILTIN_TYPE_TRAITS 1
47 # elif ( __has_extension(is_class) && __has_extension(is_enum) )
48 # define HAS_BUILTIN_TYPE_TRAITS 1
49 # elif ( __GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 3 ) )
50 # define HAS_BUILTIN_TYPE_TRAITS 1
51 # elif _MSC_VER >= 1400 /* MS Visual C++ 8.0 (Visual Studio 2005) */
52 # define HAS_BUILTIN_TYPE_TRAITS 1
53 # elif __INTEL_COMPILER >= 1100
54 # define HAS_BUILTIN_TYPE_TRAITS 1
55 # else
56 # define HAS_BUILTIN_TYPE_TRAITS 0
57 # endif
58 #endif
59 
60 #if !HAS_BUILTIN_TYPE_TRAITS
61 # include <tr1/type_traits>
62 # define LIBGIG_IS_CLASS(type) std::tr1::__is_union_or_class<type>::value //NOTE: without compiler support we cannot distinguish union from class
63 #else
64 # define LIBGIG_IS_CLASS(type) __is_class(type)
65 #endif
66 
110 namespace Serialization {
111 
112  // just symbol prototyping
113  class DataType;
114  class Object;
115  class Member;
116  class Archive;
117  class ObjectPool;
118  class Exception;
119 
120  typedef std::string String;
121 
130  typedef std::vector<uint8_t> RawData;
131 
142  typedef void* ID;
143 
151  typedef uint32_t Version;
152 
158  enum time_base_t {
160  UTC_TIME
161  };
162 
170  template<typename T>
171  bool IsEnum(const T& data) {
172  #if !HAS_BUILTIN_TYPE_TRAITS
173  return std::tr1::is_enum<T>::value;
174  #else
175  return __is_enum(T);
176  #endif
177  }
178 
189  template<typename T>
190  bool IsUnion(const T& data) {
191  #if !HAS_BUILTIN_TYPE_TRAITS
192  return false; // without compiler support we cannot distinguish union from class
193  #else
194  return __is_union(T);
195  #endif
196  }
197 
207  template<typename T>
208  bool IsClass(const T& data) {
209  #if !HAS_BUILTIN_TYPE_TRAITS
210  return std::tr1::__is_union_or_class<T>::value; // without compiler support we cannot distinguish union from class
211  #else
212  return __is_class(T);
213  #endif
214  }
215 
216  /*template<typename T>
217  bool IsTrivial(T data) {
218  return __is_trivial(T);
219  }*/
220 
221  /*template<typename T>
222  bool IsPOD(T data) {
223  return __is_pod(T);
224  }*/
225 
241  class UID {
242  public:
243  ID id;
244  size_t size;
245 
246  bool isValid() const;
247  operator bool() const { return isValid(); }
248  //bool operator()() const { return isValid(); }
249  bool operator==(const UID& other) const { return id == other.id && size == other.size; }
250  bool operator!=(const UID& other) const { return id != other.id || size != other.size; }
251  bool operator<(const UID& other) const { return id < other.id || (id == other.id && size < other.size); }
252  bool operator>(const UID& other) const { return id > other.id || (id == other.id && size > other.size); }
253 
261  template<typename T>
262  static UID from(const T& obj) {
263  return Resolver<T>::resolve(obj);
264  }
265 
266  protected:
267  // UID resolver for non-pointer types
268  template<typename T>
269  struct Resolver {
270  static UID resolve(const T& obj) {
271  const UID uid = { (ID) &obj, sizeof(obj) };
272  return uid;
273  }
274  };
275 
276  // UID resolver for pointer types (of 1st degree)
277  template<typename T>
278  struct Resolver<T*> {
279  static UID resolve(const T* const & obj) {
280  const UID uid = { (ID) obj, sizeof(*obj) };
281  return uid;
282  }
283  };
284  };
285 
291  extern const UID NO_UID;
292 
324  typedef std::vector<UID> UIDChain;
325 
326 #if LIBGIG_SERIALIZATION_INTERNAL
327  // prototyping of private internal friend functions
328  static String _encodePrimitiveValue(const Object& obj);
329  static DataType _popDataTypeBlob(const char*& p, const char* end);
330  static Member _popMemberBlob(const char*& p, const char* end);
331  static Object _popObjectBlob(const char*& p, const char* end);
332  static void _popPrimitiveValue(const char*& p, const char* end, Object& obj);
333  static String _primitiveObjectValueToString(const Object& obj);
334  // |
335  template<typename T>
336  static T _primitiveObjectValueToNumber(const Object& obj);
337 #endif // LIBGIG_SERIALIZATION_INTERNAL
338 
355  class DataType {
356  public:
357  DataType();
358  size_t size() const { return m_size; }
359  bool isValid() const;
360  bool isPointer() const;
361  bool isClass() const;
362  bool isPrimitive() const;
363  bool isInteger() const;
364  bool isReal() const;
365  bool isBool() const;
366  bool isEnum() const;
367  bool isSigned() const;
368  operator bool() const { return isValid(); }
369  //bool operator()() const { return isValid(); }
370  bool operator==(const DataType& other) const;
371  bool operator!=(const DataType& other) const;
372  bool operator<(const DataType& other) const;
373  bool operator>(const DataType& other) const;
374  String asLongDescr() const;
375  String baseTypeName() const;
376  String customTypeName(bool demangle = false) const;
377 
388  template<typename T>
389  static DataType dataTypeOf(const T& data) {
390  return Resolver<T>::resolve(data);
391  }
392 
393  protected:
394  DataType(bool isPointer, int size, String baseType, String customType = "");
395 
396  template<typename T, bool T_isPointer>
397  struct ResolverBase {
398  static DataType resolve(const T& data) {
399  const std::type_info& type = typeid(data);
400  const int sz = sizeof(data);
401 
402  // for primitive types we are using our own type names instead of
403  // using std:::type_info::name(), because the precise output of the
404  // latter may vary between compilers
405  if (type == typeid(int8_t)) return DataType(T_isPointer, sz, "int8");
406  if (type == typeid(uint8_t)) return DataType(T_isPointer, sz, "uint8");
407  if (type == typeid(int16_t)) return DataType(T_isPointer, sz, "int16");
408  if (type == typeid(uint16_t)) return DataType(T_isPointer, sz, "uint16");
409  if (type == typeid(int32_t)) return DataType(T_isPointer, sz, "int32");
410  if (type == typeid(uint32_t)) return DataType(T_isPointer, sz, "uint32");
411  if (type == typeid(int64_t)) return DataType(T_isPointer, sz, "int64");
412  if (type == typeid(uint64_t)) return DataType(T_isPointer, sz, "uint64");
413  if (type == typeid(bool)) return DataType(T_isPointer, sz, "bool");
414  if (type == typeid(float)) return DataType(T_isPointer, sz, "real32");
415  if (type == typeid(double)) return DataType(T_isPointer, sz, "real64");
416 
417  if (IsEnum(data)) return DataType(T_isPointer, sz, "enum", rawCppTypeNameOf(data));
418  if (IsUnion(data)) return DataType(T_isPointer, sz, "union", rawCppTypeNameOf(data));
419  if (IsClass(data)) return DataType(T_isPointer, sz, "class", rawCppTypeNameOf(data));
420 
421  return DataType();
422  }
423  };
424 
425  // DataType resolver for non-pointer types
426  template<typename T>
427  struct Resolver : ResolverBase<T,false> {
428  static DataType resolve(const T& data) {
429  return ResolverBase<T,false>::resolve(data);
430  }
431  };
432 
433  // DataType resolver for pointer types (of 1st degree)
434  template<typename T>
435  struct Resolver<T*> : ResolverBase<T,true> {
436  static DataType resolve(const T*& data) {
437  return ResolverBase<T,true>::resolve(*data);
438  }
439  };
440 
441  template<typename T>
442  static String rawCppTypeNameOf(const T& data) {
443  #if defined _MSC_VER // Microsoft compiler ...
444  String name = typeid(data).raw_name();
445  #else // i.e. especially GCC and clang ...
446  String name = typeid(data).name();
447  #endif
448  //while (!name.empty() && name[0] >= 0 && name[0] <= 9)
449  // name = name.substr(1);
450  return name;
451  }
452 
453  private:
454  String m_baseTypeName;
455  String m_customTypeName;
456  int m_size;
457  bool m_isPointer;
458 
459 #if LIBGIG_SERIALIZATION_INTERNAL
460  friend DataType _popDataTypeBlob(const char*& p, const char* end);
461 #endif
462  friend class Archive;
463  };
464 
486  class Member {
487  public:
488  Member();
489  UID uid() const;
490  String name() const;
491  size_t offset() const;
492  const DataType& type() const;
493  bool isValid() const;
494  operator bool() const { return isValid(); }
495  //bool operator()() const { return isValid(); }
496  bool operator==(const Member& other) const;
497  bool operator!=(const Member& other) const;
498  bool operator<(const Member& other) const;
499  bool operator>(const Member& other) const;
500 
501  protected:
502  Member(String name, UID uid, size_t offset, DataType type);
503  friend class Archive;
504 
505  private:
506  UID m_uid;
507  size_t m_offset;
508  String m_name;
509  DataType m_type;
510 
511 #if LIBGIG_SERIALIZATION_INTERNAL
512  friend Member _popMemberBlob(const char*& p, const char* end);
513 #endif
514  };
515 
540  class Object {
541  public:
542  Object();
544 
545  UID uid(int index = 0) const;
546  const UIDChain& uidChain() const;
547  const DataType& type() const;
548  const RawData& rawData() const;
549  Version version() const;
550  Version minVersion() const;
551  bool isVersionCompatibleTo(const Object& other) const;
552  std::vector<Member>& members();
553  const std::vector<Member>& members() const;
554  Member memberNamed(String name) const;
555  Member memberByUID(const UID& uid) const;
556  std::vector<Member> membersOfType(const DataType& type) const;
557  int sequenceIndexOf(const Member& member) const;
558  bool isValid() const;
559  operator bool() const { return isValid(); }
560  //bool operator()() const { return isValid(); }
561  bool operator==(const Object& other) const;
562  bool operator!=(const Object& other) const;
563  bool operator<(const Object& other) const;
564  bool operator>(const Object& other) const;
565 
566  protected:
567  void remove(const Member& member);
568  void setVersion(Version v);
569  void setMinVersion(Version v);
570 
571  private:
572  DataType m_type;
573  UIDChain m_uid;
574  Version m_version;
575  Version m_minVersion;
576  RawData m_data;
577  std::vector<Member> m_members;
578 
579 #if LIBGIG_SERIALIZATION_INTERNAL
580  friend String _encodePrimitiveValue(const Object& obj);
581  friend Object _popObjectBlob(const char*& p, const char* end);
582  friend void _popPrimitiveValue(const char*& p, const char* end, Object& obj);
583  friend String _primitiveObjectValueToString(const Object& obj);
584  // |
585  template<typename T>
586  friend T _primitiveObjectValueToNumber(const Object& obj);
587 #endif // LIBGIG_SERIALIZATION_INTERNAL
588 
589  friend class Archive;
590  };
591 
709  class Archive {
710  public:
711  Archive();
712  Archive(const RawData& data);
713  Archive(const uint8_t* data, size_t size);
714  virtual ~Archive();
715 
741  template<typename T>
742  void serialize(const T* obj) {
743  m_operation = OPERATION_SERIALIZE;
744  m_allObjects.clear();
745  m_rawData.clear();
746  m_root = UID::from(obj);
747  const_cast<T*>(obj)->serialize(this);
748  encode();
749  m_operation = OPERATION_NONE;
750  }
751 
776  template<typename T>
777  void deserialize(T* obj) {
778  Archive a;
779  m_operation = OPERATION_DESERIALIZE;
780  obj->serialize(&a);
781  a.m_root = UID::from(obj);
782  Syncer s(a, *this);
783  m_operation = OPERATION_NONE;
784  }
785 
800  template<typename T>
801  void operator<<(const T& obj) {
802  serialize(&obj);
803  }
804 
823  template<typename T>
824  void operator>>(T& obj) {
825  deserialize(&obj);
826  }
827 
828  const RawData& rawData();
829  virtual String rawDataFormat() const;
830 
876  template<typename T_classType, typename T_memberType>
877  void serializeMember(const T_classType& nativeObject, const T_memberType& nativeMember, const char* memberName) {
878  const size_t offset =
879  ((const uint8_t*)(const void*)&nativeMember) -
880  ((const uint8_t*)(const void*)&nativeObject);
881  const UIDChain uids = UIDChainResolver<T_memberType>(nativeMember);
882  const DataType type = DataType::dataTypeOf(nativeMember);
883  const Member member(memberName, uids[0], offset, type);
884  const UID parentUID = UID::from(nativeObject);
885  Object& parent = m_allObjects[parentUID];
886  if (!parent) {
887  const UIDChain uids = UIDChainResolver<T_classType>(nativeObject);
888  const DataType type = DataType::dataTypeOf(nativeObject);
889  parent = Object(uids, type);
890  }
891  parent.members().push_back(member);
892  const Object obj(uids, type);
893  const bool bExistsAlready = m_allObjects.count(uids[0]);
894  const bool isValidObject = obj;
895  const bool bExistingObjectIsInvalid = !m_allObjects[uids[0]];
896  if (!bExistsAlready || (bExistingObjectIsInvalid && isValidObject)) {
897  m_allObjects[uids[0]] = obj;
898  // recurse serialization for all members of this member
899  // (only for struct/class types, noop for primitive types)
900  SerializationRecursion<T_memberType>::serializeObject(this, nativeMember);
901  }
902  }
903 
973  template<typename T_classType>
974  void setVersion(const T_classType& nativeObject, Version v) {
975  const UID uid = UID::from(nativeObject);
976  Object& obj = m_allObjects[uid];
977  if (!obj) {
978  const UIDChain uids = UIDChainResolver<T_classType>(nativeObject);
979  const DataType type = DataType::dataTypeOf(nativeObject);
980  obj = Object(uids, type);
981  }
982  setVersion(obj, v);
983  }
984 
1014  template<typename T_classType>
1015  void setMinVersion(const T_classType& nativeObject, Version v) {
1016  const UID uid = UID::from(nativeObject);
1017  Object& obj = m_allObjects[uid];
1018  if (!obj) {
1019  const UIDChain uids = UIDChainResolver<T_classType>(nativeObject);
1020  const DataType type = DataType::dataTypeOf(nativeObject);
1021  obj = Object(uids, type);
1022  }
1023  setMinVersion(obj, v);
1024  }
1025 
1026  virtual void decode(const RawData& data);
1027  virtual void decode(const uint8_t* data, size_t size);
1028  void clear();
1029  bool isModified() const;
1030  void removeMember(Object& parent, const Member& member);
1031  void remove(const Object& obj);
1032  Object& rootObject();
1033  Object& objectByUID(const UID& uid);
1034  void setAutoValue(Object& object, String value);
1035  void setIntValue(Object& object, int64_t value);
1036  void setRealValue(Object& object, double value);
1037  void setBoolValue(Object& object, bool value);
1038  void setEnumValue(Object& object, uint64_t value);
1039  String valueAsString(const Object& object);
1040  int64_t valueAsInt(const Object& object);
1041  double valueAsReal(const Object& object);
1042  bool valueAsBool(const Object& object);
1043  void setVersion(Object& object, Version v);
1044  void setMinVersion(Object& object, Version v);
1045  String name() const;
1046  void setName(String name);
1047  String comment() const;
1048  void setComment(String comment);
1049  time_t timeStampCreated() const;
1050  time_t timeStampModified() const;
1051  tm dateTimeCreated(time_base_t base = LOCAL_TIME) const;
1052  tm dateTimeModified(time_base_t base = LOCAL_TIME) const;
1053 
1054  protected:
1055  // UID resolver for non-pointer types
1056  template<typename T>
1057  class UIDChainResolver {
1058  public:
1059  UIDChainResolver(const T& data) {
1060  m_uid.push_back(UID::from(data));
1061  }
1062 
1063  operator UIDChain() const { return m_uid; }
1064  UIDChain operator()() const { return m_uid; }
1065  private:
1066  UIDChain m_uid;
1067  };
1068 
1069  // UID resolver for pointer types (of 1st degree)
1070  template<typename T>
1071  class UIDChainResolver<T*> {
1072  public:
1073  UIDChainResolver(const T*& data) {
1074  const UID uids[2] = {
1075  { &data, sizeof(data) },
1076  { data, sizeof(*data) }
1077  };
1078  m_uid.push_back(uids[0]);
1079  m_uid.push_back(uids[1]);
1080  }
1081 
1082  operator UIDChain() const { return m_uid; }
1083  UIDChain operator()() const { return m_uid; }
1084  private:
1085  UIDChain m_uid;
1086  };
1087 
1088  // SerializationRecursion for non-pointer class/struct types.
1089  template<typename T, bool T_isRecursive>
1090  struct SerializationRecursionImpl {
1091  static void serializeObject(Archive* archive, const T& obj) {
1092  const_cast<T&>(obj).serialize(archive);
1093  }
1094  };
1095 
1096  // SerializationRecursion for pointers (of 1st degree) to class/structs.
1097  template<typename T, bool T_isRecursive>
1098  struct SerializationRecursionImpl<T*,T_isRecursive> {
1099  static void serializeObject(Archive* archive, const T*& obj) {
1100  if (!obj) return;
1101  const_cast<T*&>(obj)->serialize(archive);
1102  }
1103  };
1104 
1105  // NOOP SerializationRecursion for primitive types.
1106  template<typename T>
1107  struct SerializationRecursionImpl<T,false> {
1108  static void serializeObject(Archive* archive, const T& obj) {}
1109  };
1110 
1111  // NOOP SerializationRecursion for pointers (of 1st degree) to primitive types.
1112  template<typename T>
1113  struct SerializationRecursionImpl<T*,false> {
1114  static void serializeObject(Archive* archive, const T*& obj) {}
1115  };
1116 
1117  // Automatically handles recursion for class/struct types, while ignoring all primitive types.
1118  template<typename T>
1119  struct SerializationRecursion : SerializationRecursionImpl<T, LIBGIG_IS_CLASS(T)> {
1120  };
1121 
1122  class ObjectPool : public std::map<UID,Object> {
1123  public:
1124  // prevent passing obvious invalid UID values from creating a new pair entry
1125  Object& operator[](const UID& k) {
1126  static Object invalid;
1127  if (!k.isValid()) {
1128  invalid = Object();
1129  return invalid;
1130  }
1131  return std::map<UID,Object>::operator[](k);
1132  }
1133  };
1134 
1135  friend String _encode(const ObjectPool& objects);
1136 
1137  private:
1138  String _encodeRootBlob();
1139  void _popRootBlob(const char*& p, const char* end);
1140  void _popObjectsBlob(const char*& p, const char* end);
1141 
1142  protected:
1143  class Syncer {
1144  public:
1145  Syncer(Archive& dst, Archive& src);
1146  protected:
1147  void syncObject(const Object& dst, const Object& src);
1148  void syncPrimitive(const Object& dst, const Object& src);
1149  void syncPointer(const Object& dst, const Object& src);
1150  void syncMember(const Member& dstMember, const Member& srcMember);
1151  static Member dstMemberMatching(const Object& dstObj, const Object& srcObj, const Member& srcMember);
1152  private:
1153  Archive& m_dst;
1154  Archive& m_src;
1155  };
1156 
1157  enum operation_t {
1158  OPERATION_NONE,
1159  OPERATION_SERIALIZE,
1160  OPERATION_DESERIALIZE
1161  };
1162 
1163  virtual void encode();
1164 
1165  ObjectPool m_allObjects;
1166  operation_t m_operation;
1167  UID m_root;
1168  RawData m_rawData;
1169  bool m_isModified;
1170  String m_name;
1171  String m_comment;
1172  time_t m_timeCreated;
1173  time_t m_timeModified;
1174  };
1175 
1180  class Exception {
1181  public:
1182  String Message;
1183 
1184  Exception(String format, ...);
1185  Exception(String format, va_list arg);
1186  void PrintMessage();
1187  virtual ~Exception() {}
1188 
1189  protected:
1190  Exception();
1191  static String assemble(String format, va_list arg);
1192  };
1193 
1194 } // namespace Serialization
1195 
1196 #endif // LIBGIG_SERIALIZATION_H
Destination container for serialization, and source container for deserialization.
void setRealValue(Object &object, double value)
Set new floating point value for given floating point object.
void serializeMember(const T_classType &nativeObject, const T_memberType &nativeMember, const char *memberName)
Serialize a native C/C++ member variable.
void setMinVersion(const T_classType &nativeObject, Version v)
Set a minimum version number for your C++ class.
void setName(String name)
Assign a name to this archive.
void serialize(const T *obj)
Initiate serialization.
time_t timeStampCreated() const
Date and time when this archive was initially created.
void setBoolValue(Object &object, bool value)
Set new boolean value for given boolean object.
void clear()
Clear content of this archive.
double valueAsReal(const Object &object)
Get floating point value of object.
time_t timeStampModified() const
Date and time when this archive was modified for the last time.
virtual String rawDataFormat() const
Name of the encoding format used by this Archive class.
void setIntValue(Object &object, int64_t value)
Set new integer value for given integer object.
const RawData & rawData()
Raw data stream of this archive content.
bool isModified() const
Whether this archive was modified.
void deserialize(T *obj)
Initiate deserialization.
virtual void decode(const RawData &data)
Fill this archive with the given serialized raw data.
tm dateTimeCreated(time_base_t base=LOCAL_TIME) const
Date and time when this archive was initially created.
Object & rootObject()
Root C++ object of this archive.
Object & objectByUID(const UID &uid)
Access object by its unique identifier.
String valueAsString(const Object &object)
Get value of object as string.
int64_t valueAsInt(const Object &object)
Get integer value of object.
void setVersion(const T_classType &nativeObject, Version v)
Set current version number for your C++ class.
void removeMember(Object &parent, const Member &member)
Remove a member variable from the given object.
void remove(const Object &obj)
Remove an object from this archive.
bool valueAsBool(const Object &object)
Get boolean value of object.
void setEnumValue(Object &object, uint64_t value)
Set new value for given enum object.
void operator<<(const T &obj)
Initiate serialization of your C++ objects.
void setComment(String comment)
Assign a comment to this archive.
Archive()
Create an "empty" archive.
String name() const
Optional name of this archive.
void setAutoValue(Object &object, String value)
Automatically cast and assign appropriate value to object.
String comment() const
Optional comments for this archive.
void operator>>(T &obj)
Initiate deserialization of your C++ objects.
tm dateTimeModified(time_base_t base=LOCAL_TIME) const
Date and time when this archive was modified for the last time.
Abstract reflection of a native C++ data type.
bool isPrimitive() const
Whether this is reflecting a fundamental C/C++ data type.
bool isPointer() const
Whether this is reflecting a C/C++ pointer type.
bool isSigned() const
Whether this is a signed integer C/C++ data type.
String baseTypeName() const
The base type name of this data type.
bool operator!=(const DataType &other) const
Comparison for inequalness.
bool isReal() const
Whether this is a floating point based C/C++ data type.
DataType()
Default constructor.
String asLongDescr() const
Human readable long description for this data type.
bool isBool() const
Whether this is a boolean C/C++ data type.
bool isValid() const
Check if this is a valid DataType object.
bool operator>(const DataType &other) const
Greater than comparison.
bool isEnum() const
Whether this is a C/C++ enum data type.
bool operator<(const DataType &other) const
Smaller than comparison.
bool isClass() const
Whether this is reflecting a C/C++ struct or class type.
bool isInteger() const
Whether this is an integer C/C++ data type.
bool operator==(const DataType &other) const
Comparison for equalness.
static DataType dataTypeOf(const T &data)
Construct a DataType object for the given native C++ data.
String customTypeName(bool demangle=false) const
The user defined C/C++ data type name of this data type.
size_t size() const
Returns native memory size of the respective C++ object or variable.
Will be thrown whenever an error occurs during an serialization or deserialization process.
void PrintMessage()
Print exception message to stdout.
Abstract reflection of a native C++ class/struct's member variable.
Member()
Default constructor.
bool operator!=(const Member &other) const
Comparison for inequalness.
bool operator<(const Member &other) const
Smaller than comparison.
bool operator>(const Member &other) const
Greater than comparison.
String name() const
Name of the member.
bool operator==(const Member &other) const
Comparison for equalness.
const DataType & type() const
C/C++ Data type of this member.
size_t offset() const
Offset of member in its containing parent data structure.
bool isValid() const
Check if this is a valid Member object.
UID uid() const
Unique identifier of this member instance.
Abstract reflection of some native serialized C/C++ data.
bool isValid() const
Check if this is a valid Object instance.
Member memberNamed(String name) const
Get the member of this Object with given name.
Version version() const
Version of original user defined C/C++ struct or class.
UID uid(int index=0) const
Unique identifier of this Object.
const UIDChain & uidChain() const
Unique identifier chain of this Object.
const RawData & rawData() const
Raw data of the original native C/C++ data.
bool operator<(const Object &other) const
Smaller than comparison.
Object()
Default constructor (for an "invalid" Object).
Member memberByUID(const UID &uid) const
Get the member of this Object with given unique identifier.
std::vector< Member > membersOfType(const DataType &type) const
Get all members of this Object with given data type.
int sequenceIndexOf(const Member &member) const
Serialization/deserialization sequence number of the requested member.
bool operator!=(const Object &other) const
Comparison for inequalness.
bool operator>(const Object &other) const
Greater than comparison.
std::vector< Member > & members()
All members of the original native C/C++ struct or class instance.
const DataType & type() const
C/C++ data type this Object is reflecting.
bool isVersionCompatibleTo(const Object &other) const
Check version compatibility between Object instances.
Version minVersion() const
Minimum version of original user defined C/C++ struct or class.
bool operator==(const Object &other) const
Comparison for equalness.
Unique identifier referring to one specific native C++ object, member, fundamental variable,...
static UID from(const T &obj)
Create an unique indentifier for a native C++ object/member/variable.
bool isValid() const
Check whether this is a valid unique identifier.
size_t size
Memory size of the object or member in question.
ID id
Abstract non-unique ID of the object or member in question.
Serialization / deserialization framework.
Definition: gig.h:91
bool IsUnion(const T &data)
Check whether data is a C++ union type.
void * ID
Abstract identifier for serialized C++ objects.
const UID NO_UID
Reflects an invalid UID and behaves similar to NULL as invalid value for pointer types.
bool IsEnum(const T &data)
Check whether data is a C/C++ enum type.
bool IsClass(const T &data)
Check whether data is a C/C++ struct or C++ class type.
uint32_t Version
Version number data type.
std::vector< UID > UIDChain
Chain of UIDs.
std::vector< uint8_t > RawData
Raw data stream of serialized C++ objects.
time_base_t
To which time zone a certain timing information relates to.
@ UTC_TIME
The time stamp relates to "Greenwhich Mean Time" zone, also known as "Coordinated Universal Time"....
@ LOCAL_TIME
The time stamp relates to the machine's local time zone. Request a time stamp in local time if you wa...