34 |
#include <string> |
#include <string> |
35 |
#include <vector> |
#include <vector> |
36 |
#include <map> |
#include <map> |
37 |
|
#include <time.h> |
38 |
|
|
39 |
/** @brief Serialization / deserialization framework. |
/** @brief Serialization / deserialization framework. |
40 |
* |
* |
81 |
*/ |
*/ |
82 |
namespace Serialization { |
namespace Serialization { |
83 |
|
|
84 |
|
// just symbol prototyping |
85 |
|
class DataType; |
86 |
|
class Object; |
87 |
|
class Member; |
88 |
class Archive; |
class Archive; |
89 |
|
class ObjectPool; |
90 |
class Exception; |
class Exception; |
91 |
|
|
92 |
typedef std::string String; |
typedef std::string String; |
103 |
OPERATION_DESERIALIZE |
OPERATION_DESERIALIZE |
104 |
}; |
}; |
105 |
|
|
106 |
|
enum time_base_t { |
107 |
|
LOCAL_TIME, |
108 |
|
UTC_TIME |
109 |
|
}; |
110 |
|
|
111 |
template<typename T> |
template<typename T> |
112 |
bool IsEnum(const T& data) { |
bool IsEnum(const T& data) { |
113 |
return __is_enum(T); |
return __is_enum(T); |
183 |
|
|
184 |
typedef std::vector<UID> UIDChain; |
typedef std::vector<UID> UIDChain; |
185 |
|
|
186 |
|
// prototyping of private internal friend functions |
187 |
|
static String _encodePrimitiveValue(const Object& obj); |
188 |
|
static DataType _popDataTypeBlob(const char*& p, const char* end); |
189 |
|
static Member _popMemberBlob(const char*& p, const char* end); |
190 |
|
static Object _popObjectBlob(const char*& p, const char* end); |
191 |
|
static void _popPrimitiveValue(const char*& p, const char* end, Object& obj); |
192 |
|
static String _primitiveObjectValueToString(const Object& obj); |
193 |
|
|
194 |
/** @brief Abstract reflection of a native C++ data type. |
/** @brief Abstract reflection of a native C++ data type. |
195 |
* |
* |
196 |
* Provides detailed information about a C++ data type, whether it is a |
* Provides detailed information about a C++ data type, whether it is a |
294 |
bool m_isPointer; |
bool m_isPointer; |
295 |
|
|
296 |
friend DataType _popDataTypeBlob(const char*& p, const char* end); |
friend DataType _popDataTypeBlob(const char*& p, const char* end); |
297 |
|
friend class Archive; |
298 |
}; |
}; |
299 |
|
|
300 |
/** @brief Abstract reflection of a native C++ class/struct's member variable. |
/** @brief Abstract reflection of a native C++ class/struct's member variable. |
368 |
std::vector<Member>& members() { return m_members; } |
std::vector<Member>& members() { return m_members; } |
369 |
const std::vector<Member>& members() const { return m_members; } |
const std::vector<Member>& members() const { return m_members; } |
370 |
Member memberNamed(String name) const; |
Member memberNamed(String name) const; |
371 |
void remove(const Member& member); |
Member memberByUID(const UID& uid) const; |
372 |
std::vector<Member> membersOfType(const DataType& type) const; |
std::vector<Member> membersOfType(const DataType& type) const; |
373 |
int sequenceIndexOf(const Member& member) const; |
int sequenceIndexOf(const Member& member) const; |
374 |
bool isValid() const; |
bool isValid() const; |
379 |
bool operator<(const Object& other) const; |
bool operator<(const Object& other) const; |
380 |
bool operator>(const Object& other) const; |
bool operator>(const Object& other) const; |
381 |
|
|
382 |
|
protected: |
383 |
|
void remove(const Member& member); |
384 |
|
|
385 |
private: |
private: |
386 |
DataType m_type; |
DataType m_type; |
387 |
UIDChain m_uid; |
UIDChain m_uid; |
390 |
RawData m_data; |
RawData m_data; |
391 |
std::vector<Member> m_members; |
std::vector<Member> m_members; |
392 |
|
|
393 |
|
friend String _encodePrimitiveValue(const Object& obj); |
394 |
friend Object _popObjectBlob(const char*& p, const char* end); |
friend Object _popObjectBlob(const char*& p, const char* end); |
395 |
friend void _popPrimitiveValue(const char*& p, const char* end, Object& obj); |
friend void _popPrimitiveValue(const char*& p, const char* end, Object& obj); |
396 |
|
friend String _primitiveObjectValueToString(const Object& obj); |
397 |
|
friend class Archive; |
398 |
}; |
}; |
399 |
|
|
400 |
/** @brief Destination container for serialization, and source container for deserialization. |
/** @brief Destination container for serialization, and source container for deserialization. |
548 |
deserialize(&obj); |
deserialize(&obj); |
549 |
} |
} |
550 |
|
|
551 |
const RawData& rawData() const { return m_rawData; } |
const RawData& rawData(); |
552 |
virtual String rawDataFormat() const; |
virtual String rawDataFormat() const; |
553 |
|
|
554 |
template<typename T_classType, typename T_memberType> |
template<typename T_classType, typename T_memberType> |
582 |
virtual void decode(const RawData& data); |
virtual void decode(const RawData& data); |
583 |
virtual void decode(const uint8_t* data, size_t size); |
virtual void decode(const uint8_t* data, size_t size); |
584 |
void clear(); |
void clear(); |
585 |
|
bool isModified() const; |
586 |
|
void removeMember(Object& parent, const Member& member); |
587 |
void remove(const Object& obj); |
void remove(const Object& obj); |
588 |
Object& rootObject(); |
Object& rootObject(); |
589 |
Object& objectByUID(const UID& uid); |
Object& objectByUID(const UID& uid); |
590 |
|
void setAutoValue(Object& object, String value); |
591 |
|
void setIntValue(Object& object, int64_t value); |
592 |
|
void setRealValue(Object& object, double value); |
593 |
|
void setBoolValue(Object& object, bool value); |
594 |
|
void setEnumValue(Object& object, uint64_t value); |
595 |
|
String valueAsString(const Object& object); |
596 |
|
String name() const; |
597 |
|
void setName(String name); |
598 |
|
String comment() const; |
599 |
|
void setComment(String comment); |
600 |
|
time_t timeStampCreated() const; |
601 |
|
time_t timeStampModified() const; |
602 |
|
tm dateTimeCreated(time_base_t base = LOCAL_TIME) const; |
603 |
|
tm dateTimeModified(time_base_t base = LOCAL_TIME) const; |
604 |
|
|
605 |
protected: |
protected: |
606 |
// UID resolver for non-pointer types |
// UID resolver for non-pointer types |
707 |
operation_t m_operation; |
operation_t m_operation; |
708 |
UID m_root; |
UID m_root; |
709 |
RawData m_rawData; |
RawData m_rawData; |
710 |
|
bool m_isModified; |
711 |
|
String m_name; |
712 |
|
String m_comment; |
713 |
|
time_t m_timeCreated; |
714 |
|
time_t m_timeModified; |
715 |
}; |
}; |
716 |
|
|
717 |
/** |
/** |