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);
210 *
reinterpret_cast<variants**
>(
this) =
215 *
reinterpret_cast<string**
>(
this) =
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) );
257 *
reinterpret_cast<variants**
>(
this) =
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) );
306 return (
type_id)
reinterpret_cast<const char*
>(
this)[
sizeof(*
this)-1];
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);
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));
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);
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);
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);
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) ) } );
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__)
705 void to_variant(
size_t s, variant& v, uint32_t max_depth ) { v = variant( uint64_t(s) ); }
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) );