36 |
#include <map> |
#include <map> |
37 |
#include <time.h> |
#include <time.h> |
38 |
#include <stdarg.h> |
#include <stdarg.h> |
39 |
|
#include <assert.h> |
40 |
|
|
41 |
#ifndef __has_extension |
#ifndef __has_extension |
42 |
# define __has_extension(x) 0 |
# define __has_extension(x) 0 |
412 |
if (type == typeid(uint32_t)) return DataType(T_isPointer, sz, "uint32"); |
if (type == typeid(uint32_t)) return DataType(T_isPointer, sz, "uint32"); |
413 |
if (type == typeid(int64_t)) return DataType(T_isPointer, sz, "int64"); |
if (type == typeid(int64_t)) return DataType(T_isPointer, sz, "int64"); |
414 |
if (type == typeid(uint64_t)) return DataType(T_isPointer, sz, "uint64"); |
if (type == typeid(uint64_t)) return DataType(T_isPointer, sz, "uint64"); |
415 |
|
if (type == typeid(size_t)) { |
416 |
|
if (sz == 1) return DataType(T_isPointer, sz, "uint8"); |
417 |
|
if (sz == 2) return DataType(T_isPointer, sz, "uint16"); |
418 |
|
if (sz == 4) return DataType(T_isPointer, sz, "uint32"); |
419 |
|
if (sz == 8) return DataType(T_isPointer, sz, "uint64"); |
420 |
|
else assert(false /* unknown size_t size */); |
421 |
|
} |
422 |
|
if (type == typeid(ssize_t)) { |
423 |
|
if (sz == 1) return DataType(T_isPointer, sz, "int8"); |
424 |
|
if (sz == 2) return DataType(T_isPointer, sz, "int16"); |
425 |
|
if (sz == 4) return DataType(T_isPointer, sz, "int32"); |
426 |
|
if (sz == 8) return DataType(T_isPointer, sz, "int64"); |
427 |
|
else assert(false /* unknown ssize_t size */); |
428 |
|
} |
429 |
if (type == typeid(bool)) return DataType(T_isPointer, sz, "bool"); |
if (type == typeid(bool)) return DataType(T_isPointer, sz, "bool"); |
430 |
if (type == typeid(float)) return DataType(T_isPointer, sz, "real32"); |
if (type == typeid(float)) return DataType(T_isPointer, sz, "real32"); |
431 |
if (type == typeid(double)) return DataType(T_isPointer, sz, "real64"); |
if (type == typeid(double)) return DataType(T_isPointer, sz, "real64"); |
725 |
*/ |
*/ |
726 |
class Archive { |
class Archive { |
727 |
public: |
public: |
728 |
|
/** @brief Current activity of @c Archive object. |
729 |
|
*/ |
730 |
|
enum operation_t { |
731 |
|
OPERATION_NONE, ///< Archive is currently neither serializing, nor deserializing. |
732 |
|
OPERATION_SERIALIZE, ///< Archive is currently serializing. |
733 |
|
OPERATION_DESERIALIZE ///< Archive is currently deserializing. |
734 |
|
}; |
735 |
|
|
736 |
Archive(); |
Archive(); |
737 |
Archive(const RawData& data); |
Archive(const RawData& data); |
738 |
Archive(const uint8_t* data, size_t size); |
Archive(const uint8_t* data, size_t size); |
801 |
template<typename T> |
template<typename T> |
802 |
void deserialize(T* obj) { |
void deserialize(T* obj) { |
803 |
Archive a; |
Archive a; |
804 |
m_operation = OPERATION_DESERIALIZE; |
a.m_operation = m_operation = OPERATION_DESERIALIZE; |
805 |
obj->serialize(&a); |
obj->serialize(&a); |
806 |
a.m_root = UID::from(obj); |
a.m_root = UID::from(obj); |
807 |
Syncer s(a, *this); |
Syncer s(a, *this); |
808 |
m_operation = OPERATION_NONE; |
a.m_operation = m_operation = OPERATION_NONE; |
809 |
} |
} |
810 |
|
|
811 |
/** @brief Initiate serialization of your C++ objects. |
/** @brief Initiate serialization of your C++ objects. |
1076 |
time_t timeStampModified() const; |
time_t timeStampModified() const; |
1077 |
tm dateTimeCreated(time_base_t base = LOCAL_TIME) const; |
tm dateTimeCreated(time_base_t base = LOCAL_TIME) const; |
1078 |
tm dateTimeModified(time_base_t base = LOCAL_TIME) const; |
tm dateTimeModified(time_base_t base = LOCAL_TIME) const; |
1079 |
|
operation_t operation() const; |
1080 |
|
|
1081 |
protected: |
protected: |
1082 |
// UID resolver for non-pointer types |
// UID resolver for non-pointer types |
1194 |
Archive& m_src; |
Archive& m_src; |
1195 |
}; |
}; |
1196 |
|
|
|
enum operation_t { |
|
|
OPERATION_NONE, |
|
|
OPERATION_SERIALIZE, |
|
|
OPERATION_DESERIALIZE |
|
|
}; |
|
|
|
|
1197 |
virtual void encode(); |
virtual void encode(); |
1198 |
|
|
1199 |
ObjectPool m_allObjects; |
ObjectPool m_allObjects; |