Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
fc::variant_object Class Reference

An order-preserving dictionary of variants. More...

#include <variant_object.hpp>

Classes

class  entry
 a key/value pair More...
 

Public Types

typedef std::vector< entry >::const_iterator iterator
 

Public Member Functions

 variant_object ()
 
 variant_object (string key, variant val)
 
template<typename T >
 variant_object (string key, T &&val)
 
 variant_object (const variant_object &)
 
 variant_object (variant_object &&)
 
 variant_object (const mutable_variant_object &)
 
 variant_object (mutable_variant_object &&)
 
variant_objectoperator= (variant_object &&)
 
variant_objectoperator= (const variant_object &)
 
variant_objectoperator= (mutable_variant_object &&)
 
variant_objectoperator= (const mutable_variant_object &)
 
size_t estimated_size () const
 
Immutable Interface

Calling these methods will not result in copies of the underlying type.

iterator begin () const
 
iterator end () const
 
iterator find (const string &key) const
 
iterator find (const char *key) const
 
const variantoperator[] (const string &key) const
 
const variantoperator[] (const char *key) const
 
size_t size () const
 
bool contains (const char *key) const
 

Friends

class mutable_variant_object
 

Detailed Description

Keys are kept in the order they are inserted. This dictionary implements copy-on-write

Note
This class is not optimized for random-access on large sets of key-value pairs.

Definition at line 20 of file variant_object.hpp.

Member Typedef Documentation

◆ iterator

std::vector<entry>::const_iterator fc::variant_object::iterator

Definition at line 52 of file variant_object.hpp.

Constructor & Destructor Documentation

◆ variant_object() [1/7]

fc::variant_object::variant_object ( )

Definition at line 97 of file variant_object.cpp.

98 :_key_value(std::make_shared<std::vector<entry>>() )
99 {
100 }
Here is the caller graph for this function:

◆ variant_object() [2/7]

fc::variant_object::variant_object ( string key,
variant val )

initializes the first key/value pair in the object

Definition at line 102 of file variant_object.cpp.

103 : _key_value(std::make_shared<std::vector<entry>>())
104 {
105 //_key_value->push_back(entry(fc::move(key), fc::move(val)));
106 _key_value->emplace_back(entry(fc::move(key), fc::move(val)));
107 }

◆ variant_object() [3/7]

template<typename T >
fc::variant_object::variant_object ( string key,
T && val )
inline

Definition at line 77 of file variant_object.hpp.

78 :_key_value( std::make_shared<std::vector<entry> >() )
79 {
80 *this = variant_object( std::move(key), variant(forward<T>(val)) );
81 }
Here is the call graph for this function:

◆ variant_object() [4/7]

fc::variant_object::variant_object ( const variant_object & obj)

Definition at line 109 of file variant_object.cpp.

110 :_key_value( obj._key_value )
111 {
112 FC_ASSERT( _key_value != nullptr );
113 }
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.

◆ variant_object() [5/7]

fc::variant_object::variant_object ( variant_object && obj)

Definition at line 115 of file variant_object.cpp.

116 : _key_value( fc::move(obj._key_value) )
117 {
118 obj._key_value = std::make_shared<std::vector<entry>>();
119 FC_ASSERT( _key_value != nullptr );
120 }

◆ variant_object() [6/7]

fc::variant_object::variant_object ( const mutable_variant_object & obj)

Definition at line 122 of file variant_object.cpp.

123 : _key_value(std::make_shared<std::vector<entry>>(*obj._key_value))
124 {
125 }

◆ variant_object() [7/7]

fc::variant_object::variant_object ( mutable_variant_object && obj)

Definition at line 127 of file variant_object.cpp.

128 : _key_value(fc::move(obj._key_value))
129 {
130 FC_ASSERT( _key_value != nullptr );
131 }

Member Function Documentation

◆ begin()

variant_object::iterator fc::variant_object::begin ( ) const

Definition at line 52 of file variant_object.cpp.

53 {
54 FC_ASSERT( _key_value != nullptr );
55 return _key_value->begin();
56 }
Here is the caller graph for this function:

◆ contains()

bool fc::variant_object::contains ( const char * key) const
inline

Definition at line 68 of file variant_object.hpp.

68{ return find(key) != end(); }
iterator end() const
iterator find(const string &key) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ end()

variant_object::iterator fc::variant_object::end ( ) const

Definition at line 58 of file variant_object.cpp.

59 {
60 return _key_value->end();
61 }
Here is the caller graph for this function:

◆ estimated_size()

size_t fc::variant_object::estimated_size ( ) const

Definition at line 165 of file variant_object.cpp.

166 {
167 auto kv_size = size();
168 size_t sum = sizeof(*this) + sizeof(std::vector<entry>);
169 for (size_t iter = 0; iter < kv_size; ++iter) {
170 const auto& kv = _key_value->at(iter);
171 sum += kv.key().length() + sizeof(string);
172 sum += kv.value().estimated_size();
173 }
174 return sum;
175 }
size_t size() const
std::string string
Definition string.hpp:10
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find() [1/2]

variant_object::iterator fc::variant_object::find ( const char * key) const

Definition at line 68 of file variant_object.cpp.

69 {
70 for( auto itr = begin(); itr != end(); ++itr )
71 {
72 if( itr->key() == key )
73 {
74 return itr;
75 }
76 }
77 return end();
78 }
iterator begin() const
Here is the call graph for this function:

◆ find() [2/2]

variant_object::iterator fc::variant_object::find ( const string & key) const

Definition at line 63 of file variant_object.cpp.

64 {
65 return find( key.c_str() );
66 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=() [1/4]

variant_object & fc::variant_object::operator= ( const mutable_variant_object & obj)

Definition at line 159 of file variant_object.cpp.

160 {
161 *_key_value = *obj._key_value;
162 return *this;
163 }

◆ operator=() [2/4]

variant_object & fc::variant_object::operator= ( const variant_object & obj)

Definition at line 143 of file variant_object.cpp.

144 {
145 if (this != &obj)
146 {
147 _key_value = obj._key_value;
148 }
149 return *this;
150 }

◆ operator=() [3/4]

variant_object & fc::variant_object::operator= ( mutable_variant_object && obj)

Definition at line 152 of file variant_object.cpp.

153 {
154 _key_value = fc::move(obj._key_value);
155 obj._key_value.reset( new std::vector<entry>() );
156 return *this;
157 }

◆ operator=() [4/4]

variant_object & fc::variant_object::operator= ( variant_object && obj)

Definition at line 133 of file variant_object.cpp.

134 {
135 if (this != &obj)
136 {
137 fc_swap(_key_value, obj._key_value );
138 FC_ASSERT( _key_value != nullptr );
139 }
140 return *this;
141 }
void fc_swap(T &a, T &b)
Definition utility.hpp:211
Here is the call graph for this function:

◆ operator[]() [1/2]

const variant & fc::variant_object::operator[] ( const char * key) const

Definition at line 85 of file variant_object.cpp.

86 {
87 auto itr = find( key );
88 if( itr != end() ) return itr->value();
89 FC_THROW_EXCEPTION( key_not_found_exception, "Key ${key}", ("key",key) );
90 }
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
Here is the call graph for this function:

◆ operator[]() [2/2]

const variant & fc::variant_object::operator[] ( const string & key) const

Definition at line 80 of file variant_object.cpp.

81 {
82 return (*this)[key.c_str()];
83 }

◆ size()

size_t fc::variant_object::size ( ) const

Definition at line 92 of file variant_object.cpp.

93 {
94 return _key_value->size();
95 }
Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ mutable_variant_object

Definition at line 98 of file variant_object.hpp.


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