29 #include <boost/utility/value_init.hpp>
30 #include <boost/foreach.hpp>
35 #undef ELECTRONEUM_DEFAULT_LOG_CATEGORY
36 #define ELECTRONEUM_DEFAULT_LOG_CATEGORY "serialization"
43 #define BEGIN_KV_SERIALIZE_MAP() \
45 template<class t_storage> \
46 bool store( t_storage& st, typename t_storage::hsection hparent_section = nullptr) const\
48 return serialize_map<true>(*this, st, hparent_section);\
50 template<class t_storage> \
51 bool _load( t_storage& stg, typename t_storage::hsection hparent_section = nullptr)\
53 return serialize_map<false>(*this, stg, hparent_section);\
55 template<class t_storage> \
56 bool load( t_storage& stg, typename t_storage::hsection hparent_section = nullptr)\
59 return serialize_map<false>(*this, stg, hparent_section);\
61 catch(const std::exception& err) \
64 LOG_ERROR("Exception on unserializing: " << err.what());\
68 template<bool is_store, class this_type, class t_storage> \
69 static bool serialize_map(this_type& this_ref, t_storage& stg, typename t_storage::hsection hparent_section) \
72 #define KV_SERIALIZE_N(varialble, val_name) \
73 epee::serialization::selector<is_store>::serialize(this_ref.varialble, stg, hparent_section, val_name);
78 #define KV_SERIALIZE_OPT_N(variable, val_name, default_value) \
80 if (!epee::serialization::selector<is_store>::serialize(this_ref.variable, stg, hparent_section, val_name)) \
81 epee::serialize_default(this_ref.variable, default_value); \
84 #define KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, val_name) \
85 epee::serialization::selector<is_store>::serialize_t_val_as_blob(this_ref.varialble, stg, hparent_section, val_name);
87 #define KV_SERIALIZE_VAL_POD_AS_BLOB_N(varialble, val_name) \
88 static_assert(std::is_pod<decltype(this_ref.varialble)>::value, "t_type must be a POD type."); \
89 KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, val_name)
91 #define KV_SERIALIZE_VAL_POD_AS_BLOB_OPT_N(varialble, val_name, default_value) \
93 static_assert(std::is_pod<decltype(this_ref.varialble)>::value, "t_type must be a POD type."); \
94 bool ret = KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, val_name); \
96 epee::serialize_default(this_ref.varialble, default_value); \
99 #define KV_SERIALIZE_CONTAINER_POD_AS_BLOB_N(varialble, val_name) \
100 epee::serialization::selector<is_store>::serialize_stl_container_pod_val_as_blob(this_ref.varialble, stg, hparent_section, val_name);
102 #define END_KV_SERIALIZE_MAP() return true;}
104 #define KV_SERIALIZE(varialble) KV_SERIALIZE_N(varialble, #varialble)
105 #define KV_SERIALIZE_VAL_POD_AS_BLOB(varialble) KV_SERIALIZE_VAL_POD_AS_BLOB_N(varialble, #varialble)
106 #define KV_SERIALIZE_VAL_POD_AS_BLOB_OPT(varialble, def) KV_SERIALIZE_VAL_POD_AS_BLOB_OPT_N(varialble, #varialble, def)
107 #define KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(varialble) KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, #varialble)
108 #define KV_SERIALIZE_CONTAINER_POD_AS_BLOB(varialble) KV_SERIALIZE_CONTAINER_POD_AS_BLOB_N(varialble, #varialble)
109 #define KV_SERIALIZE_OPT(variable,default_value) KV_SERIALIZE_OPT_N(variable, #variable, default_value)
void serialize_default(const T &t, T v)