BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface 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

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

fc::variant::variant ( )

Constructs a null_type variant.

Definition at line 30 of file variant.cpp.

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

Constructs a null_type variant.

Definition at line 35 of file variant.cpp.

fc::variant::variant ( const char *  str,
uint32_t  max_depth = 1 
)
Parameters
str- UTF8 string

Definition at line 120 of file variant.cpp.

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

Definition at line 114 of file variant.cpp.

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

Definition at line 127 of file variant.cpp.

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

Definition at line 138 of file variant.cpp.

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

Definition at line 96 of file variant.cpp.

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

Definition at line 40 of file variant.cpp.

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

Definition at line 46 of file variant.cpp.

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

Definition at line 52 of file variant.cpp.

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

Definition at line 58 of file variant.cpp.

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

Definition at line 64 of file variant.cpp.

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

Definition at line 70 of file variant.cpp.

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

Definition at line 76 of file variant.cpp.

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

Definition at line 90 of file variant.cpp.

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

Definition at line 102 of file variant.cpp.

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

Definition at line 108 of file variant.cpp.

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

Definition at line 153 of file variant.cpp.

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

Definition at line 148 of file variant.cpp.

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

Definition at line 159 of file variant.cpp.

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

Definition at line 164 of file variant.cpp.

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

Definition at line 170 of file variant.cpp.

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

Definition at line 200 of file variant.cpp.

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

Definition at line 224 of file variant.cpp.

fc::variant::~variant ( )

Definition at line 230 of file variant.cpp.

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

Definition at line 359 of file variant.hpp.

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

Definition at line 579 of file variant.hpp.

Member Function Documentation

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 336 of file variant.hpp.

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

Definition at line 344 of file variant.hpp.

blob fc::variant::as_blob ( ) const

Definition at line 518 of file variant.cpp.

bool fc::variant::as_bool ( ) const

Definition at line 441 of file variant.cpp.

double fc::variant::as_double ( ) const

Definition at line 420 of file variant.cpp.

int64_t fc::variant::as_int64 ( ) const

Definition at line 377 of file variant.cpp.

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.

uint64_t fc::variant::as_uint64 ( ) const

Definition at line 398 of file variant.cpp.

void fc::variant::clear ( )

Definition at line 181 of file variant.cpp.

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

Definition at line 496 of file variant.cpp.

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

Definition at line 545 of file variant.cpp.

blob & fc::variant::get_blob ( )

Definition at line 503 of file variant.cpp.

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

Definition at line 510 of file variant.cpp.

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

Definition at line 554 of file variant.cpp.

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

Definition at line 583 of file variant.cpp.

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

Definition at line 575 of file variant.cpp.

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

Definition at line 304 of file variant.cpp.

bool fc::variant::is_array ( ) const

Definition at line 368 of file variant.cpp.

bool fc::variant::is_blob ( ) const

Definition at line 372 of file variant.cpp.

bool fc::variant::is_bool ( ) const

Definition at line 318 of file variant.cpp.

bool fc::variant::is_double ( ) const

Definition at line 322 of file variant.cpp.

bool fc::variant::is_int64 ( ) const

Definition at line 330 of file variant.cpp.

bool fc::variant::is_integer ( ) const

int64, uint64, bool

Definition at line 335 of file variant.cpp.

bool fc::variant::is_null ( ) const

Definition at line 309 of file variant.cpp.

bool fc::variant::is_numeric ( ) const

int64, uint64, double,bool

Definition at line 348 of file variant.cpp.

bool fc::variant::is_object ( ) const

Definition at line 363 of file variant.cpp.

bool fc::variant::is_string ( ) const

Definition at line 314 of file variant.cpp.

bool fc::variant::is_uint64 ( ) const

Definition at line 326 of file variant.cpp.

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

Definition at line 235 of file variant.cpp.

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

Definition at line 244 of file variant.cpp.

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

Definition at line 353 of file variant.hpp.

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

Definition at line 561 of file variant.cpp.

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

Definition at line 565 of file variant.cpp.

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

Definition at line 570 of file variant.cpp.

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: