Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::chain::variant_snapshot_reader Class Reference

#include <snapshot.hpp>

Inheritance diagram for sysio::chain::variant_snapshot_reader:
Collaboration diagram for sysio::chain::variant_snapshot_reader:

Public Member Functions

 variant_snapshot_reader (const fc::variant &snapshot)
 
void validate () const override
 
bool has_section (const string &section_name) override
 
void set_section (const string &section_name) override
 
bool read_row (detail::abstract_snapshot_row_reader &row_reader) override
 
bool empty () override
 
void clear_section () override
 
void return_to_header () override
 
- Public Member Functions inherited from sysio::chain::snapshot_reader
template<typename F >
void read_section (const std::string &section_name, F f)
 
template<typename T , typename F >
void read_section (F f)
 
template<typename T >
bool has_section (const std::string &suffix=std::string())
 
virtual ~snapshot_reader ()
 

Additional Inherited Members

- Protected Member Functions inherited from sysio::chain::snapshot_reader

Detailed Description

Definition at line 311 of file snapshot.hpp.

Constructor & Destructor Documentation

◆ variant_snapshot_reader()

sysio::chain::variant_snapshot_reader::variant_snapshot_reader ( const fc::variant & snapshot)
explicit

Definition at line 31 of file snapshot.cpp.

32:snapshot(snapshot)
33,cur_section(nullptr)
34,cur_row(0)
35{
36}

Member Function Documentation

◆ clear_section()

void sysio::chain::variant_snapshot_reader::clear_section ( )
overridevirtual

Implements sysio::chain::snapshot_reader.

Definition at line 113 of file snapshot.cpp.

113 {
114 cur_section = nullptr;
115 cur_row = 0;
116}
Here is the caller graph for this function:

◆ empty()

bool sysio::chain::variant_snapshot_reader::empty ( )
overridevirtual

Implements sysio::chain::snapshot_reader.

Definition at line 108 of file snapshot.cpp.

108 {
109 const auto& rows = (*cur_section)["rows"].get_array();
110 return rows.empty();
111}

◆ has_section()

bool sysio::chain::variant_snapshot_reader::has_section ( const string & section_name)
overridevirtual

Implements sysio::chain::snapshot_reader.

Definition at line 79 of file snapshot.cpp.

79 {
80 const auto& sections = snapshot["sections"].get_array();
81 for( const auto& section: sections ) {
82 if (section["name"].as_string() == section_name) {
83 return true;
84 }
85 }
86
87 return false;
88}

◆ read_row()

bool sysio::chain::variant_snapshot_reader::read_row ( detail::abstract_snapshot_row_reader & row_reader)
overridevirtual

Implements sysio::chain::snapshot_reader.

Definition at line 102 of file snapshot.cpp.

102 {
103 const auto& rows = (*cur_section)["rows"].get_array();
104 row_reader.provide(rows.at(cur_row++));
105 return cur_row < rows.size();
106}
Here is the call graph for this function:

◆ return_to_header()

void sysio::chain::variant_snapshot_reader::return_to_header ( )
overridevirtual

Implements sysio::chain::snapshot_reader.

Definition at line 118 of file snapshot.cpp.

118 {
120}
Here is the call graph for this function:

◆ set_section()

void sysio::chain::variant_snapshot_reader::set_section ( const string & section_name)
overridevirtual

Implements sysio::chain::snapshot_reader.

Definition at line 90 of file snapshot.cpp.

90 {
91 const auto& sections = snapshot["sections"].get_array();
92 for( const auto& section: sections ) {
93 if (section["name"].as_string() == section_name) {
94 cur_section = &section.get_object();
95 return;
96 }
97 }
98
99 SYS_THROW(snapshot_exception, "Variant snapshot has no section named ${n}", ("n", section_name));
100}
#define SYS_THROW(exc_type, FORMAT,...)

◆ validate()

void sysio::chain::variant_snapshot_reader::validate ( ) const
overridevirtual

Implements sysio::chain::snapshot_reader.

Definition at line 38 of file snapshot.cpp.

38 {
39 SYS_ASSERT(snapshot.is_object(), snapshot_validation_exception,
40 "Variant snapshot is not an object");
41 const fc::variant_object& o = snapshot.get_object();
42
43 SYS_ASSERT(o.contains("version"), snapshot_validation_exception,
44 "Variant snapshot has no version");
45
46 const auto& version = o["version"];
47 SYS_ASSERT(version.is_integer(), snapshot_validation_exception,
48 "Variant snapshot version is not an integer");
49
50 SYS_ASSERT(version.as_uint64() == (uint64_t)current_snapshot_version, snapshot_validation_exception,
51 "Variant snapshot is an unsuppored version. Expected : ${expected}, Got: ${actual}",
52 ("expected", current_snapshot_version)("actual",o["version"].as_uint64()));
53
54 SYS_ASSERT(o.contains("sections"), snapshot_validation_exception,
55 "Variant snapshot has no sections");
56
57 const auto& sections = o["sections"];
58 SYS_ASSERT(sections.is_array(), snapshot_validation_exception, "Variant snapshot sections is not an array");
59
60 const auto& section_array = sections.get_array();
61 for( const auto& section: section_array ) {
62 SYS_ASSERT(section.is_object(), snapshot_validation_exception, "Variant snapshot section is not an object");
63
64 const auto& so = section.get_object();
65 SYS_ASSERT(so.contains("name"), snapshot_validation_exception,
66 "Variant snapshot section has no name");
67
68 SYS_ASSERT(so["name"].is_string(), snapshot_validation_exception,
69 "Variant snapshot section name is not a string");
70
71 SYS_ASSERT(so.contains("rows"), snapshot_validation_exception,
72 "Variant snapshot section has no rows");
73
74 SYS_ASSERT(so["rows"].is_array(), snapshot_validation_exception,
75 "Variant snapshot section rows is not an array");
76 }
77}
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
An order-preserving dictionary of variants.
bool contains(const char *key) const
unsigned __int64 uint64_t
Definition stdint.h:136
Here is the call graph for this function:

The documentation for this class was generated from the following files: