BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
Classes | Public Types | Public Member Functions | List of all members
fc::variant Class Reference

stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
More...

#include <variant.hpp>

Classes

class  visitor
 

Public Types

enum  type_id {
  null_type = 0, int64_type = 1, uint64_type = 2, double_type = 3,
  bool_type = 4, string_type = 5, array_type = 6, object_type = 7,
  blob_type = 8
}
 

Public Member Functions

 variant ()
 Constructs a null_type variant. More...
 
 variant (std::nullptr_t, uint32_t max_depth=1)
 Constructs a null_type variant. More...
 
 variant (const char *str, uint32_t max_depth=1)
 
 variant (char *str, uint32_t max_depth=1)
 
 variant (wchar_t *str, uint32_t max_depth=1)
 
 variant (const wchar_t *str, uint32_t max_depth=1)
 
 variant (float val, uint32_t max_depth=1)
 
 variant (uint8_t val, uint32_t max_depth=1)
 
 variant (int8_t val, uint32_t max_depth=1)
 
 variant (uint16_t val, uint32_t max_depth=1)
 
 variant (int16_t val, uint32_t max_depth=1)
 
 variant (uint32_t val, uint32_t max_depth=1)
 
 variant (int32_t val, uint32_t max_depth=1)
 
 variant (uint64_t val, uint32_t max_depth=1)
 
 variant (int64_t val, uint32_t max_depth=1)
 
 variant (double val, uint32_t max_depth=1)
 
 variant (bool val, uint32_t max_depth=1)
 
 variant (blob val, uint32_t max_depth=1)
 
 variant (std::string val, uint32_t max_depth=1)
 
 variant (variant_object, uint32_t max_depth=1)
 
 variant (mutable_variant_object, uint32_t max_depth=1)
 
 variant (variants, uint32_t max_depth=1)
 
 variant (const variant &, uint32_t max_depth=1)
 
 variant (variant &&, uint32_t max_depth=1)
 
 ~variant ()
 
void visit (const visitor &v) const
 
type_id get_type () const
 
bool is_null () const
 
bool is_string () const
 
bool is_bool () const
 
bool is_int64 () const
 
bool is_uint64 () const
 
bool is_double () const
 
bool is_object () const
 
bool is_array () const
 
bool is_blob () const
 
bool is_numeric () const
 
bool is_integer () const
 
int64_t as_int64 () const
 
uint64_t as_uint64 () const
 
bool as_bool () const
 
double as_double () const
 
blobget_blob ()
 
const blobget_blob () const
 
blob as_blob () const
 
std::string as_string () const
 
const std::string & get_string () const
 
variantsget_array ()
 
const variantsget_array () const
 
variant_objectget_object ()
 
const variant_objectget_object () const
 
const variantoperator[] (const char *) const
 
const variantoperator[] (size_t pos) const
 
size_t size () const
 
template<typename T >
as (uint32_t max_depth) const
 
template<typename T >
void as (T &v, uint32_t max_depth) const
 
variantoperator= (variant &&v)
 
variantoperator= (const variant &v)
 
template<typename T >
variantoperator= (T &&v)
 
template<typename T >
 variant (const optional< T > &v, uint32_t max_depth)
 
template<typename T >
 variant (const T &val, uint32_t max_depth)
 
void clear ()
 

Detailed Description

stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.

variant's allocate everything but strings, arrays, and objects on the stack and are 'move aware' for values allocated on the heap.

Memory usage on 64 bit systems is 16 bytes and 12 bytes on 32 bit systems.

Definition at line 198 of file variant.hpp.

Member Enumeration Documentation

◆ type_id

Enumerator
null_type 
int64_type 
uint64_type 
double_type 
bool_type 
string_type 
array_type 
object_type 
blob_type 

Definition at line 201 of file variant.hpp.

Constructor & Destructor Documentation

◆ variant() [1/26]

fc::variant::variant ( )

Constructs a null_type variant.

Definition at line 30 of file variant.cpp.

◆ variant() [2/26]

fc::variant::variant ( std::nullptr_t  ,
uint32_t  max_depth = 1 
)

Constructs a null_type variant.

Definition at line 35 of file variant.cpp.

◆ variant() [3/26]

fc::variant::variant ( const char *  str,
uint32_t  max_depth = 1 
)
Parameters
str- UTF8 string
max_depth- the maximum depth to recurse into

Definition at line 120 of file variant.cpp.

◆ variant() [4/26]

fc::variant::variant ( char *  str,
uint32_t  max_depth = 1 
)

Definition at line 114 of file variant.cpp.

◆ variant() [5/26]

fc::variant::variant ( wchar_t *  str,
uint32_t  max_depth = 1 
)

Definition at line 127 of file variant.cpp.

◆ variant() [6/26]

fc::variant::variant ( const wchar_t *  str,
uint32_t  max_depth = 1 
)

Definition at line 138 of file variant.cpp.

◆ variant() [7/26]

fc::variant::variant ( float  val,
uint32_t  max_depth = 1 
)

Definition at line 96 of file variant.cpp.

◆ variant() [8/26]

fc::variant::variant ( uint8_t  val,
uint32_t  max_depth = 1 
)

Definition at line 40 of file variant.cpp.

◆ variant() [9/26]

fc::variant::variant ( int8_t  val,
uint32_t  max_depth = 1 
)

Definition at line 46 of file variant.cpp.

◆ variant() [10/26]

fc::variant::variant ( uint16_t  val,
uint32_t  max_depth = 1 
)

Definition at line 52 of file variant.cpp.

◆ variant() [11/26]

fc::variant::variant ( int16_t  val,
uint32_t  max_depth = 1 
)

Definition at line 58 of file variant.cpp.

◆ variant() [12/26]

fc::variant::variant ( uint32_t  val,
uint32_t  max_depth = 1 
)

Definition at line 64 of file variant.cpp.

◆ variant() [13/26]

fc::variant::variant ( int32_t  val,
uint32_t  max_depth = 1 
)

Definition at line 70 of file variant.cpp.

◆ variant() [14/26]

fc::variant::variant ( uint64_t  val,
uint32_t  max_depth = 1 
)

Definition at line 76 of file variant.cpp.

◆ variant() [15/26]

fc::variant::variant ( int64_t  val,
uint32_t  max_depth = 1 
)

Definition at line 90 of file variant.cpp.

◆ variant() [16/26]

fc::variant::variant ( double  val,
uint32_t  max_depth = 1 
)

Definition at line 102 of file variant.cpp.

◆ variant() [17/26]

fc::variant::variant ( bool  val,
uint32_t  max_depth = 1 
)

Definition at line 108 of file variant.cpp.

◆ variant() [18/26]

fc::variant::variant ( blob  val,
uint32_t  max_depth = 1 
)

Definition at line 153 of file variant.cpp.

◆ variant() [19/26]

fc::variant::variant ( std::string  val,
uint32_t  max_depth = 1 
)

Definition at line 148 of file variant.cpp.

◆ variant() [20/26]

fc::variant::variant ( variant_object  obj,
uint32_t  max_depth = 1 
)

Definition at line 159 of file variant.cpp.

◆ variant() [21/26]

fc::variant::variant ( mutable_variant_object  obj,
uint32_t  max_depth = 1 
)

Definition at line 164 of file variant.cpp.

◆ variant() [22/26]

fc::variant::variant ( variants  arr,
uint32_t  max_depth = 1 
)

Definition at line 170 of file variant.cpp.

◆ variant() [23/26]

fc::variant::variant ( const variant v,
uint32_t  max_depth = 1 
)

Definition at line 200 of file variant.cpp.

◆ variant() [24/26]

fc::variant::variant ( variant &&  v,
uint32_t  max_depth = 1 
)

Definition at line 224 of file variant.cpp.

◆ ~variant()

fc::variant::~variant ( )

Definition at line 230 of file variant.cpp.

◆ variant() [25/26]

template<typename T >
fc::variant::variant ( const optional< T > &  v,
uint32_t  max_depth 
)
inline

Definition at line 360 of file variant.hpp.

◆ variant() [26/26]

template<typename T >
fc::variant::variant ( const T &  val,
uint32_t  max_depth 
)

Definition at line 580 of file variant.hpp.

Member Function Documentation

◆ as() [1/2]

template<typename T >
void fc::variant::as ( T &  v,
uint32_t  max_depth 
) const
inline

Definition at line 345 of file variant.hpp.

◆ as() [2/2]

template<typename T >
T fc::variant::as ( uint32_t  max_depth) const
inline

_types that use non-intrusive variant conversion can implement the following method to implement conversion from variant to T.

void from_variant( const Variant& var, T& val, uint32_t max_depth )

The above form is not always convienant, so the this templated method is used to enable conversion from Variants to other types.

Definition at line 337 of file variant.hpp.

◆ as_blob()

blob fc::variant::as_blob ( ) const

Definition at line 518 of file variant.cpp.

◆ as_bool()

bool fc::variant::as_bool ( ) const

Definition at line 441 of file variant.cpp.

◆ as_double()

double fc::variant::as_double ( ) const

Definition at line 420 of file variant.cpp.

◆ as_int64()

int64_t fc::variant::as_int64 ( ) const

Definition at line 377 of file variant.cpp.

◆ as_string()

string fc::variant::as_string ( ) const

Convert's double, ints, bools, etc to a string

Exceptions
ifget_type() == array_type | get_type() == object_type

Definition at line 469 of file variant.cpp.

◆ as_uint64()

uint64_t fc::variant::as_uint64 ( ) const

Definition at line 398 of file variant.cpp.

◆ clear()

void fc::variant::clear ( )

Definition at line 181 of file variant.cpp.

◆ get_array() [1/2]

const variants & fc::variant::get_array ( )
Exceptions
ifget_type() != array_type | null_type
ifget_type() != array_type

Definition at line 496 of file variant.cpp.

◆ get_array() [2/2]

const variants& fc::variant::get_array ( ) const
Exceptions
ifget_type() != array_type

◆ get_blob() [1/2]

const blob & fc::variant::get_blob ( )

Definition at line 503 of file variant.cpp.

◆ get_blob() [2/2]

const blob& fc::variant::get_blob ( ) const

◆ get_object() [1/2]

const variant_object & fc::variant::get_object ( )
Exceptions
ifget_type() != object_type | null_type
ifget_type() != object_type

Definition at line 554 of file variant.cpp.

◆ get_object() [2/2]

const variant_object& fc::variant::get_object ( ) const
Exceptions
ifget_type() != object_type

◆ get_string()

const string & fc::variant::get_string ( ) const
Precondition
get_type() == string_type

Definition at line 575 of file variant.cpp.

◆ get_type()

variant::type_id fc::variant::get_type ( ) const

Definition at line 304 of file variant.cpp.

◆ is_array()

bool fc::variant::is_array ( ) const

Definition at line 368 of file variant.cpp.

◆ is_blob()

bool fc::variant::is_blob ( ) const

Definition at line 372 of file variant.cpp.

◆ is_bool()

bool fc::variant::is_bool ( ) const

Definition at line 318 of file variant.cpp.

◆ is_double()

bool fc::variant::is_double ( ) const

Definition at line 322 of file variant.cpp.

◆ is_int64()

bool fc::variant::is_int64 ( ) const

Definition at line 330 of file variant.cpp.

◆ is_integer()

bool fc::variant::is_integer ( ) const

int64, uint64, bool

Definition at line 335 of file variant.cpp.

◆ is_null()

bool fc::variant::is_null ( ) const

Definition at line 309 of file variant.cpp.

◆ is_numeric()

bool fc::variant::is_numeric ( ) const

int64, uint64, double,bool

Definition at line 348 of file variant.cpp.

◆ is_object()

bool fc::variant::is_object ( ) const

Definition at line 363 of file variant.cpp.

◆ is_string()

bool fc::variant::is_string ( ) const

Definition at line 314 of file variant.cpp.

◆ is_uint64()

bool fc::variant::is_uint64 ( ) const

Definition at line 326 of file variant.cpp.

◆ operator=() [1/3]

variant & fc::variant::operator= ( const variant v)

Definition at line 244 of file variant.cpp.

◆ operator=() [2/3]

template<typename T >
variant& fc::variant::operator= ( T &&  v)
inline

Definition at line 354 of file variant.hpp.

◆ operator=() [3/3]

variant & fc::variant::operator= ( variant &&  v)

Definition at line 235 of file variant.cpp.

◆ operator[]() [1/2]

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

Definition at line 561 of file variant.cpp.

◆ operator[]() [2/2]

const variant & fc::variant::operator[] ( size_t  pos) const
Precondition
is_array()

Definition at line 565 of file variant.cpp.

◆ size()

size_t fc::variant::size ( ) const
Precondition
is_array()

Definition at line 570 of file variant.cpp.

◆ visit()

void fc::variant::visit ( const visitor v) const

Definition at line 271 of file variant.cpp.


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