1 |
/*************************************************************************** |
/*************************************************************************** |
2 |
* * |
* * |
3 |
* Copyright (C) 2017 Christian Schoenebeck * |
* Copyright (C) 2017-2019 Christian Schoenebeck * |
4 |
* <cuse@users.sourceforge.net> * |
* <cuse@users.sourceforge.net> * |
5 |
* * |
* * |
6 |
* This library is part of libgig. * |
* This library is part of libgig. * |
7 |
* * |
* * |
35 |
#include <vector> |
#include <vector> |
36 |
#include <map> |
#include <map> |
37 |
#include <time.h> |
#include <time.h> |
38 |
|
#include <stdarg.h> |
39 |
|
|
40 |
#ifndef __has_extension |
#ifndef __has_extension |
41 |
# define __has_extension(x) 0 |
# define __has_extension(x) 0 |
223 |
return __is_pod(T); |
return __is_pod(T); |
224 |
}*/ |
}*/ |
225 |
|
|
226 |
/** @brief Unique identifier for one specific C++ object, member or fundamental variable. |
/** @brief Unique identifier referring to one specific native C++ object, member, fundamental variable, or any other native C++ data. |
227 |
* |
* |
228 |
* Reflects a unique identifier for one specific serialized C++ class |
* Reflects a unique identifier for one specific serialized C++ data, i.e. |
229 |
* instance, C/C++ struct instance, member, primitive pointer, or |
* C++ class instance, C/C++ struct instance, member, primitive pointer, |
230 |
* fundamental variables. |
* fundamental variables, or any other native C/C++ data originally being |
231 |
|
* serialized. |
232 |
* |
* |
233 |
* A unique identifier is composed of an id (an identifier which is not |
* A unique identifier is composed of an id (an identifier which is not |
234 |
* necessarily unique) and a size. Since the underlying ID is derived from |
* necessarily unique) and a size. Since the underlying ID is derived from |
323 |
*/ |
*/ |
324 |
typedef std::vector<UID> UIDChain; |
typedef std::vector<UID> UIDChain; |
325 |
|
|
326 |
|
#if LIBGIG_SERIALIZATION_INTERNAL |
327 |
// prototyping of private internal friend functions |
// prototyping of private internal friend functions |
328 |
static String _encodePrimitiveValue(const Object& obj); |
static String _encodePrimitiveValue(const Object& obj); |
329 |
static DataType _popDataTypeBlob(const char*& p, const char* end); |
static DataType _popDataTypeBlob(const char*& p, const char* end); |
334 |
// | |
// | |
335 |
template<typename T> |
template<typename T> |
336 |
static T _primitiveObjectValueToNumber(const Object& obj); |
static T _primitiveObjectValueToNumber(const Object& obj); |
337 |
|
#endif // LIBGIG_SERIALIZATION_INTERNAL |
338 |
|
|
339 |
/** @brief Abstract reflection of a native C++ data type. |
/** @brief Abstract reflection of a native C++ data type. |
340 |
* |
* |
441 |
template<typename T> |
template<typename T> |
442 |
static String rawCppTypeNameOf(const T& data) { |
static String rawCppTypeNameOf(const T& data) { |
443 |
#if defined _MSC_VER // Microsoft compiler ... |
#if defined _MSC_VER // Microsoft compiler ... |
444 |
# warning type_info::raw_name() demangling has not been tested yet with Microsoft compiler! Feedback appreciated! |
String name = typeid(data).raw_name(); |
|
String name = typeid(data).raw_name(); //NOTE: I haven't checked yet what MSC actually outputs here exactly |
|
445 |
#else // i.e. especially GCC and clang ... |
#else // i.e. especially GCC and clang ... |
446 |
String name = typeid(data).name(); |
String name = typeid(data).name(); |
447 |
#endif |
#endif |
456 |
int m_size; |
int m_size; |
457 |
bool m_isPointer; |
bool m_isPointer; |
458 |
|
|
459 |
|
#if LIBGIG_SERIALIZATION_INTERNAL |
460 |
friend DataType _popDataTypeBlob(const char*& p, const char* end); |
friend DataType _popDataTypeBlob(const char*& p, const char* end); |
461 |
|
#endif |
462 |
friend class Archive; |
friend class Archive; |
463 |
}; |
}; |
464 |
|
|
508 |
String m_name; |
String m_name; |
509 |
DataType m_type; |
DataType m_type; |
510 |
|
|
511 |
|
#if LIBGIG_SERIALIZATION_INTERNAL |
512 |
friend Member _popMemberBlob(const char*& p, const char* end); |
friend Member _popMemberBlob(const char*& p, const char* end); |
513 |
|
#endif |
514 |
}; |
}; |
515 |
|
|
516 |
/** @brief Abstract reflection of a native C++ class/struct instance. |
/** @brief Abstract reflection of some native serialized C/C++ data. |
517 |
* |
* |
518 |
* Provides detailed information about a specific serialized C++ object, |
* When your native C++ objects are serialized, all native data is |
519 |
* like its C++ member variables, its C++ class/struct name, its native |
* translated and reflected by such an Object reflection. So each instance |
520 |
* memory size and more. When your native C++ objects are serialized, all |
* of your serialized native C++ class objects become available as an |
521 |
* native data is translated reflected by such an Object reflection. So each |
* Object, but also each member variable of your C++ objects is translated |
522 |
* instance of your serialized C++ class objects become available as an |
* into an Object, and any other native C/C++ data. So essentially every |
523 |
* Object, but also each member variable of your C++ objects, and all other |
* native data is turned into its own Object and accessible by this API. |
524 |
* native C/C++ data. So essentially every native data is turned into its |
* |
525 |
* own Object and accessible by this API. |
* For each one of those Object reflections, this class provides detailed |
526 |
|
* information about their native origin. For example if an Object |
527 |
|
* represents a native C++ class instante, then it provides access to its |
528 |
|
* C++ class/struct name, to its C++ member variables, its native memory |
529 |
|
* size and much more. |
530 |
* |
* |
531 |
* Even though this framework allows you to adjust abstract Object instances |
* Even though this framework allows you to adjust abstract Object instances |
532 |
* to a certain extent, most of the methods of this Object class are |
* to a certain extent, most of the methods of this Object class are |
533 |
* read-only though and the actual modifyable methods are made available |
* read-only though and the actual modifyable methods are made available |
534 |
* not as part of this Object class, but as part of the Archive class |
* not as part of this Object class, but as part of the Archive class |
535 |
* instead. This was designed like this for performance and safety reasons. |
* instead. This design decision was made for performance and safety |
536 |
|
* reasons. |
537 |
* |
* |
538 |
* @see Archive::setIntValue() as an example for modifying Object instances. |
* @see Archive::setIntValue() as an example for modifying Object instances. |
539 |
*/ |
*/ |
576 |
RawData m_data; |
RawData m_data; |
577 |
std::vector<Member> m_members; |
std::vector<Member> m_members; |
578 |
|
|
579 |
|
#if LIBGIG_SERIALIZATION_INTERNAL |
580 |
friend String _encodePrimitiveValue(const Object& obj); |
friend String _encodePrimitiveValue(const Object& obj); |
581 |
friend Object _popObjectBlob(const char*& p, const char* end); |
friend Object _popObjectBlob(const char*& p, const char* end); |
582 |
friend void _popPrimitiveValue(const char*& p, const char* end, Object& obj); |
friend void _popPrimitiveValue(const char*& p, const char* end, Object& obj); |
583 |
friend String _primitiveObjectValueToString(const Object& obj); |
friend String _primitiveObjectValueToString(const Object& obj); |
584 |
|
// | |
585 |
template<typename T> |
template<typename T> |
586 |
friend T _primitiveObjectValueToNumber(const Object& obj); |
friend T _primitiveObjectValueToNumber(const Object& obj); |
587 |
|
#endif // LIBGIG_SERIALIZATION_INTERNAL |
588 |
|
|
589 |
friend class Archive; |
friend class Archive; |
590 |
}; |
}; |
1181 |
public: |
public: |
1182 |
String Message; |
String Message; |
1183 |
|
|
1184 |
Exception(String Message) { Exception::Message = Message; } |
Exception(String format, ...); |
1185 |
|
Exception(String format, va_list arg); |
1186 |
void PrintMessage(); |
void PrintMessage(); |
1187 |
virtual ~Exception() {} |
virtual ~Exception() {} |
1188 |
|
|
1189 |
|
protected: |
1190 |
|
Exception(); |
1191 |
|
static String assemble(String format, va_list arg); |
1192 |
}; |
}; |
1193 |
|
|
1194 |
} // namespace Serialization |
} // namespace Serialization |