35 |
#include <vector> |
#include <vector> |
36 |
#include <map> |
#include <map> |
37 |
#include <time.h> |
#include <time.h> |
38 |
|
#if __cplusplus < 201103L |
39 |
|
# include <tr1/type_traits> |
40 |
|
# define LIBGIG_IS_CLASS(type) std::tr1::__is_union_or_class<type>::value //NOTE: without compiler support we cannot distinguish union from class |
41 |
|
#else |
42 |
|
# define LIBGIG_IS_CLASS(type) __is_class(type) |
43 |
|
#endif |
44 |
|
|
45 |
/** @brief Serialization / deserialization framework. |
/** @brief Serialization / deserialization framework. |
46 |
* |
* |
116 |
|
|
117 |
template<typename T> |
template<typename T> |
118 |
bool IsEnum(const T& data) { |
bool IsEnum(const T& data) { |
119 |
|
#if __cplusplus < 201103L |
120 |
|
return std::tr1::is_enum<T>::value; |
121 |
|
#else |
122 |
return __is_enum(T); |
return __is_enum(T); |
123 |
|
#endif |
124 |
} |
} |
125 |
|
|
126 |
template<typename T> |
template<typename T> |
127 |
bool IsUnion(const T& data) { |
bool IsUnion(const T& data) { |
128 |
|
#if __cplusplus < 201103L |
129 |
|
return false; // without compiler support we cannot distinguish union from class |
130 |
|
#else |
131 |
return __is_union(T); |
return __is_union(T); |
132 |
|
#endif |
133 |
} |
} |
134 |
|
|
135 |
template<typename T> |
template<typename T> |
136 |
bool IsClass(const T& data) { |
bool IsClass(const T& data) { |
137 |
|
#if __cplusplus < 201103L |
138 |
|
return std::tr1::__is_union_or_class<T>::value; // without compiler support we cannot distinguish union from class |
139 |
|
#else |
140 |
return __is_class(T); |
return __is_class(T); |
141 |
|
#endif |
142 |
} |
} |
143 |
|
|
144 |
/*template<typename T> |
/*template<typename T> |
180 |
template<typename T> |
template<typename T> |
181 |
struct Resolver { |
struct Resolver { |
182 |
static UID resolve(const T& obj) { |
static UID resolve(const T& obj) { |
183 |
return (UID) { (ID) &obj, sizeof(obj) }; |
const UID uid = { (ID) &obj, sizeof(obj) }; |
184 |
|
return uid; |
185 |
} |
} |
186 |
}; |
}; |
187 |
|
|
189 |
template<typename T> |
template<typename T> |
190 |
struct Resolver<T*> { |
struct Resolver<T*> { |
191 |
static UID resolve(const T* const & obj) { |
static UID resolve(const T* const & obj) { |
192 |
return (UID) { (ID) obj, sizeof(*obj) }; |
const UID uid = { (ID) obj, sizeof(*obj) }; |
193 |
|
return uid; |
194 |
} |
} |
195 |
}; |
}; |
196 |
}; |
}; |
210 |
static Object _popObjectBlob(const char*& p, const char* end); |
static Object _popObjectBlob(const char*& p, const char* end); |
211 |
static void _popPrimitiveValue(const char*& p, const char* end, Object& obj); |
static void _popPrimitiveValue(const char*& p, const char* end, Object& obj); |
212 |
static String _primitiveObjectValueToString(const Object& obj); |
static String _primitiveObjectValueToString(const Object& obj); |
213 |
|
// | |
214 |
|
template<typename T> |
215 |
|
static T _primitiveObjectValueToNumber(const Object& obj); |
216 |
|
|
217 |
/** @brief Abstract reflection of a native C++ data type. |
/** @brief Abstract reflection of a native C++ data type. |
218 |
* |
* |
242 |
bool operator>(const DataType& other) const; |
bool operator>(const DataType& other) const; |
243 |
String asLongDescr() const; |
String asLongDescr() const; |
244 |
String baseTypeName() const { return m_baseTypeName; } |
String baseTypeName() const { return m_baseTypeName; } |
245 |
String customTypeName() const { return m_customTypeName; } |
String customTypeName(bool demangle = false) const; |
246 |
|
|
247 |
template<typename T> |
template<typename T> |
248 |
static DataType dataTypeOf(const T& data) { |
static DataType dataTypeOf(const T& data) { |
417 |
friend Object _popObjectBlob(const char*& p, const char* end); |
friend Object _popObjectBlob(const char*& p, const char* end); |
418 |
friend void _popPrimitiveValue(const char*& p, const char* end, Object& obj); |
friend void _popPrimitiveValue(const char*& p, const char* end, Object& obj); |
419 |
friend String _primitiveObjectValueToString(const Object& obj); |
friend String _primitiveObjectValueToString(const Object& obj); |
420 |
|
|
421 |
|
template<typename T> |
422 |
|
friend T _primitiveObjectValueToNumber(const Object& obj); |
423 |
|
|
424 |
friend class Archive; |
friend class Archive; |
425 |
}; |
}; |
426 |
|
|
620 |
void setBoolValue(Object& object, bool value); |
void setBoolValue(Object& object, bool value); |
621 |
void setEnumValue(Object& object, uint64_t value); |
void setEnumValue(Object& object, uint64_t value); |
622 |
String valueAsString(const Object& object); |
String valueAsString(const Object& object); |
623 |
|
int64_t valueAsInt(const Object& object); |
624 |
|
double valueAsReal(const Object& object); |
625 |
|
bool valueAsBool(const Object& object); |
626 |
String name() const; |
String name() const; |
627 |
void setName(String name); |
void setName(String name); |
628 |
String comment() const; |
String comment() const; |
652 |
class UIDChainResolver<T*> { |
class UIDChainResolver<T*> { |
653 |
public: |
public: |
654 |
UIDChainResolver(const T*& data) { |
UIDChainResolver(const T*& data) { |
655 |
m_uid.push_back((UID) { &data, sizeof(data) }); |
const UID uids[2] = { |
656 |
m_uid.push_back((UID) { data, sizeof(*data) }); |
{ &data, sizeof(data) }, |
657 |
|
{ data, sizeof(*data) } |
658 |
|
}; |
659 |
|
m_uid.push_back(uids[0]); |
660 |
|
m_uid.push_back(uids[1]); |
661 |
} |
} |
662 |
|
|
663 |
operator UIDChain() const { return m_uid; } |
operator UIDChain() const { return m_uid; } |
697 |
|
|
698 |
// Automatically handles recursion for class/struct types, while ignoring all primitive types. |
// Automatically handles recursion for class/struct types, while ignoring all primitive types. |
699 |
template<typename T> |
template<typename T> |
700 |
struct SerializationRecursion : SerializationRecursionImpl<T, __is_class(T)> { |
struct SerializationRecursion : SerializationRecursionImpl<T, LIBGIG_IS_CLASS(T)> { |
701 |
}; |
}; |
702 |
|
|
703 |
class ObjectPool : public std::map<UID,Object> { |
class ObjectPool : public std::map<UID,Object> { |