34 |
#include <string> |
#include <string> |
35 |
#include <vector> |
#include <vector> |
36 |
#include <map> |
#include <map> |
37 |
|
#include <time.h> |
38 |
|
#if __cplusplus < 201103L |
39 |
|
# include <tr1/type_traits> |
40 |
|
#endif |
41 |
|
|
42 |
/** @brief Serialization / deserialization framework. |
/** @brief Serialization / deserialization framework. |
43 |
* |
* |
106 |
OPERATION_DESERIALIZE |
OPERATION_DESERIALIZE |
107 |
}; |
}; |
108 |
|
|
109 |
|
enum time_base_t { |
110 |
|
LOCAL_TIME, |
111 |
|
UTC_TIME |
112 |
|
}; |
113 |
|
|
114 |
template<typename T> |
template<typename T> |
115 |
bool IsEnum(const T& data) { |
bool IsEnum(const T& data) { |
116 |
return __is_enum(T); |
return __is_enum(T); |
187 |
typedef std::vector<UID> UIDChain; |
typedef std::vector<UID> UIDChain; |
188 |
|
|
189 |
// prototyping of private internal friend functions |
// prototyping of private internal friend functions |
190 |
|
static String _encodePrimitiveValue(const Object& obj); |
191 |
static DataType _popDataTypeBlob(const char*& p, const char* end); |
static DataType _popDataTypeBlob(const char*& p, const char* end); |
192 |
static Member _popMemberBlob(const char*& p, const char* end); |
static Member _popMemberBlob(const char*& p, const char* end); |
193 |
static Object _popObjectBlob(const char*& p, const char* end); |
static Object _popObjectBlob(const char*& p, const char* end); |
194 |
static void _popPrimitiveValue(const char*& p, const char* end, Object& obj); |
static void _popPrimitiveValue(const char*& p, const char* end, Object& obj); |
195 |
|
static String _primitiveObjectValueToString(const Object& obj); |
196 |
|
|
197 |
/** @brief Abstract reflection of a native C++ data type. |
/** @brief Abstract reflection of a native C++ data type. |
198 |
* |
* |
297 |
bool m_isPointer; |
bool m_isPointer; |
298 |
|
|
299 |
friend DataType _popDataTypeBlob(const char*& p, const char* end); |
friend DataType _popDataTypeBlob(const char*& p, const char* end); |
300 |
|
friend class Archive; |
301 |
}; |
}; |
302 |
|
|
303 |
/** @brief Abstract reflection of a native C++ class/struct's member variable. |
/** @brief Abstract reflection of a native C++ class/struct's member variable. |
371 |
std::vector<Member>& members() { return m_members; } |
std::vector<Member>& members() { return m_members; } |
372 |
const std::vector<Member>& members() const { return m_members; } |
const std::vector<Member>& members() const { return m_members; } |
373 |
Member memberNamed(String name) const; |
Member memberNamed(String name) const; |
374 |
void remove(const Member& member); |
Member memberByUID(const UID& uid) const; |
375 |
std::vector<Member> membersOfType(const DataType& type) const; |
std::vector<Member> membersOfType(const DataType& type) const; |
376 |
int sequenceIndexOf(const Member& member) const; |
int sequenceIndexOf(const Member& member) const; |
377 |
bool isValid() const; |
bool isValid() const; |
382 |
bool operator<(const Object& other) const; |
bool operator<(const Object& other) const; |
383 |
bool operator>(const Object& other) const; |
bool operator>(const Object& other) const; |
384 |
|
|
385 |
|
protected: |
386 |
|
void remove(const Member& member); |
387 |
|
|
388 |
private: |
private: |
389 |
DataType m_type; |
DataType m_type; |
390 |
UIDChain m_uid; |
UIDChain m_uid; |
393 |
RawData m_data; |
RawData m_data; |
394 |
std::vector<Member> m_members; |
std::vector<Member> m_members; |
395 |
|
|
396 |
|
friend String _encodePrimitiveValue(const Object& obj); |
397 |
friend Object _popObjectBlob(const char*& p, const char* end); |
friend Object _popObjectBlob(const char*& p, const char* end); |
398 |
friend void _popPrimitiveValue(const char*& p, const char* end, Object& obj); |
friend void _popPrimitiveValue(const char*& p, const char* end, Object& obj); |
399 |
|
friend String _primitiveObjectValueToString(const Object& obj); |
400 |
|
friend class Archive; |
401 |
}; |
}; |
402 |
|
|
403 |
/** @brief Destination container for serialization, and source container for deserialization. |
/** @brief Destination container for serialization, and source container for deserialization. |
551 |
deserialize(&obj); |
deserialize(&obj); |
552 |
} |
} |
553 |
|
|
554 |
const RawData& rawData() const { return m_rawData; } |
const RawData& rawData(); |
555 |
virtual String rawDataFormat() const; |
virtual String rawDataFormat() const; |
556 |
|
|
557 |
template<typename T_classType, typename T_memberType> |
template<typename T_classType, typename T_memberType> |
585 |
virtual void decode(const RawData& data); |
virtual void decode(const RawData& data); |
586 |
virtual void decode(const uint8_t* data, size_t size); |
virtual void decode(const uint8_t* data, size_t size); |
587 |
void clear(); |
void clear(); |
588 |
|
bool isModified() const; |
589 |
|
void removeMember(Object& parent, const Member& member); |
590 |
void remove(const Object& obj); |
void remove(const Object& obj); |
591 |
Object& rootObject(); |
Object& rootObject(); |
592 |
Object& objectByUID(const UID& uid); |
Object& objectByUID(const UID& uid); |
593 |
|
void setAutoValue(Object& object, String value); |
594 |
|
void setIntValue(Object& object, int64_t value); |
595 |
|
void setRealValue(Object& object, double value); |
596 |
|
void setBoolValue(Object& object, bool value); |
597 |
|
void setEnumValue(Object& object, uint64_t value); |
598 |
|
String valueAsString(const Object& object); |
599 |
|
String name() const; |
600 |
|
void setName(String name); |
601 |
|
String comment() const; |
602 |
|
void setComment(String comment); |
603 |
|
time_t timeStampCreated() const; |
604 |
|
time_t timeStampModified() const; |
605 |
|
tm dateTimeCreated(time_base_t base = LOCAL_TIME) const; |
606 |
|
tm dateTimeModified(time_base_t base = LOCAL_TIME) const; |
607 |
|
|
608 |
protected: |
protected: |
609 |
// UID resolver for non-pointer types |
// UID resolver for non-pointer types |
710 |
operation_t m_operation; |
operation_t m_operation; |
711 |
UID m_root; |
UID m_root; |
712 |
RawData m_rawData; |
RawData m_rawData; |
713 |
|
bool m_isModified; |
714 |
|
String m_name; |
715 |
|
String m_comment; |
716 |
|
time_t m_timeCreated; |
717 |
|
time_t m_timeModified; |
718 |
}; |
}; |
719 |
|
|
720 |
/** |
/** |