9 #include <unordered_map> 10 #include <unordered_set> 19 #include <boost/endian/buffers.hpp> 20 #include <boost/multi_index_container_fwd.hpp> 23 #define _FC_ASSERT(...) FC_ASSERT( __VA_ARGS__ ) 30 #define _FC_ASSERT( cond, msg ) { if( !(cond) ) { char t[] = #cond ": " msg; fc::throw_assertion_failure( t ); } } 50 class mutable_variant_object;
54 template<
typename T>
struct safe;
55 template<
typename... Types>
64 template<
typename T,
typename... Args>
void to_variant(
const boost::multi_index_container<T,Args...>& s,
variant& v, uint32_t max_depth );
65 template<
typename T,
typename... Args>
void from_variant(
const variant& v, boost::multi_index_container<T,Args...>& s, uint32_t max_depth );
69 template<
typename T>
void to_variant(
const std::unique_ptr<T>& s,
variant& v, uint32_t max_depth );
70 template<
typename T>
void from_variant(
const variant& v, std::unique_ptr<T>& s, uint32_t max_depth );
101 void to_variant(
const std::vector<char>& var,
variant& vo, uint32_t max_depth = 1 );
104 template<
typename K,
typename T>
105 void to_variant(
const std::unordered_map<K,T>& var,
variant& vo, uint32_t max_depth );
106 template<
typename K,
typename T>
109 template<
typename K,
typename... T>
110 void to_variant(
const fc::flat_map<K,T...>& var,
variant& vo, uint32_t max_depth );
111 template<
typename K,
typename T,
typename... A>
114 template<
typename K,
typename T>
116 template<
typename K,
typename T>
118 template<
typename K,
typename T>
119 void to_variant(
const std::multimap<K,T>& var,
variant& vo, uint32_t max_depth );
120 template<
typename K,
typename T>
125 void to_variant(
const std::unordered_set<T>& var,
variant& vo, uint32_t max_depth );
134 template<
typename T,
typename... A>
135 void to_variant(
const fc::flat_set<T, A...>& var,
variant& vo, uint32_t max_depth );
136 template<
typename T,
typename... A>
156 #if defined(__APPLE__) or defined(__OpenBSD__) 158 #elif !defined(_WIN32) 165 void to_variant(
const std::shared_ptr<T>& var,
variant& vo, uint32_t max_depth );
171 template<
typename A,
typename B>
173 template<
typename A,
typename B>
176 template<boost::endian::order O,
class T, std::
size_t N, boost::endian::align A>
177 void to_variant(
const boost::endian::endian_buffer<O,T,N,A>& var,
variant& vo, uint32_t max_depth )
181 template<boost::endian::order O,
class T, std::
size_t N, boost::endian::align A>
217 variant( std::nullptr_t, uint32_t max_depth = 1 );
221 variant(
const char* str, uint32_t max_depth = 1 );
222 variant(
char* str, uint32_t max_depth = 1 );
223 variant(
wchar_t* str, uint32_t max_depth = 1 );
224 variant(
const wchar_t* str, uint32_t max_depth = 1 );
225 variant(
float val, uint32_t max_depth = 1 );
226 variant( uint8_t val, uint32_t max_depth = 1 );
227 variant( int8_t val, uint32_t max_depth = 1 );
228 variant( uint16_t val, uint32_t max_depth = 1 );
229 variant( int16_t val, uint32_t max_depth = 1 );
230 variant( uint32_t val, uint32_t max_depth = 1 );
231 variant( int32_t val, uint32_t max_depth = 1 );
232 variant( uint64_t val, uint32_t max_depth = 1 );
233 #if defined(__APPLE__) or defined(__OpenBSD__) 234 variant(
size_t val, uint32_t max_depth = 1 );
236 variant( int64_t val, uint32_t max_depth = 1 );
237 variant(
double val, uint32_t max_depth = 1 );
238 variant(
bool val, uint32_t max_depth = 1 );
240 variant( std::string val, uint32_t max_depth = 1 );
243 variant( variants, uint32_t max_depth = 1 );
256 virtual void handle()
const = 0;
257 virtual void handle(
const int64_t& v )
const = 0;
258 virtual void handle(
const uint64_t& v )
const = 0;
259 virtual void handle(
const double& v )
const = 0;
260 virtual void handle(
const bool& v )
const = 0;
261 virtual void handle(
const std::string& v )
const = 0;
263 virtual void handle(
const variants& v)
const = 0;
266 void visit(
const visitor& v )
const;
271 bool is_string()
const;
273 bool is_int64()
const;
274 bool is_uint64()
const;
275 bool is_double()
const;
276 bool is_object()
const;
277 bool is_array()
const;
282 bool is_numeric()
const;
286 bool is_integer()
const;
288 int64_t as_int64()
const;
289 uint64_t as_uint64()
const;
291 double as_double()
const;
294 const blob& get_blob()
const;
300 std::string as_string()
const;
303 const std::string& get_string()
const;
306 variants& get_array();
309 const variants& get_array()
const;
318 const variant& operator[](
const char* )
const;
320 const variant& operator[](
size_t pos )
const;
337 T
as( uint32_t max_depth )
const 345 void as( T& v, uint32_t max_depth )
const 356 return *
this =
variant( std::forward<T>(v) );
362 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
363 memset(
this, 0,
sizeof(*
this) );
368 variant(
const T& val, uint32_t max_depth );
375 char _type[
sizeof(
void*)];
401 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
409 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
410 std::vector<variant> vars(var.size());
412 for(
const auto& item : var )
413 vars[i++] =
variant( item, max_depth - 1 );
419 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
422 vo.reserve( vars.size() );
423 for(
const auto& item : vars )
424 vo.insert( item.as<T>( max_depth - 1 ) );
428 template<
typename K,
typename T>
431 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
432 std::vector< variant > vars(var.size());
434 for(
const auto& key_value : var )
435 vars[i++] =
fc::variant( key_value, max_depth - 1 );
438 template<
typename K,
typename T>
441 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
444 vo.reserve( vars.size() );
445 for(
const auto& item : vars )
446 vo.insert( item.as< std::pair<K,T> >( max_depth - 1 ) );
448 template<
typename K,
typename T>
451 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
452 std::vector< variant > vars(var.size());
454 for(
const auto& key_value : var )
455 vars[i++] =
fc::variant( key_value, max_depth - 1 );
458 template<
typename K,
typename T>
461 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
464 for(
auto item : vars )
465 vo.insert( item.as< std::pair<K,T> >( max_depth - 1 ) );
468 template<
typename K,
typename T>
471 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
472 std::vector< variant > vars(var.size());
474 for(
const auto& key_value : var )
475 vars[i++] =
fc::variant( key_value, max_depth - 1 );
478 template<
typename K,
typename T>
481 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
484 for(
auto item : vars )
485 vo.insert( item.as< std::pair<K,T> >( max_depth - 1 ) );
492 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
493 std::vector<variant> vars(var.size());
495 for(
const auto& item : var )
502 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
505 for(
const auto& item : vars )
506 vo.insert( item.as<T>( max_depth - 1 ) );
513 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
516 dest.resize( vars.size() );
517 for(
const auto& item : vars )
518 dest.push_back( item.as<T>( max_depth - 1 ) );
525 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
526 std::vector<variant> vars(src.size());
527 for(
size_t i = 0; i < src.size(); ++i )
528 vars[i] =
variant( src[i], max_depth - 1 );
537 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
540 dest.reserve( vars.size() );
541 for(
const auto& item : vars )
542 dest.push_back( item.as<T>( max_depth - 1 ) );
549 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
550 std::vector<variant> vars(t.size());
551 for(
size_t i = 0; i < t.size(); ++i )
552 vars[i] =
variant( t[i], max_depth - 1 );
558 template<
typename A,
typename B>
561 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
562 std::vector<variant> vars(2);
563 vars[0] =
variant( t.first, max_depth - 1 );
564 vars[1] =
variant( t.second, max_depth - 1 );
567 template<
typename A,
typename B>
570 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
572 if( vars.size() > 0 )
573 p.first = vars[0].as<A>( max_depth - 1 );
574 if( vars.size() > 1 )
575 p.second = vars[1].as<B>( max_depth - 1 );
582 memset(
this, 0,
sizeof(*
this) );
591 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
600 if( var.
is_null() ) vo =
nullptr;
603 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
604 if( !vo ) vo = std::make_shared<T>();
613 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
622 if( var.
is_null() ) vo.reset();
625 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
626 if( !vo ) vo.reset(
new T() );
639 s.
value = v.
as<T>( max_depth );
642 template<
typename T,
typename... Args>
643 void to_variant(
const boost::multi_index_container<T,Args...>& c,
variant& v, uint32_t max_depth )
645 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
646 std::vector<variant> vars;
647 vars.reserve( c.size() );
648 for(
const auto& item : c )
649 vars.emplace_back(
variant( item, max_depth - 1 ) );
653 template<
typename T,
typename... Args>
656 _FC_ASSERT( max_depth > 0,
"Recursion depth exceeded!" );
659 for(
const auto& item : vars )
660 c.insert( item.as<T>( max_depth - 1 ) );
673 from_hex( ve, bi.data(), std::min<size_t>( ve.size() / 2, bi.size() ) );
675 memset( bi.data(), 0, bi.size() );
688 from_hex( ve, (
char*)bi.data(), std::min<size_t>( ve.size() / 2, bi.size() ) );
690 memset( bi.data(), 0, bi.size() );
variant(const optional< T > &v, uint32_t max_depth)
T as(uint32_t max_depth) const
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
optional< variant > ovariant
An order-perserving dictionary of variant's.
Defines types and macros used to provide reflection.
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)
void throw_assertion_failure(const std::string &message)
variant & operator=(T &&v)
variant()
Constructs a null_type variant.
bool operator!=(const optional< T > &left, const optional< T > &right)
provides stack-based nullable value similar to boost::optional
FC_REFLECT_TYPENAME(fc::log_message)
FC_REFLECT_ENUM(graphene::net::core_message_type_enum,(trx_message_type)(block_message_type)(core_message_type_first)(item_ids_inventory_message_type)(blockchain_item_ids_inventory_message_type)(fetch_blockchain_item_ids_message_type)(fetch_items_message_type)(item_not_available_message_type)(hello_message_type)(connection_accepted_message_type)(connection_rejected_message_type)(address_request_message_type)(address_message_type)(closing_connection_message_type)(current_time_request_message_type)(current_time_reply_message_type)(check_firewall_message_type)(check_firewall_reply_message_type)(get_current_connections_request_message_type)(get_current_connections_reply_message_type)(core_message_type_last))(different_chain)(already_connected)(connected_to_self)(not_accepting_connections)(blocked)(invalid_hello_message)(client_too_old))(inbound)(outbound))(firewalled)(not_firewalled))(unable_to_connect)(connection_successful)) namespace std
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)
auto operator-(const fwd< T, S, A > &x, U &&u) -> typename detail::sub< T, U >::type
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
variant operator/(const variant &a, const variant &b)
bool operator>(const variant &a, const variant &b)
#define _FC_ASSERT(cond, msg)
void from_variant(const variant &var, flat_set< T, A... > &vo, uint32_t _max_depth)
defines wrappers for boost::asio functions
bool operator<(const variant &a, const variant &b)
void as(T &v, uint32_t max_depth) const
std::string to_hex(const char *d, uint32_t s)
variant operator*(const variant &a, const variant &b)
std::string as_string() const
An order-perserving dictionary of variant's.