Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
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.
 
 variant (nullptr_t)
 Constructs a null_type variant.
 
 variant (const char *str)
 
 variant (char *str)
 
 variant (wchar_t *str)
 
 variant (const wchar_t *str)
 
 variant (float val)
 
 variant (uint8_t val)
 
 variant (int8_t val)
 
 variant (uint16_t val)
 
 variant (int16_t val)
 
 variant (uint32_t val)
 
 variant (int32_t val)
 
 variant (uint64_t val)
 
 variant (int64_t val)
 
 variant (double val)
 
 variant (bool val)
 
 variant (blob val)
 
 variant (fc::string val)
 
 variant (variant_object)
 
 variant (mutable_variant_object)
 
 variant (variants)
 
 variant (const variant &)
 
 variant (variant &&)
 
 ~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
 
string as_string () const
 
const stringget_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
 
size_t estimated_size () const
 
template<typename T >
T as () const
 
template<typename T >
void as (T &v) const
 
variantoperator= (variant &&v)
 
variantoperator= (const variant &v)
 
template<typename T >
variantoperator= (T &&v)
 
template<typename T >
 variant (const std::optional< T > &v)
 
template<typename T >
 variant (const T &val)
 
template<typename T >
 variant (const T &val, const fc::yield_function_t &yield)
 
void clear ()
 

Detailed Description

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

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

Definition at line 190 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 193 of file variant.hpp.

194 {
195 null_type = 0,
196 int64_type = 1,
197 uint64_type = 2,
198 double_type = 3,
199 bool_type = 4,
200 string_type = 5,
201 array_type = 6,
202 object_type = 7,
203 blob_type = 8
204 };

Constructor & Destructor Documentation

◆ variant() [1/27]

fc::variant::variant ( )

Definition at line 24 of file variant.cpp.

25{
27}
void set_variant_type(variant *v, variant::type_id t)
Definition variant.cpp:18
Here is the call graph for this function:
Here is the caller graph for this function:

◆ variant() [2/27]

fc::variant::variant ( fc::nullptr_t )

Definition at line 29 of file variant.cpp.

30{
32}
Here is the call graph for this function:

◆ variant() [3/27]

fc::variant::variant ( const char * str)
Parameters
str- UTF8 string

Definition at line 106 of file variant.cpp.

107{
108 *reinterpret_cast<string**>(this) = new string( str );
110}
Here is the call graph for this function:

◆ variant() [4/27]

fc::variant::variant ( char * str)

Definition at line 100 of file variant.cpp.

101{
102 *reinterpret_cast<string**>(this) = new string( str );
104}
Here is the call graph for this function:

◆ variant() [5/27]

fc::variant::variant ( wchar_t * str)

Definition at line 113 of file variant.cpp.

114{
115 size_t len = wcslen(str);
116 boost::scoped_array<char> buffer(new char[len]);
117 for (unsigned i = 0; i < len; ++i)
118 buffer[i] = (char)str[i];
119 *reinterpret_cast<string**>(this) = new string(buffer.get(), len);
121}
return str
Definition CLI11.hpp:1359
size_t len
Here is the call graph for this function:

◆ variant() [6/27]

fc::variant::variant ( const wchar_t * str)

Definition at line 124 of file variant.cpp.

125{
126 size_t len = wcslen(str);
127 boost::scoped_array<char> buffer(new char[len]);
128 for (unsigned i = 0; i < len; ++i)
129 buffer[i] = (char)str[i];
130 *reinterpret_cast<string**>(this) = new string(buffer.get(), len);
132}
Here is the call graph for this function:

◆ variant() [7/27]

fc::variant::variant ( float val)

Definition at line 82 of file variant.cpp.

83{
84 *reinterpret_cast<double*>(this) = val;
86}
Here is the call graph for this function:

◆ variant() [8/27]

fc::variant::variant ( uint8_t val)

Definition at line 34 of file variant.cpp.

35{
36 *reinterpret_cast<uint64_t*>(this) = val;
38}
unsigned __int64 uint64_t
Definition stdint.h:136
Here is the call graph for this function:

◆ variant() [9/27]

fc::variant::variant ( int8_t val)

Definition at line 40 of file variant.cpp.

41{
42 *reinterpret_cast<int64_t*>(this) = val;
44}
signed __int64 int64_t
Definition stdint.h:135
Here is the call graph for this function:

◆ variant() [10/27]

fc::variant::variant ( uint16_t val)

Definition at line 46 of file variant.cpp.

47{
48 *reinterpret_cast<uint64_t*>(this) = val;
50}
Here is the call graph for this function:

◆ variant() [11/27]

fc::variant::variant ( int16_t val)

Definition at line 52 of file variant.cpp.

53{
54 *reinterpret_cast<int64_t*>(this) = val;
56}
Here is the call graph for this function:

◆ variant() [12/27]

fc::variant::variant ( uint32_t val)

Definition at line 58 of file variant.cpp.

59{
60 *reinterpret_cast<uint64_t*>(this) = val;
62}
Here is the call graph for this function:

◆ variant() [13/27]

fc::variant::variant ( int32_t val)

Definition at line 64 of file variant.cpp.

65{
66 *reinterpret_cast<int64_t*>(this) = val;
68}
Here is the call graph for this function:

◆ variant() [14/27]

fc::variant::variant ( uint64_t val)

Definition at line 70 of file variant.cpp.

71{
72 *reinterpret_cast<uint64_t*>(this) = val;
74}
Here is the call graph for this function:

◆ variant() [15/27]

fc::variant::variant ( int64_t val)

Definition at line 76 of file variant.cpp.

77{
78 *reinterpret_cast<int64_t*>(this) = val;
80}
Here is the call graph for this function:

◆ variant() [16/27]

fc::variant::variant ( double val)

Definition at line 88 of file variant.cpp.

89{
90 *reinterpret_cast<double*>(this) = val;
92}
Here is the call graph for this function:

◆ variant() [17/27]

fc::variant::variant ( bool val)

Definition at line 94 of file variant.cpp.

95{
96 *reinterpret_cast<bool*>(this) = val;
98}
Here is the call graph for this function:

◆ variant() [18/27]

fc::variant::variant ( blob val)

Definition at line 139 of file variant.cpp.

140{
141 *reinterpret_cast<blob**>(this) = new blob( fc::move(val) );
143}
Here is the call graph for this function:

◆ variant() [19/27]

fc::variant::variant ( fc::string val)

Definition at line 134 of file variant.cpp.

135{
136 *reinterpret_cast<string**>(this) = new string( fc::move(val) );
138}
Here is the call graph for this function:

◆ variant() [20/27]

fc::variant::variant ( variant_object obj)

Definition at line 145 of file variant.cpp.

146{
147 *reinterpret_cast<variant_object**>(this) = new variant_object(fc::move(obj));
149}
Here is the call graph for this function:

◆ variant() [21/27]

fc::variant::variant ( mutable_variant_object obj)

Definition at line 150 of file variant.cpp.

151{
152 *reinterpret_cast<variant_object**>(this) = new variant_object(fc::move(obj));
154}
Here is the call graph for this function:

◆ variant() [22/27]

fc::variant::variant ( variants arr)

Definition at line 156 of file variant.cpp.

157{
158 *reinterpret_cast<variants**>(this) = new variants(fc::move(arr));
160}
std::vector< fc::variant > variants
Definition variant.hpp:173
Here is the call graph for this function:

◆ variant() [23/27]

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

Definition at line 190 of file variant.cpp.

191{
192 switch( v.get_type() )
193 {
194 case object_type:
195 *reinterpret_cast<variant_object**>(this) =
196 new variant_object(**reinterpret_cast<const const_variant_object_ptr*>(&v));
198 return;
199 case array_type:
200 *reinterpret_cast<variants**>(this) =
201 new variants(**reinterpret_cast<const const_variants_ptr*>(&v));
203 return;
204 case string_type:
205 *reinterpret_cast<string**>(this) =
206 new string(**reinterpret_cast<const const_string_ptr*>(&v) );
208 return;
209 case blob_type:
210 *reinterpret_cast<blob**>(this) =
211 new blob(**reinterpret_cast<const const_blob_ptr*>(&v) );
213 return;
214 default:
215 memcpy( this, &v, sizeof(v) );
216 }
217}
const variant_object * const_variant_object_ptr
Definition variant.cpp:163
const string * const_string_ptr
Definition variant.cpp:166
const variants * const_variants_ptr
Definition variant.cpp:164
const blob * const_blob_ptr
Definition variant.cpp:165
memcpy((char *) pInfo->slotDescription, s, l)
Here is the call graph for this function:

◆ variant() [24/27]

fc::variant::variant ( variant && v)

Definition at line 219 of file variant.cpp.

220{
221 memcpy( this, &v, sizeof(v) );
223}
Here is the call graph for this function:

◆ ~variant()

fc::variant::~variant ( )

Definition at line 225 of file variant.cpp.

226{
227 clear();
228}
void clear()
Definition variant.cpp:168
Here is the call graph for this function:

◆ variant() [25/27]

template<typename T >
fc::variant::variant ( const std::optional< T > & v)
inlineexplicit

Definition at line 350 of file variant.hpp.

351 {
352 memset( this, 0, sizeof(*this) );
353 if( v.has_value() ) *this = variant(*v);
354 }
variant()
Constructs a null_type variant.
Definition variant.cpp:24
memset(pInfo->slotDescription, ' ', 64)
Here is the call graph for this function:

◆ variant() [26/27]

template<typename T >
fc::variant::variant ( const T & val)
explicit

Definition at line 616 of file variant.hpp.

617 {
618 memset( this, 0, sizeof(*this) );
619 to_variant( val, *this );
620 }
void to_variant(const sysio::chain::shared_public_key &var, fc::variant &vo)
Definition authority.cpp:4
Here is the call graph for this function:

◆ variant() [27/27]

template<typename T >
fc::variant::variant ( const T & val,
const fc::yield_function_t & yield )
explicit

Definition at line 623 of file variant.hpp.

624 {
625 memset( this, 0, sizeof(*this) );
626 to_variant( val, *this, yield );
627 }
Here is the call graph for this function:

Member Function Documentation

◆ as() [1/2]

template<typename T >
T fc::variant::as ( ) 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 )

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

328 {
329 T tmp;
330 from_variant( *this, tmp );
331 return tmp;
332 }
void from_variant(const fc::variant &v, sysio::chain::chain_id_type &cid)
#define T(meth, val, expected)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ as() [2/2]

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

Definition at line 335 of file variant.hpp.

336 {
337 from_variant( *this, v );
338 }
Here is the call graph for this function:

◆ as_blob()

blob fc::variant::as_blob ( ) const

Definition at line 518 of file variant.cpp.

519{
520 switch( get_type() )
521 {
522 case null_type: return blob();
523 case blob_type: return get_blob();
524 case string_type:
525 {
526 const string& str = get_string();
527 if( str.size() == 0 ) return blob();
528 if( str.back() == '=' )
529 {
530 std::string b64 = base64_decode( get_string() );
531 return blob( { std::vector<char>( b64.begin(), b64.end() ) } );
532 }
533 return blob( { std::vector<char>( str.begin(), str.end() ) } );
534 }
535 case object_type:
536 case array_type:
537 FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to Blob", ("type",get_type()) );
538 default:
539 return blob( { std::vector<char>( (char*)&_data, (char*)&_data + sizeof(_data) ) } );
540 }
541}
const string & get_string() const
Definition variant.cpp:606
blob & get_blob()
Definition variant.cpp:503
type_id get_type() const
Definition variant.cpp:304
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
std::string base64_decode(const std::string &encoded_string)
Definition base64.cpp:152
Here is the call graph for this function:

◆ as_bool()

bool fc::variant::as_bool ( ) const

Definition at line 441 of file variant.cpp.

442{
443 switch( get_type() )
444 {
445 case string_type:
446 {
447 const string& s = **reinterpret_cast<const const_string_ptr*>(this);
448 if( s == "true" )
449 return true;
450 if( s == "false" )
451 return false;
452 FC_THROW_EXCEPTION( bad_cast_exception, "Cannot convert string to bool (only \"true\" or \"false\" can be converted)" );
453 }
454 case double_type:
455 return *reinterpret_cast<const double*>(this) != 0.0;
456 case int64_type:
457 return *reinterpret_cast<const int64_t*>(this) != 0;
458 case uint64_type:
459 return *reinterpret_cast<const uint64_t*>(this) != 0;
460 case bool_type:
461 return *reinterpret_cast<const bool*>(this);
462 case null_type:
463 return false;
464 default:
465 FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to bool" , ("type",get_type()));
466 }
467}
char * s
Here is the call graph for this function:
Here is the caller graph for this function:

◆ as_double()

double fc::variant::as_double ( ) const

Definition at line 420 of file variant.cpp.

421{
422 switch( get_type() )
423 {
424 case string_type:
425 return to_double(**reinterpret_cast<const const_string_ptr*>(this));
426 case double_type:
427 return *reinterpret_cast<const double*>(this);
428 case int64_type:
429 return static_cast<double>(*reinterpret_cast<const int64_t*>(this));
430 case uint64_type:
431 return static_cast<double>(*reinterpret_cast<const uint64_t*>(this));
432 case bool_type:
433 return *reinterpret_cast<const bool*>(this);
434 case null_type:
435 return 0;
436 default:
437 FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to double", ("type",get_type()) );
438 }
439}
double to_double(const fc::string &)
Definition string.cpp:118
Here is the call graph for this function:
Here is the caller graph for this function:

◆ as_int64()

int64_t fc::variant::as_int64 ( ) const

Definition at line 377 of file variant.cpp.

378{
379 switch( get_type() )
380 {
381 case string_type:
382 return to_int64(**reinterpret_cast<const const_string_ptr*>(this));
383 case double_type:
384 return int64_t(*reinterpret_cast<const double*>(this));
385 case int64_type:
386 return *reinterpret_cast<const int64_t*>(this);
387 case uint64_type:
388 return int64_t(*reinterpret_cast<const uint64_t*>(this));
389 case bool_type:
390 return *reinterpret_cast<const bool*>(this);
391 case null_type:
392 return 0;
393 default:
394 FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to int64", ("type", get_type()) );
395 }
396}
int64_t to_int64(const fc::string &)
Definition string.cpp:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

470{
471 switch( get_type() )
472 {
473 case string_type:
474 return **reinterpret_cast<const const_string_ptr*>(this);
475 case double_type:
476 return to_string(*reinterpret_cast<const double*>(this));
477 case int64_type:
478 return to_string(*reinterpret_cast<const int64_t*>(this));
479 case uint64_type:
480 return to_string(*reinterpret_cast<const uint64_t*>(this));
481 case bool_type:
482 return *reinterpret_cast<const bool*>(this) ? "true" : "false";
483 case blob_type:
484 if( get_blob().data.size() )
485 return base64_encode( get_blob().data.data(), get_blob().data.size() ) + "=";
486 return string();
487 case null_type:
488 return string();
489 default:
490 FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to string", ("type", get_type() ) );
491 }
492}
std::string string
Definition string.hpp:10
std::string base64_encode(unsigned char const *bytes_to_encode, unsigned int in_len)
Definition base64.cpp:92
fc::string to_string(double)
Definition string.cpp:131
std::vector< char > data
Definition variant.hpp:44
Here is the call graph for this function:
Here is the caller graph for this function:

◆ as_uint64()

uint64_t fc::variant::as_uint64 ( ) const

Definition at line 398 of file variant.cpp.

399{ try {
400 switch( get_type() )
401 {
402 case string_type:
403 return to_uint64(**reinterpret_cast<const const_string_ptr*>(this));
404 case double_type:
405 return static_cast<uint64_t>(*reinterpret_cast<const double*>(this));
406 case int64_type:
407 return static_cast<uint64_t>(*reinterpret_cast<const int64_t*>(this));
408 case uint64_type:
409 return *reinterpret_cast<const uint64_t*>(this);
410 case bool_type:
411 return static_cast<uint64_t>(*reinterpret_cast<const bool*>(this));
412 case null_type:
413 return 0;
414 default:
415 FC_THROW_EXCEPTION( bad_cast_exception,"Invalid cast from ${type} to uint64", ("type",get_type()));
416 }
417} FC_CAPTURE_AND_RETHROW( (*this) ) }
#define FC_CAPTURE_AND_RETHROW(...)
uint64_t to_uint64(const fc::string &)
Definition string.cpp:105
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

void fc::variant::clear ( )

Definition at line 168 of file variant.cpp.

169{
170 switch( get_type() )
171 {
172 case object_type:
173 delete *reinterpret_cast<variant_object**>(this);
174 break;
175 case array_type:
176 delete *reinterpret_cast<variants**>(this);
177 break;
178 case string_type:
179 delete *reinterpret_cast<string**>(this);
180 break;
181 case blob_type:
182 delete *reinterpret_cast<blob**>(this);
183 break;
184 default:
185 break;
186 }
188}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ estimated_size()

size_t fc::variant::estimated_size ( ) const

Definition at line 575 of file variant.cpp.

576{
577 switch( get_type() )
578 {
579 case null_type:
580 case int64_type:
581 case uint64_type:
582 case double_type:
583 case bool_type:
584 return sizeof(*this);
585 case string_type:
586 return as_string().length() + sizeof(string) + sizeof(*this);
587 case array_type:
588 {
589 const auto& arr = get_array();
590 auto arr_size = arr.size();
591 size_t sum = sizeof(*this) + sizeof(variants);
592 for (size_t iter = 0; iter < arr_size; ++iter) {
593 sum += arr[iter].estimated_size();
594 }
595 return sum;
596 }
597 case object_type:
598 return get_object().estimated_size() + sizeof(*this);
599 case blob_type:
600 return sizeof(blob) + get_blob().data.size() + sizeof(*this);
601 default:
602 FC_THROW_EXCEPTION( assert_exception, "Invalid Type / Corrupted Memory" );
603 }
604}
size_t estimated_size() const
variant_object & get_object()
Definition variant.cpp:554
string as_string() const
Definition variant.cpp:469
variants & get_array()
Definition variant.cpp:496
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_array() [1/2]

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

Definition at line 496 of file variant.cpp.

497{
498 if( get_type() == array_type )
499 return **reinterpret_cast<variants**>(this);
500
501 FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to Array", ("type",get_type()) );
502}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_array() [2/2]

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

Definition at line 545 of file variant.cpp.

546{
547 if( get_type() == array_type )
548 return **reinterpret_cast<const const_variants_ptr*>(this);
549 FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to Array", ("type",get_type()) );
550}
Here is the call graph for this function:

◆ get_blob() [1/2]

blob & fc::variant::get_blob ( )

Definition at line 503 of file variant.cpp.

504{
505 if( get_type() == blob_type )
506 return **reinterpret_cast<blob**>(this);
507
508 FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to Blob", ("type",get_type()) );
509}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_blob() [2/2]

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

Definition at line 510 of file variant.cpp.

511{
512 if( get_type() == blob_type )
513 return **reinterpret_cast<const const_blob_ptr*>(this);
514
515 FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to Blob", ("type",get_type()) );
516}
Here is the call graph for this function:

◆ get_object() [1/2]

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

Definition at line 554 of file variant.cpp.

555{
556 if( get_type() == object_type )
557 return **reinterpret_cast<variant_object**>(this);
558 FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from ${type} to Object", ("type",get_type()) );
559}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_object() [2/2]

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

Definition at line 614 of file variant.cpp.

615{
616 if( get_type() == object_type )
617 return **reinterpret_cast<const const_variant_object_ptr*>(this);
618 FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from type '${type}' to Object", ("type",get_type()) );
619}
Here is the call graph for this function:

◆ get_string()

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

Definition at line 606 of file variant.cpp.

607{
608 if( get_type() == string_type )
609 return **reinterpret_cast<const const_string_ptr*>(this);
610 FC_THROW_EXCEPTION( bad_cast_exception, "Invalid cast from type '${type}' to string", ("type",get_type()) );
611}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_type()

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

Definition at line 304 of file variant.cpp.

305{
306 return (type_id)reinterpret_cast<const char*>(this)[sizeof(*this)-1];
307}
Here is the caller graph for this function:

◆ is_array()

bool fc::variant::is_array ( ) const

Definition at line 368 of file variant.cpp.

369{
370 return get_type() == array_type;
371}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_blob()

bool fc::variant::is_blob ( ) const

Definition at line 372 of file variant.cpp.

373{
374 return get_type() == blob_type;
375}
Here is the call graph for this function:

◆ is_bool()

bool fc::variant::is_bool ( ) const

Definition at line 318 of file variant.cpp.

319{
320 return get_type() == bool_type;
321}
Here is the call graph for this function:

◆ is_double()

bool fc::variant::is_double ( ) const

Definition at line 322 of file variant.cpp.

323{
324 return get_type() == double_type;
325}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_int64()

bool fc::variant::is_int64 ( ) const

Definition at line 330 of file variant.cpp.

331{
332 return get_type() == int64_type;
333}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_integer()

bool fc::variant::is_integer ( ) const

int64, uint64, bool

Definition at line 335 of file variant.cpp.

336{
337 switch( get_type() )
338 {
339 case int64_type:
340 case uint64_type:
341 case bool_type:
342 return true;
343 default:
344 return false;
345 }
346 return false;
347}
Here is the call graph for this function:

◆ is_null()

bool fc::variant::is_null ( ) const

Definition at line 309 of file variant.cpp.

310{
311 return get_type() == null_type;
312}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_numeric()

bool fc::variant::is_numeric ( ) const

int64, uint64, double,bool

Definition at line 348 of file variant.cpp.

349{
350 switch( get_type() )
351 {
352 case int64_type:
353 case uint64_type:
354 case double_type:
355 case bool_type:
356 return true;
357 default:
358 return false;
359 }
360 return false;
361}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_object()

bool fc::variant::is_object ( ) const

Definition at line 363 of file variant.cpp.

364{
365 return get_type() == object_type;
366}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_string()

bool fc::variant::is_string ( ) const

Definition at line 314 of file variant.cpp.

315{
316 return get_type() == string_type;
317}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_uint64()

bool fc::variant::is_uint64 ( ) const

Definition at line 326 of file variant.cpp.

327{
328 return get_type() == uint64_type;
329}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=() [1/3]

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

Definition at line 239 of file variant.cpp.

240{
241 if( this == &v )
242 return *this;
243
244 clear();
245 switch( v.get_type() )
246 {
247 case object_type:
248 *reinterpret_cast<variant_object**>(this) =
249 new variant_object((**reinterpret_cast<const const_variant_object_ptr*>(&v)));
250 break;
251 case array_type:
252 *reinterpret_cast<variants**>(this) =
253 new variants((**reinterpret_cast<const const_variants_ptr*>(&v)));
254 break;
255 case string_type:
256 *reinterpret_cast<string**>(this) = new string((**reinterpret_cast<const const_string_ptr*>(&v)) );
257 break;
258 case blob_type:
259 *reinterpret_cast<blob**>(this) = new blob((**reinterpret_cast<const const_blob_ptr*>(&v)) );
260 break;
261 default:
262 memcpy( this, &v, sizeof(v) );
263 }
264 set_variant_type( this, v.get_type() );
265 return *this;
266}
Here is the call graph for this function:

◆ operator=() [2/3]

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

Definition at line 344 of file variant.hpp.

345 {
346 return *this = variant( fc::forward<T>(v) );
347 }
Here is the call graph for this function:

◆ operator=() [3/3]

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

Definition at line 230 of file variant.cpp.

231{
232 if( this == &v ) return *this;
233 clear();
234 memcpy( (char*)this, (char*)&v, sizeof(v) );
236 return *this;
237}
Here is the call graph for this function:

◆ operator[]() [1/2]

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

Definition at line 561 of file variant.cpp.

562{
563 return get_object()[key];
564}
uint8_t key[16]
Definition yubico_otp.c:41
Here is the call graph for this function:

◆ operator[]() [2/2]

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

Definition at line 565 of file variant.cpp.

566{
567 return get_array()[pos];
568}
Here is the call graph for this function:

◆ size()

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

Definition at line 570 of file variant.cpp.

571{
572 return get_array().size();
573}
Here is the call graph for this function:

◆ visit()

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

Definition at line 268 of file variant.cpp.

269{
270 switch( get_type() )
271 {
272 case null_type:
273 v.handle();
274 return;
275 case int64_type:
276 v.handle( *reinterpret_cast<const int64_t*>(this) );
277 return;
278 case uint64_type:
279 v.handle( *reinterpret_cast<const uint64_t*>(this) );
280 return;
281 case double_type:
282 v.handle( *reinterpret_cast<const double*>(this) );
283 return;
284 case bool_type:
285 v.handle( *reinterpret_cast<const bool*>(this) );
286 return;
287 case string_type:
288 v.handle( **reinterpret_cast<const const_string_ptr*>(this) );
289 return;
290 case array_type:
291 v.handle( **reinterpret_cast<const const_variants_ptr*>(this) );
292 return;
293 case object_type:
294 v.handle( **reinterpret_cast<const const_variant_object_ptr*>(this) );
295 return;
296 case blob_type:
297 v.handle( **reinterpret_cast<const const_blob_ptr*>(this) );
298 return;
299 default:
300 FC_THROW_EXCEPTION( assert_exception, "Invalid Type / Corrupted Memory" );
301 }
302}
Here is the call graph for this function:
Here is the caller graph for this function:

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