10 #include <boost/scoped_array.hpp> 14 #if defined(__APPLE__) or defined(__OpenBSD__) 15 #include <boost/multiprecision/integer.hpp> 26 char* data =
reinterpret_cast<char*
>(v);
42 *
reinterpret_cast<uint64_t*
>(
this) = val;
48 *
reinterpret_cast<int64_t*
>(
this) = val;
54 *
reinterpret_cast<uint64_t*
>(
this) = val;
60 *
reinterpret_cast<int64_t*
>(
this) = val;
66 *
reinterpret_cast<uint64_t*
>(
this) = val;
72 *
reinterpret_cast<int64_t*
>(
this) = val;
78 *
reinterpret_cast<uint64_t*
>(
this) = val;
82 #if defined(__APPLE__) or defined(__OpenBSD__) 85 *
reinterpret_cast<uint64_t*
>(
this) = val;
92 *
reinterpret_cast<int64_t*
>(
this) = val;
98 *
reinterpret_cast<double*
>(
this) = val;
104 *
reinterpret_cast<double*
>(
this) = val;
110 *
reinterpret_cast<bool*
>(
this) = val;
116 *
reinterpret_cast<string**
>(
this) =
new string( str );
122 *
reinterpret_cast<string**
>(
this) =
new string( str );
129 size_t len = wcslen(str);
130 boost::scoped_array<char> buffer(
new char[len]);
131 for (
unsigned i = 0; i < len; ++i)
132 buffer[i] = (
char)str[i];
133 *
reinterpret_cast<string**
>(
this) =
new string(buffer.get(), len);
140 size_t len = wcslen(str);
141 boost::scoped_array<char> buffer(
new char[len]);
142 for (
unsigned i = 0; i < len; ++i)
143 buffer[i] = (
char)str[i];
144 *
reinterpret_cast<string**
>(
this) =
new string(buffer.get(), len);
150 *
reinterpret_cast<string**
>(
this) =
new string( std::move(val) );
155 *
reinterpret_cast<blob**
>(
this) =
new blob( std::move(val) );
189 delete *
reinterpret_cast<variants**
>(
this);
192 delete *
reinterpret_cast<string**
>(
this);
206 new variant_object(**reinterpret_cast<const const_variant_object_ptr*>(&v));
210 *
reinterpret_cast<variants**
>(
this) =
211 new variants(**reinterpret_cast<const const_variants_ptr*>(&v));
215 *
reinterpret_cast<string**
>(
this) =
216 new string(**reinterpret_cast<const const_string_ptr*>(&v) );
220 memcpy(
this, &v,
sizeof(v) );
226 memcpy(
this, &v,
sizeof(v) );
237 if(
this == &v )
return *
this;
239 memcpy( (
char*)
this, (
char*)&v,
sizeof(v) );
254 new variant_object((**reinterpret_cast<const const_variant_object_ptr*>(&v)));
257 *
reinterpret_cast<variants**
>(
this) =
258 new variants((**reinterpret_cast<const const_variants_ptr*>(&v)));
261 *
reinterpret_cast<string**
>(
this) =
new string((**reinterpret_cast<const const_string_ptr*>(&v)) );
265 memcpy(
this, &v,
sizeof(v) );
279 v.
handle( *reinterpret_cast<const int64_t*>(
this) );
282 v.
handle( *reinterpret_cast<const uint64_t*>(
this) );
285 v.
handle( *reinterpret_cast<const double*>(
this) );
288 v.
handle( *reinterpret_cast<const bool*>(
this) );
291 v.
handle( **reinterpret_cast<const const_string_ptr*>(
this) );
294 v.
handle( **reinterpret_cast<const const_variants_ptr*>(
this) );
297 v.
handle( **reinterpret_cast<const const_variant_object_ptr*>(
this) );
306 return (
type_id)
reinterpret_cast<const char*
>(
this)[
sizeof(*
this)-1];
382 return to_int64(**reinterpret_cast<const const_string_ptr*>(
this));
384 return int64_t(*reinterpret_cast<const double*>(
this));
386 return *
reinterpret_cast<const int64_t*
>(
this);
388 return int64_t(*reinterpret_cast<const uint64_t*>(
this));
390 return *
reinterpret_cast<const bool*
>(
this);
403 return to_uint64(**reinterpret_cast<const const_string_ptr*>(
this));
405 return static_cast<uint64_t
>(*
reinterpret_cast<const double*
>(
this));
407 return static_cast<uint64_t
>(*
reinterpret_cast<const int64_t*
>(
this));
409 return *
reinterpret_cast<const uint64_t*
>(
this);
411 return static_cast<uint64_t
>(*
reinterpret_cast<const bool*
>(
this));
425 return to_double(**reinterpret_cast<const const_string_ptr*>(
this));
427 return *
reinterpret_cast<const double*
>(
this);
429 return static_cast<double>(*
reinterpret_cast<const int64_t*
>(
this));
431 return static_cast<double>(*
reinterpret_cast<const uint64_t*
>(
this));
433 return *
reinterpret_cast<const bool*
>(
this);
447 const string& s = **
reinterpret_cast<const const_string_ptr*
>(
this);
452 FC_THROW_EXCEPTION( bad_cast_exception,
"Cannot convert string to bool (only \"true\" or \"false\" can be converted)" );
455 return *
reinterpret_cast<const double*
>(
this) != 0.0;
457 return *
reinterpret_cast<const int64_t*
>(
this) != 0;
459 return *
reinterpret_cast<const uint64_t*
>(
this) != 0;
461 return *
reinterpret_cast<const bool*
>(
this);
474 return **
reinterpret_cast<const const_string_ptr*
>(
this);
476 return to_string(*reinterpret_cast<const double*>(
this));
478 return to_string(*reinterpret_cast<const int64_t*>(
this));
480 return to_string(*reinterpret_cast<const uint64_t*>(
this));
482 return *
reinterpret_cast<const bool*
>(
this) ?
"true" :
"false";
499 return **
reinterpret_cast<variants**
>(
this);
506 return **
reinterpret_cast<blob**
>(
this);
513 return **
reinterpret_cast<const const_blob_ptr*
>(
this);
527 if( str.size() == 0 )
return blob();
528 if( str.back() ==
'=' )
531 return blob( { std::vector<char>( b64.begin(), b64.end() ) } );
533 return blob( { std::vector<char>( str.begin(), str.end() ) } );
539 return blob( { std::vector<char>( (
char*)&_data, (
char*)&_data +
sizeof(_data) ) } );
548 return **
reinterpret_cast<const const_variants_ptr*
>(
this);
578 return **
reinterpret_cast<const const_string_ptr*
>(
this);
586 return **
reinterpret_cast<const const_variant_object_ptr*
>(
this);
616 vo =
static_cast<uint32_t
>(var.
as_uint64());
622 vo =
static_cast<int32_t
>(var.
as_int64());
650 vo =
static_cast<float>(var.
as_double());
655 v =
variant( std::string(s), max_depth );
672 vo.resize( str.size() / 2 );
675 size_t r =
from_hex( str, vo.data(), vo.size() );
682 #if defined(__APPLE__) or defined(__OpenBSD__) 683 boost::multiprecision::uint128_t helper =
uint128_hi64( var );
686 vo = boost::lexical_cast<std::string>( helper );
688 vo = boost::lexical_cast<std::string>( var );
694 #if defined(__APPLE__) or defined(__OpenBSD__) 695 boost::multiprecision::uint128_t helper = boost::lexical_cast<boost::multiprecision::uint128_t>( var.
as_string() );
696 vo =
static_cast<uint64_t
>( helper >> 64 );
698 vo +=
static_cast<uint64_t
>( helper & 0xffffffffffffffffULL );
700 vo = boost::lexical_cast<uint128_t>( var.
as_string() );
704 #if defined(__APPLE__) or defined(__OpenBSD__) 706 #elif !defined(_WIN32) 769 result.reserve( std::max(aa.size(),ba.size()) );
770 auto num = std::max(aa.size(),ba.size());
771 for(
unsigned i = 0; i < num; ++i )
773 if( aa.size() > i && ba.size() > i )
774 result[i] = aa[i] + ba[i];
775 else if( aa.size() > i )
786 FC_ASSERT(
false,
"invalid operation ${a} + ${b}", (
"a",a)(
"b",b) );
796 result.reserve( std::max(aa.size(),ba.size()) );
797 auto num = std::max(aa.size(),ba.size());
798 for(
unsigned i = 0; i < num; --i )
800 if( aa.size() > i && ba.size() > i )
801 result[i] = aa[i] - ba[i];
802 else if( aa.size() > i )
813 FC_ASSERT(
false,
"invalid operation ${a} + ${b}", (
"a",a)(
"b",b) );
825 result.reserve( std::max(aa.size(),ba.size()) );
826 auto num = std::max(aa.size(),ba.size());
827 for(
unsigned i = 0; i < num; ++i )
829 if( aa.size() > i && ba.size() > i )
830 result[i] = aa[i] * ba[i];
831 else if( aa.size() > i )
838 FC_ASSERT(
false,
"invalid operation ${a} * ${b}", (
"a",a)(
"b",b) );
850 result.reserve( std::max(aa.size(),ba.size()) );
851 auto num = std::max(aa.size(),ba.size());
852 for(
unsigned i = 0; i < num; ++i )
854 if( aa.size() > i && ba.size() > i )
855 result[i] = aa[i] / ba[i];
856 else if( aa.size() > i )
863 FC_ASSERT(
false,
"invalid operation ${a} / ${b}", (
"a",a)(
"b",b) );
const variants * const_variants_ptr
bool operator<=(const variant &a, const variant &b)
An order-perserving dictionary of variant's.
std::vector< variant > variants
auto operator+(const fwd< T, S, A > &x, U &&u) -> typename detail::add< T, U >::type
bool operator!(const variant &a)
uint64_t as_uint64() const
const variant_object * const_variant_object_ptr
int64_t to_int64(const std::string &)
std::string base64_encode(unsigned char const *bytes_to_encode, unsigned int in_len)
uint64_t uint128_hi64(const uint128_t &x)
variant()
Constructs a null_type variant.
bool operator!=(const optional< T > &left, const optional< T > &right)
virtual void handle() const =0
handles null_type variants
variant_object & get_object()
bool operator==(const optional< T > &left, const optional< T > &right)
void to_variant(const flat_set< T, A... > &var, variant &vo, uint32_t _max_depth)
variant & operator=(variant &&v)
double to_double(const std::string &)
auto operator-(const fwd< T, S, A > &x, U &&u) -> typename detail::sub< T, U >::type
const variant & operator[](const char *) const
#define FC_CAPTURE_AND_RETHROW(...)
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
uint64_t to_uint64(const std::string &)
variant operator/(const variant &a, const variant &b)
Defines exception's used by fc.
bool operator>(const variant &a, const variant &b)
void visit(const visitor &v) const
void from_variant(const variant &var, flat_set< T, A... > &vo, uint32_t _max_depth)
const string * const_string_ptr
std::string to_string(double)
uint64_t uint128_lo64(const uint128_t &x)
std::string base64_decode(const std::string &encoded_string)
bool operator<(const variant &a, const variant &b)
const std::string & get_string() const
std::string to_hex(const char *d, uint32_t s)
variant operator*(const variant &a, const variant &b)
const blob * const_blob_ptr
An order-perserving dictionary of variant's.
std::string as_string() const
void set_variant_type(variant *v, variant::type_id t)