Electroneum
Loading...
Searching...
No Matches
epee::serialization::portable_storage Class Reference

#include <portable_storage.h>

Public Types

typedef epee::serialization::hsection hsection
typedef epee::serialization::harray harray
typedef storage_entry meta_entry

Public Member Functions

 portable_storage ()
virtual ~portable_storage ()
hsection open_section (const std::string &section_name, hsection hparent_section, bool create_if_notexist=false)
template<class t_value>
bool get_value (const std::string &value_name, t_value &val, hsection hparent_section)
bool get_value (const std::string &value_name, storage_entry &val, hsection hparent_section)
template<class t_value>
bool set_value (const std::string &value_name, const t_value &target, hsection hparent_section)
template<class t_value>
harray get_first_value (const std::string &value_name, t_value &target, hsection hparent_section)
template<class t_value>
bool get_next_value (harray hval_array, t_value &target)
template<class t_value>
harray insert_first_value (const std::string &value_name, const t_value &target, hsection hparent_section)
template<class t_value>
bool insert_next_value (harray hval_array, const t_value &target)
harray get_first_section (const std::string &pSectionName, hsection &h_child_section, hsection hparent_section)
bool get_next_section (harray hSecArray, hsection &h_child_section)
harray insert_first_section (const std::string &pSectionName, hsection &hinserted_childsection, hsection hparent_section)
bool insert_next_section (harray hSecArray, hsection &hinserted_childsection)
bool delete_entry (const std::string &pentry_name, hsection hparent_section=nullptr)
bool store_to_binary (binarybuffer &target)
bool load_from_binary (const epee::span< const uint8_t > target)
bool load_from_binary (const std::string &target)
template<class trace_policy>
bool dump_as_xml (std::string &targetObj, const std::string &root_name="")
bool dump_as_json (std::string &targetObj, size_t indent=0, bool insert_newlines=true)
bool load_from_json (const std::string &source)

Detailed Description

Definition at line 50 of file portable_storage.h.

Member Typedef Documentation

◆ harray

◆ hsection

◆ meta_entry

Constructor & Destructor Documentation

◆ portable_storage()

epee::serialization::portable_storage::portable_storage ( )
inline

Definition at line 57 of file portable_storage.h.

57{}

◆ ~portable_storage()

virtual epee::serialization::portable_storage::~portable_storage ( )
inlinevirtual

Definition at line 58 of file portable_storage.h.

58{}

Member Function Documentation

◆ delete_entry()

bool epee::serialization::portable_storage::delete_entry ( const std::string & pentry_name,
hsection hparent_section = nullptr )

◆ dump_as_json()

bool epee::serialization::portable_storage::dump_as_json ( std::string & targetObj,
size_t indent = 0,
bool insert_newlines = true )
inline

Definition at line 114 of file portable_storage.h.

115 {
116 TRY_ENTRY();
117 std::stringstream ss;
118 epee::serialization::dump_as_json(ss, m_root, indent, insert_newlines);
119 buff = ss.str();
120 return true;
121 CATCH_ENTRY("portable_storage::dump_as_json", false)
122 }
#define CATCH_ENTRY(location, return_val)
#define TRY_ENTRY()
void dump_as_json(t_stream &strm, const array_entry &ae, size_t indent, bool insert_newlines)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dump_as_xml()

template<class trace_policy>
bool epee::serialization::portable_storage::dump_as_xml ( std::string & targetObj,
const std::string & root_name = "" )

Definition at line 132 of file portable_storage.h.

133 {
134 return false;//TODO: don't think i ever again will use xml - ambiguous and "overtagged" format
135 }

◆ get_first_section()

harray epee::serialization::portable_storage::get_first_section ( const std::string & pSectionName,
hsection & h_child_section,
hsection hparent_section )
inline

Definition at line 408 of file portable_storage.h.

409 {
410 TRY_ENTRY();
411 if(!hparent_section) hparent_section = &m_root;
412 storage_entry* pentry = find_storage_entry(sec_name, hparent_section);
413 if(!pentry)
414 return nullptr;
415 if(pentry->type() != typeid(array_entry))
416 return nullptr;
417 array_entry& ar_entry = boost::get<array_entry>(*pentry);
418 if(ar_entry.type() != typeid(array_entry_t<section>))
419 return nullptr;
420 array_entry_t<section>& sec_array = boost::get<array_entry_t<section>>(ar_entry);
421 section* psec = sec_array.get_first_val();
422 if(!psec)
423 return nullptr;
424 h_child_section = psec;
425 return &ar_entry;
426 CATCH_ENTRY("portable_storage::get_first_section", nullptr);
427 }
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
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
Here is the call graph for this function:

◆ get_first_value()

template<class t_value>
harray epee::serialization::portable_storage::get_first_value ( const std::string & value_name,
t_value & target,
hsection hparent_section )

Definition at line 315 of file portable_storage.h.

316 {
317 BOOST_MPL_ASSERT(( boost::mpl::contains<storage_entry::types, t_value> ));
318 //TRY_ENTRY();
319 if(!hparent_section) hparent_section = &m_root;
320 storage_entry* pentry = find_storage_entry(value_name, hparent_section);
321 if(!pentry)
322 return nullptr;
323 if(pentry->type() != typeid(array_entry))
324 return nullptr;
325 array_entry& ar_entry = boost::get<array_entry>(*pentry);
326
327 get_first_value_visitor<t_value> gfv(target);
328 if(!boost::apply_visitor(gfv, ar_entry))
329 return nullptr;
330 return &ar_entry;
331 //CATCH_ENTRY("portable_storage::get_first_value", nullptr);
332 }

◆ get_next_section()

bool epee::serialization::portable_storage::get_next_section ( harray hSecArray,
hsection & h_child_section )
inline

Definition at line 430 of file portable_storage.h.

431 {
432 TRY_ENTRY();
433 CHECK_AND_ASSERT(hsec_array, false);
434 if(hsec_array->type() != typeid(array_entry_t<section>))
435 return false;
436 array_entry_t<section>& sec_array = boost::get<array_entry_t<section>>(*hsec_array);
437 h_child_section = sec_array.get_next_val();
438 if(!h_child_section)
439 return false;
440 return true;
441 CATCH_ENTRY("portable_storage::get_next_section", false);
442 }
#define CHECK_AND_ASSERT(expr, fail_ret_val)
Here is the call graph for this function:

◆ get_next_value()

template<class t_value>
bool epee::serialization::portable_storage::get_next_value ( harray hval_array,
t_value & target )

Definition at line 353 of file portable_storage.h.

354 {
355 BOOST_MPL_ASSERT(( boost::mpl::contains<storage_entry::types, t_value> ));
356 //TRY_ENTRY();
357 CHECK_AND_ASSERT(hval_array, false);
358 array_entry& ar_entry = *hval_array;
359 get_next_value_visitor<t_value> gnv(target);
360 if(!boost::apply_visitor(gnv, ar_entry))
361 return false;
362 return true;
363 //CATCH_ENTRY("portable_storage::get_next_value", false);
364 }

◆ get_value() [1/2]

bool epee::serialization::portable_storage::get_value ( const std::string & value_name,
storage_entry & val,
hsection hparent_section )
inline

Definition at line 232 of file portable_storage.h.

233 {
234 //TRY_ENTRY();
235 if(!hparent_section) hparent_section = &m_root;
236 storage_entry* pentry = find_storage_entry(value_name, hparent_section);
237 if(!pentry)
238 return false;
239
240 val = *pentry;
241 return true;
242 //CATCH_ENTRY("portable_storage::template<>get_value", false);
243 }

◆ get_value() [2/2]

template<class t_value>
bool epee::serialization::portable_storage::get_value ( const std::string & value_name,
t_value & val,
hsection hparent_section )

Definition at line 216 of file portable_storage.h.

217 {
218 BOOST_MPL_ASSERT(( boost::mpl::contains<storage_entry::types, t_value> ));
219 //TRY_ENTRY();
220 if(!hparent_section) hparent_section = &m_root;
221 storage_entry* pentry = find_storage_entry(value_name, hparent_section);
222 if(!pentry)
223 return false;
224
225 get_value_visitor<t_value> gvv(val);
226 boost::apply_visitor(gvv, *pentry);
227 return true;
228 //CATCH_ENTRY("portable_storage::template<>get_value", false);
229 }
Here is the caller graph for this function:

◆ insert_first_section()

harray epee::serialization::portable_storage::insert_first_section ( const std::string & pSectionName,
hsection & hinserted_childsection,
hsection hparent_section )
inline

Definition at line 445 of file portable_storage.h.

446 {
447 TRY_ENTRY();
448 if(!hparent_section) hparent_section = &m_root;
449 storage_entry* pentry = find_storage_entry(sec_name, hparent_section);
450 if(!pentry)
451 {
452 pentry = insert_new_entry_get_storage_entry(sec_name, hparent_section, array_entry(array_entry_t<section>()));
453 if(!pentry)
454 return nullptr;
455 }
456 if(pentry->type() != typeid(array_entry))
457 *pentry = storage_entry(array_entry(array_entry_t<section>()));
458
459 array_entry& ar_entry = boost::get<array_entry>(*pentry);
460 if(ar_entry.type() != typeid(array_entry_t<section>))
461 ar_entry = array_entry(array_entry_t<section>());
462
463 array_entry_t<section>& sec_array = boost::get<array_entry_t<section>>(ar_entry);
464 hinserted_childsection = &sec_array.insert_first_val(section());
465 return &ar_entry;
466 CATCH_ENTRY("portable_storage::insert_first_section", nullptr);
467 }
Here is the call graph for this function:

◆ insert_first_value()

template<class t_value>
harray epee::serialization::portable_storage::insert_first_value ( const std::string & value_name,
const t_value & target,
hsection hparent_section )

Definition at line 367 of file portable_storage.h.

368 {
369 TRY_ENTRY();
370 if(!hparent_section) hparent_section = &m_root;
371 storage_entry* pentry = find_storage_entry(value_name, hparent_section);
372 if(!pentry)
373 {
374 pentry = insert_new_entry_get_storage_entry(value_name, hparent_section, array_entry(array_entry_t<t_value>()));
375 if(!pentry)
376 return nullptr;
377 }
378 if(pentry->type() != typeid(array_entry))
379 *pentry = storage_entry(array_entry(array_entry_t<t_value>()));
380
381 array_entry& arr = boost::get<array_entry>(*pentry);
382 if(arr.type() != typeid(array_entry_t<t_value>))
383 arr = array_entry(array_entry_t<t_value>());
384
385 array_entry_t<t_value>& arr_typed = boost::get<array_entry_t<t_value> >(arr);
386 arr_typed.insert_first_val(target);
387 return &arr;
388 CATCH_ENTRY("portable_storage::insert_first_value", nullptr);
389 }
Here is the call graph for this function:

◆ insert_next_section()

bool epee::serialization::portable_storage::insert_next_section ( harray hSecArray,
hsection & hinserted_childsection )
inline

Definition at line 470 of file portable_storage.h.

471 {
472 TRY_ENTRY();
473 CHECK_AND_ASSERT(hsec_array, false);
474 CHECK_AND_ASSERT_MES(hsec_array->type() == typeid(array_entry_t<section>),
475 false, "unexpected type(not 'section') in insert_next_section, type: " << hsec_array->type().name());
476
477 array_entry_t<section>& sec_array = boost::get<array_entry_t<section>>(*hsec_array);
478 hinserted_childsection = &sec_array.insert_next_value(section());
479 return true;
480 CATCH_ENTRY("portable_storage::insert_next_section", false);
481 }
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Here is the call graph for this function:

◆ insert_next_value()

template<class t_value>
bool epee::serialization::portable_storage::insert_next_value ( harray hval_array,
const t_value & target )

Definition at line 392 of file portable_storage.h.

393 {
394 TRY_ENTRY();
395 CHECK_AND_ASSERT(hval_array, false);
396
397 CHECK_AND_ASSERT_MES(hval_array->type() == typeid(array_entry_t<t_value>),
398 false, "unexpected type in insert_next_value: " << typeid(array_entry_t<t_value>).name());
399
400 array_entry_t<t_value>& arr_typed = boost::get<array_entry_t<t_value> >(*hval_array);
401 arr_typed.insert_next_value(target);
402 return true;
403 CATCH_ENTRY("portable_storage::insert_next_value", false);
404 }
Here is the call graph for this function:

◆ load_from_binary() [1/2]

bool epee::serialization::portable_storage::load_from_binary ( const epee::span< const uint8_t > target)
inline

Definition at line 153 of file portable_storage.h.

154 {
155 m_root.m_entries.clear();
156 if(source.size() < sizeof(storage_block_header))
157 {
158 LOG_ERROR("portable_storage: wrong binary format, packet size = " << source.size() << " less than expected sizeof(storage_block_header)=" << sizeof(storage_block_header));
159 return false;
160 }
161 storage_block_header* pbuff = (storage_block_header*)source.data();
162 if(pbuff->m_signature_a != SWAP32LE(PORTABLE_STORAGE_SIGNATUREA) ||
163 pbuff->m_signature_b != SWAP32LE(PORTABLE_STORAGE_SIGNATUREB)
164 )
165 {
166 LOG_ERROR("portable_storage: wrong binary format - signature mismatch");
167 return false;
168 }
169 if(pbuff->m_ver != PORTABLE_STORAGE_FORMAT_VER)
170 {
171 LOG_ERROR("portable_storage: wrong binary format - unknown format ver = " << pbuff->m_ver);
172 return false;
173 }
174 TRY_ENTRY();
175 throwable_buffer_reader buf_reader(source.data()+sizeof(storage_block_header), source.size()-sizeof(storage_block_header));
176 buf_reader.read(m_root);
177 return true;//TODO:
178 CATCH_ENTRY("portable_storage::load_from_binary", false);
179 }
#define SWAP32LE
Definition int-util.h:224
#define LOG_ERROR(x)
Definition misc_log_ex.h:98
const CharType(& source)[N]
Definition pointer.h:1147
#define PORTABLE_STORAGE_SIGNATUREA
#define PORTABLE_STORAGE_SIGNATUREB
#define PORTABLE_STORAGE_FORMAT_VER
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_from_binary() [2/2]

bool epee::serialization::portable_storage::load_from_binary ( const std::string & target)
inline

Definition at line 88 of file portable_storage.h.

bool load_from_binary(const epee::span< const uint8_t > target)
span< const T > strspan(const std::string &s) noexcept
make a span from a std::string
Definition span.h:171
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_from_json()

bool epee::serialization::portable_storage::load_from_json ( const std::string & source)
inline

Definition at line 124 of file portable_storage.h.

125 {
126 TRY_ENTRY();
127 return json::load_from_json(source, *this);
128 CATCH_ENTRY("portable_storage::load_from_json", false)
129 }
Here is the caller graph for this function:

◆ open_section()

hsection epee::serialization::portable_storage::open_section ( const std::string & section_name,
hsection hparent_section,
bool create_if_notexist = false )
inline

Definition at line 182 of file portable_storage.h.

183 {
184 TRY_ENTRY();
185 hparent_section = hparent_section ? hparent_section:&m_root;
186 storage_entry* pentry = find_storage_entry(section_name, hparent_section);
187 if(!pentry)
188 {
189 if(!create_if_notexist)
190 return nullptr;
191 return insert_new_section(section_name, hparent_section);
192 }
193 CHECK_AND_ASSERT(pentry , nullptr);
194 //check that section_entry we find is real "CSSection"
195 if(pentry->type() != typeid(section))
196 {
197 if(create_if_notexist)
198 *pentry = storage_entry(section());//replace
199 else
200 return nullptr;
201 }
202 return &boost::get<section>(*pentry);
203 CATCH_ENTRY("portable_storage::open_section", nullptr);
204 }
Here is the caller graph for this function:

◆ set_value()

template<class t_value>
bool epee::serialization::portable_storage::set_value ( const std::string & value_name,
const t_value & target,
hsection hparent_section )

Definition at line 246 of file portable_storage.h.

247 {
248 BOOST_MPL_ASSERT(( boost::mpl::contains<boost::mpl::push_front<storage_entry::types, storage_entry>::type, t_value> ));
249 TRY_ENTRY();
250 if(!hparent_section)
251 hparent_section = &m_root;
252 storage_entry* pentry = find_storage_entry(value_name, hparent_section);
253 if(!pentry)
254 {
255 pentry = insert_new_entry_get_storage_entry(value_name, hparent_section, v);
256 if(!pentry)
257 return false;
258 return true;
259 }
260 *pentry = storage_entry(v);
261 return true;
262 CATCH_ENTRY("portable_storage::template<>set_value", false);
263 }
Here is the caller graph for this function:

◆ store_to_binary()

bool epee::serialization::portable_storage::store_to_binary ( binarybuffer & target)
inline

Definition at line 138 of file portable_storage.h.

139 {
140 TRY_ENTRY();
141 std::stringstream ss;
142 storage_block_header sbh = AUTO_VAL_INIT(sbh);
143 sbh.m_signature_a = SWAP32LE(PORTABLE_STORAGE_SIGNATUREA);
144 sbh.m_signature_b = SWAP32LE(PORTABLE_STORAGE_SIGNATUREB);
145 sbh.m_ver = PORTABLE_STORAGE_FORMAT_VER;
146 ss.write((const char*)&sbh, sizeof(storage_block_header));
147 pack_entry_to_buff(ss, m_root);
148 target = ss.str();
149 return true;
150 CATCH_ENTRY("portable_storage::store_to_binary", false)
151 }
#define AUTO_VAL_INIT(v)
bool pack_entry_to_buff(t_stream &strm, const array_entry &ae)
Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following file:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/contrib/epee/include/storages/portable_storage.h