30#include <boost/utility/value_init.hpp>
31#include <boost/foreach.hpp>
35#undef MONERO_DEFAULT_LOG_CATEGORY
36#define MONERO_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 using type = typename std::remove_const<typename std::remove_reference<decltype(*this)>::type>::type; \
49 auto &self = const_cast<type&>(*this); \
50 return self.template serialize_map<true>(st, hparent_section); \
52 template<class t_storage> \
53 bool _load( t_storage& stg, typename t_storage::hsection hparent_section = nullptr)\
55 return serialize_map<false>(stg, hparent_section);\
57 template<class t_storage> \
58 bool load( t_storage& stg, typename t_storage::hsection hparent_section = nullptr)\
61 return serialize_map<false>(stg, hparent_section);\
63 catch(const std::exception& err) \
66 LOG_ERROR("Exception on unserializing: " << err.what());\
72 template<bool is_store, class t_storage> \
73 bool serialize_map(t_storage& stg, typename t_storage::hsection hparent_section) \
75 decltype(*this) &this_ref = *this; \
78#define KV_SERIALIZE_N(varialble, val_name) \
79 epee::serialization::selector<is_store>::serialize(this_ref.varialble, stg, hparent_section, val_name);
81#define KV_SERIALIZE_PARENT(type) \
83 if (!((type*)this)->serialize_map<is_store, t_storage>(stg, hparent_section)) \
90#define KV_SERIALIZE_OPT_N(variable, val_name, default_value) \
92 if (is_store && this_ref.variable == default_value) \
94 if (!epee::serialization::selector<is_store>::serialize(this_ref.variable, stg, hparent_section, val_name)) \
95 epee::serialize_default(this_ref.variable, default_value); \
98#define KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, val_name) \
99 epee::serialization::selector<is_store>::serialize_t_val_as_blob(this_ref.varialble, stg, hparent_section, val_name);
101#define KV_SERIALIZE_VAL_POD_AS_BLOB_N(varialble, val_name) \
102 static_assert(std::is_pod<decltype(this_ref.varialble)>::value, "t_type must be a POD type."); \
103 KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, val_name)
105#define KV_SERIALIZE_VAL_POD_AS_BLOB_OPT_N(varialble, val_name, default_value) \
107 static_assert(std::is_pod<decltype(this_ref.varialble)>::value, "t_type must be a POD type."); \
108 bool ret = KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, val_name); \
110 epee::serialize_default(this_ref.varialble, default_value); \
113#define KV_SERIALIZE_CONTAINER_POD_AS_BLOB_N(varialble, val_name) \
114 epee::serialization::selector<is_store>::serialize_stl_container_pod_val_as_blob(this_ref.varialble, stg, hparent_section, val_name);
116#define END_KV_SERIALIZE_MAP() return true;}
118#define KV_SERIALIZE(varialble) KV_SERIALIZE_N(varialble, #varialble)
119#define KV_SERIALIZE_VAL_POD_AS_BLOB(varialble) KV_SERIALIZE_VAL_POD_AS_BLOB_N(varialble, #varialble)
120#define KV_SERIALIZE_VAL_POD_AS_BLOB_OPT(varialble, def) KV_SERIALIZE_VAL_POD_AS_BLOB_OPT_N(varialble, #varialble, def)
121#define KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(varialble) KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, #varialble)
122#define KV_SERIALIZE_CONTAINER_POD_AS_BLOB(varialble) KV_SERIALIZE_CONTAINER_POD_AS_BLOB_N(varialble, #varialble)
123#define KV_SERIALIZE_OPT(variable,default_value) KV_SERIALIZE_OPT_N(variable, #variable, default_value)
TODO: (mj-xmr) This will be reduced in an another PR.
Definition: byte_slice.h:40
void serialize_default(const T &t, T v)
Definition: keyvalue_serialization.h:87