7#include <boost/scoped_array.hpp>
20 char* data =
reinterpret_cast<char*
>(v);
36 *
reinterpret_cast<uint64_t*
>(
this) = val;
42 *
reinterpret_cast<int64_t*
>(
this) = val;
48 *
reinterpret_cast<uint64_t*
>(
this) = val;
54 *
reinterpret_cast<int64_t*
>(
this) = val;
60 *
reinterpret_cast<uint64_t*
>(
this) = val;
66 *
reinterpret_cast<int64_t*
>(
this) = val;
72 *
reinterpret_cast<uint64_t*
>(
this) = val;
78 *
reinterpret_cast<int64_t*
>(
this) = val;
84 *
reinterpret_cast<double*
>(
this) = val;
90 *
reinterpret_cast<double*
>(
this) = val;
96 *
reinterpret_cast<bool*
>(
this) = val;
102 *
reinterpret_cast<string**
>(
this) =
new string( str );
108 *
reinterpret_cast<string**
>(
this) =
new string( str );
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);
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);
136 *
reinterpret_cast<string**
>(
this) =
new string( fc::move(val) );
141 *
reinterpret_cast<blob**
>(
this) =
new blob( fc::move(val) );
176 delete *
reinterpret_cast<variants**
>(
this);
179 delete *
reinterpret_cast<string**
>(
this);
182 delete *
reinterpret_cast<blob**
>(
this);
200 *
reinterpret_cast<variants**
>(
this) =
205 *
reinterpret_cast<string**
>(
this) =
210 *
reinterpret_cast<blob**
>(
this) =
215 memcpy(
this, &v,
sizeof(v) );
221 memcpy(
this, &v,
sizeof(v) );
232 if(
this == &v )
return *
this;
234 memcpy( (
char*)
this, (
char*)&v,
sizeof(v) );
252 *
reinterpret_cast<variants**
>(
this) =
256 *
reinterpret_cast<string**
>(
this) =
new string((**
reinterpret_cast<const const_string_ptr*
>(&v)) );
262 memcpy(
this, &v,
sizeof(v) );
282 v.
handle( *
reinterpret_cast<const double*
>(
this) );
285 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);
390 return *
reinterpret_cast<const bool*
>(
this);
405 return static_cast<uint64_t>(*
reinterpret_cast<const double*
>(
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));
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) ) } );
584 return sizeof(*this);
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();
665 vo = boost::multiprecision::uint128_t( var ).str();
673 vo =
static_cast<unsigned __int128
>( boost::multiprecision::uint128_t(var.
as_string()) );
675 FC_THROW_EXCEPTION( bad_cast_exception,
"Cannot convert variant of type '${type}' into a uint128_t", (
"type", var.
get_type()) );
680 vo = boost::multiprecision::int128_t( var ).str();
688 vo =
static_cast<__int128
>( boost::multiprecision::int128_t(var.
as_string()) );
690 FC_THROW_EXCEPTION( bad_cast_exception,
"Cannot convert variant of type '${type}' into a int128_t", (
"type", var.
get_type()) );
716 vo =
static_cast<float>(var.
as_double());
740 FC_ASSERT( str.size() % 2 == 0,
"the length of hex string should be even number" );
741 vo.resize( str.size() / 2 );
743 size_t r =
from_hex( str, vo.data(), vo.size() );
766void clean_append(
string& app,
const std::string_view&
s,
size_t pos = 0,
size_t len = string::npos ) {
767 std::string_view
sub =
s.substr( pos,
len );
768 app.reserve( app.size() +
sub.size() );
769 const bool escape_control_chars =
false;
779 const auto arg_num = (args.
size() == 0) ? 1 : args.
size();
782 const auto minimize_sub_max_size = minimize ? ( max_format_size -
format.size() ) / arg_num :
minimize_max_size;
784 result.reserve( max_format_size + 3 * args.
size());
786 size_t next =
format.find(
'$' );
787 while( prev != string::npos && prev <
format.size() ) {
788 if( next != string::npos ) {
795 if( next == string::npos ) {
805 if(
format[prev] ==
'{' ) {
807 next =
format.find(
'}', prev );
809 if( next != string::npos ) {
811 string key =
format.substr( prev + 1, (next - prev - 1) );
813 auto val = args.
find( key );
814 bool replaced =
true;
815 if( val != args.
end() ) {
816 if( val->value().is_object() || val->value().is_array() ) {
820 const auto max_length = minimize ? minimize_sub_max_size : std::numeric_limits<uint64_t>::max();
829 }
else if( val->value().is_blob() ) {
830 if( minimize && val->value().get_blob().data.size() > minimize_sub_max_size ) {
835 }
else if( val->value().is_string() ) {
836 if( minimize && val->value().get_string().size() > minimize_sub_max_size ) {
838 clean_append( result, val->value().get_string(), 0, sz );
856 next =
format.find(
'$', prev );
863 next =
format.find(
'$', prev );
870 #elif !defined(_MSC_VER)
930 result.reserve( std::max(aa.size(),ba.size()) );
931 auto num = std::max(aa.size(),ba.size());
932 for(
unsigned i = 0; i < num; ++i )
934 if( aa.size() > i && ba.size() > i )
935 result[i] = aa[i] + ba[i];
936 else if( aa.size() > i )
947 FC_ASSERT(
false,
"invalid operation ${a} + ${b}", (
"a",
a)(
"b",b) );
957 result.reserve( std::max(aa.size(),ba.size()) );
958 auto num = std::max(aa.size(),ba.size());
959 for(
unsigned i = 0; i < num; --i )
961 if( aa.size() > i && ba.size() > i )
962 result[i] = aa[i] - ba[i];
963 else if( aa.size() > i )
974 FC_ASSERT(
false,
"invalid operation ${a} + ${b}", (
"a",
a)(
"b",b) );
986 result.reserve( std::max(aa.size(),ba.size()) );
987 auto num = std::max(aa.size(),ba.size());
988 for(
unsigned i = 0; i < num; ++i )
990 if( aa.size() > i && ba.size() > i )
991 result[i] = aa[i] * ba[i];
992 else if( aa.size() > i )
999 FC_ASSERT(
false,
"invalid operation ${a} * ${b}", (
"a",
a)(
"b",b) );
1011 result.reserve( std::max(aa.size(),ba.size()) );
1012 auto num = std::max(aa.size(),ba.size());
1013 for(
unsigned i = 0; i < num; ++i )
1015 if( aa.size() > i && ba.size() > i )
1016 result[i] = aa[i] / ba[i];
1017 else if( aa.size() > i )
1024 FC_ASSERT(
false,
"invalid operation ${a} / ${b}", (
"a",
a)(
"b",b) );
static string to_string(const variant &v, const yield_function_t &yield, const output_formatting format=output_formatting::stringify_large_ints_and_doubles)
@ stringify_large_ints_and_doubles
An order-preserving dictionary of variants.
static constexpr time_point maximum()
virtual void handle() const =0
handles null_type variants
An order-preserving dictionary of variants.
size_t estimated_size() const
iterator find(const string &key) const
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
variant & operator=(variant &&v)
variant_object & get_object()
const string & get_string() const
void visit(const visitor &v) const
uint64_t as_uint64() const
variant()
Constructs a null_type variant.
size_t estimated_size() const
const variant & operator[](const char *) const
Defines exception's used by fc.
#define FC_CAPTURE_AND_RETHROW(...)
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
void set_variant_type(variant *v, variant::type_id t)
bool operator<(const array< T, N > &a, const array< T, N > &b)
const variant_object * const_variant_object_ptr
auto operator+(const fwd< T, S, A > &x, U &&u) -> typename detail::add< T, U >::type
auto operator-(const fwd< T, S, A > &x, U &&u) -> typename detail::sub< T, U >::type
std::string base64_encode(unsigned char const *bytes_to_encode, unsigned int in_len)
const string * const_string_ptr
bool operator!(const fc::variant &a)
bool operator<=(const variant &a, const variant &b)
bool operator>(const array< T, N > &a, const array< T, N > &b)
fc::string to_string(double)
void clean_append(string &app, const std::string_view &s, size_t pos=0, size_t len=string::npos)
bool operator!=(const array< T, N > &a, const array< T, N > &b)
bool operator==(const array< T, N > &a, const array< T, N > &b)
std::vector< fc::variant > variants
constexpr size_t minimize_max_size
fc::variant operator*(const fc::variant &a, const fc::variant &b)
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< Size, Size, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void > > UInt
fc::string to_hex(const char *d, uint32_t s)
const variants * const_variants_ptr
double to_double(const fc::string &)
uint64_t to_uint64(const fc::string &)
fc::variant operator/(const fc::variant &a, const fc::variant &b)
void from_variant(const fc::variant &v, sysio::chain::chain_id_type &cid)
fc::string format_string(const fc::string &, const variant_object &, bool minimize=false)
const blob * const_blob_ptr
void to_variant(const sysio::chain::shared_public_key &var, fc::variant &vo)
std::string base64_decode(const std::string &encoded_string)
std::string escape_string(const std::string_view &str, const json::yield_function_t &yield, bool escape_control_chars=true)
decltype(nullptr) nullptr_t
int64_t to_int64(const fc::string &)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
unsigned __int64 uint64_t
#define MAX_SIZE_OF_BYTE_ARRAYS
void sub(const Operand &op, uint32 imm)
memcpy((char *) pInfo->slotDescription, s, l)