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

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

#include <variant_object.hpp>

Public Types

typedef variant_object::entry entry
 a key/value pair
 
typedef std::vector< entry >::iterator iterator
 
typedef std::vector< entry >::const_iterator const_iterator
 

Public Member Functions

variantoperator[] (const string &key)
 
variantoperator[] (const char *key)
 
template<typename T , typename = std::enable_if_t<!std::is_base_of<mutable_variant_object, std::decay_t<T>>::value>>
 mutable_variant_object (T &&v)
 
 mutable_variant_object ()
 
 mutable_variant_object (string key, variant val)
 
template<typename T >
 mutable_variant_object (string key, T &&val)
 
 mutable_variant_object (mutable_variant_object &&)
 
 mutable_variant_object (const mutable_variant_object &)
 
 mutable_variant_object (const variant_object &)
 
mutable_variant_objectoperator= (mutable_variant_object &&)
 
mutable_variant_objectoperator= (const mutable_variant_object &)
 
mutable_variant_objectoperator= (const variant_object &)
 
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
 
mutable Interface

Calling these methods will result in a copy of the underlying type being created if there is more than one reference to this object.

void reserve (size_t s)
 
iterator begin ()
 
iterator end ()
 
void erase (const string &key)
 
iterator find (const string &key)
 
iterator find (const char *key)
 
mutable_variant_objectset (string key, variant var) &
 
mutable_variant_object set (string key, variant var) &&
 
mutable_variant_objectoperator() (string key, variant var) &
 
mutable_variant_object operator() (string key, variant var) &&
 
template<typename T >
mutable_variant_objectoperator() (string key, T &&var) &
 
template<typename T >
mutable_variant_object operator() (string key, T &&var) &&
 
mutable_variant_objectoperator() (const variant_object &vo) &
 
mutable_variant_object operator() (const variant_object &vo) &&
 
mutable_variant_objectoperator() (const mutable_variant_object &mvo) &
 
mutable_variant_object operator() (const mutable_variant_object &mvo) &&
 

Friends

class 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 117 of file variant_object.hpp.

Member Typedef Documentation

◆ const_iterator

std::vector<entry>::const_iterator fc::mutable_variant_object::const_iterator

Definition at line 124 of file variant_object.hpp.

◆ entry

◆ iterator

Definition at line 123 of file variant_object.hpp.

Constructor & Destructor Documentation

◆ mutable_variant_object() [1/7]

template<typename T , typename = std::enable_if_t<!std::is_base_of<mutable_variant_object, std::decay_t<T>>::value>>
fc::mutable_variant_object::mutable_variant_object ( T && v)
inlineexplicit

Definition at line 212 of file variant_object.hpp.

213 :_key_value( new std::vector<entry>() )
214 {
215 *this = variant(fc::forward<T>(v)).get_object();
216 }
Here is the call graph for this function:

◆ mutable_variant_object() [2/7]

fc::mutable_variant_object::mutable_variant_object ( )

Definition at line 273 of file variant_object.cpp.

274 :_key_value(new std::vector<entry>)
275 {
276 }

◆ mutable_variant_object() [3/7]

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

initializes the first key/value pair in the object

Definition at line 278 of file variant_object.cpp.

279 : _key_value(new std::vector<entry>())
280 {
281 _key_value->push_back(entry(fc::move(key), fc::move(val)));
282 }
variant_object::entry entry
a key/value pair

◆ mutable_variant_object() [4/7]

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

Definition at line 223 of file variant_object.hpp.

224 :_key_value( new std::vector<entry>() )
225 {
226 set( std::move(key), variant(forward<T>(val)) );
227 }
bool set

◆ mutable_variant_object() [5/7]

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

Definition at line 294 of file variant_object.cpp.

295 : _key_value(fc::move(obj._key_value))
296 {
297 }

◆ mutable_variant_object() [6/7]

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

Definition at line 289 of file variant_object.cpp.

290 : _key_value( new std::vector<entry>(*obj._key_value) )
291 {
292 }

◆ mutable_variant_object() [7/7]

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

Definition at line 284 of file variant_object.cpp.

285 : _key_value( new std::vector<entry>(*obj._key_value) )
286 {
287 }

Member Function Documentation

◆ begin() [1/2]

mutable_variant_object::iterator fc::mutable_variant_object::begin ( )

Definition at line 190 of file variant_object.cpp.

191 {
192 return _key_value->begin();
193 }

◆ begin() [2/2]

mutable_variant_object::iterator fc::mutable_variant_object::begin ( ) const

Definition at line 200 of file variant_object.cpp.

201 {
202 return _key_value->begin();
203 }
Here is the caller graph for this function:

◆ end() [1/2]

mutable_variant_object::iterator fc::mutable_variant_object::end ( )

Definition at line 195 of file variant_object.cpp.

196 {
197 return _key_value->end();
198 }

◆ end() [2/2]

mutable_variant_object::iterator fc::mutable_variant_object::end ( ) const

Definition at line 205 of file variant_object.cpp.

206 {
207 return _key_value->end();
208 }
Here is the caller graph for this function:

◆ erase()

void fc::mutable_variant_object::erase ( const string & key)

Definition at line 328 of file variant_object.cpp.

329 {
330 for( auto itr = begin(); itr != end(); ++itr )
331 {
332 if( itr->key() == key )
333 {
334 _key_value->erase(itr);
335 return;
336 }
337 }
338 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find() [1/4]

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

Definition at line 232 of file variant_object.cpp.

233 {
234 for( auto itr = begin(); itr != end(); ++itr )
235 {
236 if( itr->key() == key )
237 {
238 return itr;
239 }
240 }
241 return end();
242 }
Here is the call graph for this function:

◆ find() [2/4]

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

Definition at line 215 of file variant_object.cpp.

216 {
217 for( auto itr = begin(); itr != end(); ++itr )
218 {
219 if( itr->key() == key )
220 {
221 return itr;
222 }
223 }
224 return end();
225 }
Here is the call graph for this function:

◆ find() [3/4]

mutable_variant_object::iterator fc::mutable_variant_object::find ( const string & key)
Returns
end() if key is not found

Definition at line 227 of file variant_object.cpp.

228 {
229 return find( key.c_str() );
230 }
iterator find(const string &key) const
Here is the call graph for this function:

◆ find() [4/4]

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

Definition at line 210 of file variant_object.cpp.

211 {
212 return find( key.c_str() );
213 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator()() [1/8]

mutable_variant_object & fc::mutable_variant_object::operator() ( const mutable_variant_object & mvo) &

Copy another mutable_variant_object into this mutable_variant_object.

Definition at line 398 of file variant_object.cpp.

399 {
400 if( &mvo == this ) // mvo(mvo) is no-op
401 return *this;
402 for( const mutable_variant_object::entry& e : mvo )
403 set( e.key(), e.value() );
404 return *this;
405 }

◆ operator()() [2/8]

mutable_variant_object fc::mutable_variant_object::operator() ( const mutable_variant_object & mvo) &&

Definition at line 407 of file variant_object.cpp.

408 {
409 for( const mutable_variant_object::entry& e : mvo )
410 set( e.key(), e.value() );
411 return std::move(*this);
412 }

◆ operator()() [3/8]

mutable_variant_object & fc::mutable_variant_object::operator() ( const variant_object & vo) &

Copy a variant_object into this mutable_variant_object.

Definition at line 384 of file variant_object.cpp.

385 {
386 for( const variant_object::entry& e : vo )
387 set( e.key(), e.value() );
388 return *this;
389 }

◆ operator()() [4/8]

mutable_variant_object fc::mutable_variant_object::operator() ( const variant_object & vo) &&

Definition at line 391 of file variant_object.cpp.

392 {
393 for( const variant_object::entry& e : vo )
394 set( e.key(), e.value() );
395 return std::move(*this);
396 }

◆ operator()() [5/8]

template<typename T >
mutable_variant_object & fc::mutable_variant_object::operator() ( string key,
T && var ) &
inline

Definition at line 185 of file variant_object.hpp.

186 {
187 set(std::move(key), variant( fc::forward<T>(var) ) );
188 return *this;
189 }

◆ operator()() [6/8]

template<typename T >
mutable_variant_object fc::mutable_variant_object::operator() ( string key,
T && var ) &&
inline

Definition at line 191 of file variant_object.hpp.

192 {
193 set(std::move(key), variant( fc::forward<T>(var) ) );
194 return std::move(*this);
195 }

◆ operator()() [7/8]

mutable_variant_object & fc::mutable_variant_object::operator() ( string key,
variant var ) &

Appends key and var without checking for duplicates, designed to simplify construction of dictionaries using (key,val)(key2,val2) syntax Convenience method to simplify the manual construction of variant_objects

Instead of: mutable_variant_object("c",c).set("a",a).set("b",b);

You can use: mutable_variant_object( "c", c )( "b", b)( "c",c )

Returns
*this;

Appends key and var without checking for duplicates, designed to simplify construction of dictionaries using (key,val)(key2,val2) syntax

Definition at line 372 of file variant_object.cpp.

373 {
374 _key_value->push_back( entry( fc::move(key), fc::move(var) ) );
375 return *this;
376 }

◆ operator()() [8/8]

mutable_variant_object fc::mutable_variant_object::operator() ( string key,
variant var ) &&

Definition at line 378 of file variant_object.cpp.

379 {
380 _key_value->push_back( entry( fc::move(key), fc::move(var) ) );
381 return std::move(*this);
382 }

◆ operator=() [1/3]

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

Definition at line 314 of file variant_object.cpp.

315 {
316 if (this != &obj)
317 {
318 *_key_value = *obj._key_value;
319 }
320 return *this;
321 }

◆ operator=() [2/3]

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

Definition at line 299 of file variant_object.cpp.

300 {
301 *_key_value = *obj._key_value;
302 return *this;
303 }

◆ operator=() [3/3]

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

Definition at line 305 of file variant_object.cpp.

306 {
307 if (this != &obj)
308 {
309 _key_value = fc::move(obj._key_value);
310 }
311 return *this;
312 }

◆ operator[]() [1/4]

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

Definition at line 260 of file variant_object.cpp.

261 {
262 auto itr = find( key );
263 if( itr != end() ) return itr->value();
264 _key_value->emplace_back(entry(key, variant()));
265 return _key_value->back().value();
266 }
Here is the call graph for this function:

◆ operator[]() [2/4]

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

Definition at line 249 of file variant_object.cpp.

250 {
251 auto itr = find( key );
252 if( itr != end() ) return itr->value();
253 FC_THROW_EXCEPTION( key_not_found_exception, "Key ${key}", ("key",key) );
254 }
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
Here is the call graph for this function:

◆ operator[]() [3/4]

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

Definition at line 255 of file variant_object.cpp.

256 {
257 return (*this)[key.c_str()];
258 }

◆ operator[]() [4/4]

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

Definition at line 244 of file variant_object.cpp.

245 {
246 return (*this)[key.c_str()];
247 }

◆ reserve()

void fc::mutable_variant_object::reserve ( size_t s)

Definition at line 323 of file variant_object.cpp.

324 {
325 _key_value->reserve(s);
326 }
char * s
Here is the caller graph for this function:

◆ set() [1/2]

mutable_variant_object & fc::mutable_variant_object::set ( string key,
variant var ) &

replaces the value at key with var or inserts key if not found

replaces the value at key with var or insert's key if not found

Definition at line 341 of file variant_object.cpp.

342 {
343 auto itr = find( key.c_str() );
344 if( itr != end() )
345 {
346 itr->set( fc::move(var) );
347 }
348 else
349 {
350 _key_value->push_back( entry( fc::move(key), fc::move(var) ) );
351 }
352 return *this;
353 }
Here is the caller graph for this function:

◆ set() [2/2]

mutable_variant_object fc::mutable_variant_object::set ( string key,
variant var ) &&

Definition at line 355 of file variant_object.cpp.

356 {
357 auto itr = find( key.c_str() );
358 if( itr != end() )
359 {
360 itr->set( fc::move(var) );
361 }
362 else
363 {
364 _key_value->push_back( entry( fc::move(key), fc::move(var) ) );
365 }
366 return std::move(*this);
367 }

◆ size()

size_t fc::mutable_variant_object::size ( ) const

Definition at line 268 of file variant_object.cpp.

269 {
270 return _key_value->size();
271 }
Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ variant_object

friend class variant_object
friend

Definition at line 238 of file variant_object.hpp.


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