34#include <boost/mpl/contains.hpp>
62 template<
class t_value>
63 bool get_value(
const std::string& value_name, t_value& val,
hsection hparent_section);
65 template<
class t_value>
66 bool set_value(
const std::string& value_name, t_value&& target,
hsection hparent_section);
70 template<
class t_value>
72 template<
class t_value>
74 template<
class t_value>
76 template<
class t_value>
96 template<
class trace_policy>
97 bool dump_as_xml(std::string& targetObj,
const std::string& root_name =
"");
98 bool dump_as_json(std::string& targetObj,
size_t indent = 0,
bool insert_newlines =
true);
105 template<
class entry_type>
121 template<
class trace_policy>
127 template<
class to_type>
132 template<
class from_type>
136 template<
class t_value>
139 BOOST_MPL_ASSERT(( boost::mpl::contains<storage_entry::types, t_value> ));
141 if(!hparent_section) hparent_section = &
m_root;
147 boost::apply_visitor(gvv, *pentry);
152 template<
class t_value>
155 using t_real_value =
typename std::decay<t_value>::type;
156 BOOST_MPL_ASSERT(( boost::mpl::contains<boost::mpl::push_front<storage_entry::types, storage_entry>::type, t_real_value> ));
159 hparent_section = &
m_root;
168 *pentry = std::forward<t_value>(v);
170 CATCH_ENTRY(
"portable_storage::template<>set_value",
false);
173 template<
class entry_type>
176 static_assert(std::is_rvalue_reference<entry_type&&>(),
"unexpected copy of value");
178 CHECK_AND_ASSERT(psection,
nullptr);
179 CHECK_AND_ASSERT(!pentry_name.empty(),
nullptr);
180 auto ins_res = psection->
m_entries.emplace(pentry_name, std::forward<entry_type>(entry));
181 return &ins_res.first->second;
182 CATCH_ENTRY(
"portable_storage::insert_new_entry_get_storage_entry",
nullptr);
185 template<
class to_type>
190 template<
class from_type>
193 const from_type* pv =
a.get_first_val();
201 template<
class t_value>
204 BOOST_MPL_ASSERT(( boost::mpl::contains<storage_entry::types, t_value> ));
206 if(!hparent_section) hparent_section = &
m_root;
212 array_entry& ar_entry = boost::get<array_entry>(*pentry);
215 if(!boost::apply_visitor(gfv, ar_entry))
221 template<
class to_type>
226 template<
class from_type>
230 const from_type* pv =
a.get_next_val();
238 template<
class t_value>
241 BOOST_MPL_ASSERT(( boost::mpl::contains<storage_entry::types, t_value> ));
243 CHECK_AND_ASSERT(hval_array,
false);
246 if(!boost::apply_visitor(gnv, ar_entry))
252 template<
class t_value>
255 using t_real_value =
typename std::decay<t_value>::type;
256 static_assert(std::is_rvalue_reference<t_value&&>(),
"unexpected copy of value");
258 if(!hparent_section) hparent_section = &
m_root;
269 array_entry& arr = boost::get<array_entry>(*pentry);
276 CATCH_ENTRY(
"portable_storage::insert_first_value",
nullptr);
279 template<
class t_value>
282 using t_real_value =
typename std::decay<t_value>::type;
283 static_assert(std::is_rvalue_reference<t_value&&>(),
"unexpected copy of value");
285 CHECK_AND_ASSERT(hval_array,
false);
293 CATCH_ENTRY(
"portable_storage::insert_next_value",
false);
Definition byte_slice.h:69
A partial drop-in replacement for std::ostream.
Definition byte_stream.h:58
bool load_from_binary(const epee::span< const uint8_t > target, const limits_t *limits=nullptr)
Definition portable_storage.cpp:87
storage_entry * insert_new_entry_get_storage_entry(const std::string &pentry_name, hsection psection, entry_type &&entry)
Definition portable_storage.h:174
bool get_value(const std::string &value_name, t_value &val, hsection hparent_section)
Definition portable_storage.h:137
epee::serialization::hsection hsection
Definition portable_storage.h:48
bool delete_entry(const std::string &pentry_name, hsection hparent_section=nullptr)
bool store_to_binary(byte_slice &target, std::size_t initial_buffer_size=8192)
Definition portable_storage.cpp:46
harray get_first_value(const std::string &value_name, t_value &target, hsection hparent_section)
Definition portable_storage.h:202
storage_entry meta_entry
Definition portable_storage.h:50
bool set_value(const std::string &value_name, t_value &&target, hsection hparent_section)
Definition portable_storage.h:153
harray insert_first_section(const std::string &pSectionName, hsection &hinserted_childsection, hsection hparent_section)
Definition portable_storage.cpp:210
harray get_first_section(const std::string &pSectionName, hsection &h_child_section, hsection hparent_section)
Definition portable_storage.cpp:175
bool insert_next_section(harray hSecArray, hsection &hinserted_childsection)
Definition portable_storage.cpp:234
bool insert_next_value(harray hval_array, t_value &&target)
Definition portable_storage.h:280
virtual ~portable_storage()
Definition portable_storage.h:60
bool dump_as_xml(std::string &targetObj, const std::string &root_name="")
Definition portable_storage.h:122
bool load_from_binary(const std::string &target, const limits_t *limits=nullptr)
Definition portable_storage.h:91
hsection open_section(const std::string §ion_name, hsection hparent_section, bool create_if_notexist=false)
Definition portable_storage.cpp:117
harray insert_first_value(const std::string &value_name, t_value &&target, hsection hparent_section)
Definition portable_storage.h:253
portable_storage()
Definition portable_storage.h:59
bool get_next_value(harray hval_array, t_value &target)
Definition portable_storage.h:239
bool dump_as_json(std::string &targetObj, size_t indent=0, bool insert_newlines=true)
Definition portable_storage.cpp:70
epee::serialization::harray harray
Definition portable_storage.h:49
storage_entry * find_storage_entry(const std::string &pentry_name, hsection psection)
Definition portable_storage.cpp:154
section m_root
Definition portable_storage.h:102
bool load_from_json(const std::string &source)
Definition portable_storage.cpp:80
hsection insert_new_section(const std::string &pentry_name, hsection psection)
Definition portable_storage.cpp:166
hsection get_root_section()
Definition portable_storage.h:103
bool get_next_section(harray hSecArray, hsection &h_child_section)
Definition portable_storage.cpp:196
Non-owning sequence of data. Does not deep copy.
Definition span.h:55
Definition keyvalue_serialization_overloads.h:49
section * hsection
Definition portable_storage_base.h:174
void convert_t(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:203
boost::variant< uint64_t, uint32_t, uint16_t, uint8_t, int64_t, int32_t, int16_t, int8_t, double, bool, std::string, section, array_entry > storage_entry
Definition portable_storage_base.h:161
boost::make_recursive_variant< array_entry_t< section >, array_entry_t< uint64_t >, array_entry_t< uint32_t >, array_entry_t< uint16_t >, array_entry_t< uint8_t >, array_entry_t< int64_t >, array_entry_t< int32_t >, array_entry_t< int16_t >, array_entry_t< int8_t >, array_entry_t< double >, array_entry_t< bool >, array_entry_t< std::string >, array_entry_t< section >, array_entry_t< boost::recursive_variant_ > >::type array_entry
Definition portable_storage_base.h:159
array_entry * harray
Definition portable_storage_base.h:175
TODO: (mj-xmr) This will be reduced in an another PR.
Definition byte_slice.h:40
span< const T > strspan(const U &s) noexcept
make a span from a std::string
Definition span.h:183
const CharType(& source)[N]
Definition pointer.h:1147
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1124
unsigned int uint32_t
Definition stdint.h:126
unsigned char uint8_t
Definition stdint.h:124
Definition portable_storage_base.h:83
t_entry_type & insert_first_val(t_entry_type &&v)
Definition portable_storage_base.h:121
t_entry_type & insert_next_value(t_entry_type &&v)
Definition portable_storage_base.h:128
Definition portable_storage.h:187
to_type & m_target
Definition portable_storage.h:188
get_first_value_visitor(to_type &target)
Definition portable_storage.h:189
bool operator()(const array_entry_t< from_type > &a)
Definition portable_storage.h:191
Definition portable_storage.h:223
bool operator()(const array_entry_t< from_type > &a)
Definition portable_storage.h:227
get_next_value_visitor(to_type &target)
Definition portable_storage.h:225
to_type & m_target
Definition portable_storage.h:224
Definition portable_storage.h:129
void operator()(const from_type &v)
Definition portable_storage.h:133
get_value_visitor(to_type &target)
Definition portable_storage.h:131
to_type & m_target
Definition portable_storage.h:130
Definition portable_storage.h:53
size_t n_objects
Definition portable_storage.h:54
size_t n_fields
Definition portable_storage.h:55
size_t n_strings
Definition portable_storage.h:56
Definition portable_storage_base.h:169
std::map< std::string, storage_entry > m_entries
Definition portable_storage_base.h:170