Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
variant_object.hpp
Go to the documentation of this file.
1#pragma once
2#include <fc/variant.hpp>
3#include <fc/unique_ptr.hpp>
4
5namespace fc
6{
7 class mutable_variant_object;
8
21 {
22 public:
24 class entry
25 {
26 public:
27 entry();
28 entry( string k, variant v );
29 entry( entry&& e );
30 entry( const entry& e);
31 entry& operator=(const entry&);
33
34 const string& key()const;
35 const variant& value()const;
36 void set( variant v );
37
38 variant& value();
39
40 friend bool operator == (const entry& a, const entry& b) {
41 return a._key == b._key && a._value == b._value;
42 }
43 friend bool operator != (const entry& a, const entry& b) {
44 return !(a == b);
45 }
46
47 private:
48 string _key;
49 variant _value;
50 };
51
52 typedef std::vector< entry >::const_iterator iterator;
53
61 iterator begin()const;
62 iterator end()const;
63 iterator find( const string& key )const;
64 iterator find( const char* key )const;
65 const variant& operator[]( const string& key )const;
66 const variant& operator[]( const char* key )const;
67 size_t size()const;
68 bool contains( const char* key ) const { return find(key) != end(); }
70
72
74 variant_object( string key, variant val );
75
76 template<typename T>
77 variant_object( string key, T&& val )
78 :_key_value( std::make_shared<std::vector<entry> >() )
79 {
80 *this = variant_object( std::move(key), variant(forward<T>(val)) );
81 }
84
87
90
93
94 size_t estimated_size()const;
95
96 private:
97 std::shared_ptr< std::vector< entry > > _key_value;
99 };
101 void to_variant( const variant_object& var, variant& vo );
103 void from_variant( const variant& var, variant_object& vo );
104
105
118 {
119 public:
122
123 typedef std::vector< entry >::iterator iterator;
124 typedef std::vector< entry >::const_iterator const_iterator;
125
133 iterator begin()const;
134 iterator end()const;
135 iterator find( const string& key )const;
136 iterator find( const char* key )const;
137 const variant& operator[]( const string& key )const;
138 const variant& operator[]( const char* key )const;
139 size_t size()const;
141 variant& operator[]( const string& key );
142 variant& operator[]( const char* key );
143
151 void reserve( size_t s);
152 iterator begin();
153 iterator end();
154 void erase( const string& key );
159 iterator find( const string& key );
160 iterator find( const char* key );
161
162
164 mutable_variant_object& set( string key, variant var ) &;
165 mutable_variant_object set( string key, variant var ) &&;
166
182 mutable_variant_object& operator()( string key, variant var ) &;
183 mutable_variant_object operator()( string key, variant var ) &&;
184 template<typename T>
185 mutable_variant_object& operator()( string key, T&& var ) &
186 {
187 set(std::move(key), variant( fc::forward<T>(var) ) );
188 return *this;
189 }
190 template<typename T>
191 mutable_variant_object operator()( string key, T&& var ) &&
192 {
193 set(std::move(key), variant( fc::forward<T>(var) ) );
194 return std::move(*this);
195 }
207
208
209 template<typename T,
210 typename = std::enable_if_t<!std::is_base_of<mutable_variant_object,
211 std::decay_t<T>>::value>>
212 explicit mutable_variant_object( T&& v )
213 :_key_value( new std::vector<entry>() )
214 {
215 *this = variant(fc::forward<T>(v)).get_object();
216 }
217
219
221 mutable_variant_object( string key, variant val );
222 template<typename T>
223 mutable_variant_object( string key, T&& val )
224 :_key_value( new std::vector<entry>() )
225 {
226 set( std::move(key), variant(forward<T>(val)) );
227 }
228
232
236 private:
237 std::unique_ptr< std::vector< entry > > _key_value;
238 friend class variant_object;
239 };
241 void to_variant( const mutable_variant_object& var, variant& vo );
243 void from_variant( const variant& var, mutable_variant_object& vo );
244
245} // namespace fc
An order-preserving dictionary of variants.
std::vector< entry >::iterator iterator
mutable_variant_object(string key, T &&val)
mutable_variant_object & operator=(mutable_variant_object &&)
variant_object::entry entry
a key/value pair
mutable_variant_object & operator()(string key, T &&var) &
mutable_variant_object & operator()(string key, variant var) &
const variant & operator[](const string &key) const
mutable_variant_object operator()(string key, T &&var) &&
void erase(const string &key)
iterator find(const string &key) const
std::vector< entry >::const_iterator const_iterator
const string & key() const
friend bool operator!=(const entry &a, const entry &b)
friend bool operator==(const entry &a, const entry &b)
const variant & value() const
entry & operator=(const entry &)
An order-preserving dictionary of variants.
size_t size() const
const variant & operator[](const string &key) const
size_t estimated_size() const
std::vector< entry >::const_iterator iterator
variant_object(string key, T &&val)
iterator end() const
variant_object & operator=(variant_object &&)
iterator find(const string &key) const
iterator begin() const
bool contains(const char *key) const
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
variant_object & get_object()
Definition variant.cpp:554
namespace sysio::chain
Definition authority.cpp:3
void from_variant(const fc::variant &v, sysio::chain::chain_id_type &cid)
void to_variant(const sysio::chain::shared_public_key &var, fc::variant &vo)
Definition authority.cpp:4
Definition name.hpp:106
#define value
Definition pkcs11.h:157
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
#define T(meth, val, expected)
char * s
bool set