BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
variant.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <array>
4 #include <cstddef>
5 #include <deque>
6 #include <map>
7 #include <memory>
8 #include <set>
9 #include <unordered_map>
10 #include <unordered_set>
11 #include <vector>
12 
13 #include <string.h> // memset
14 
15 #include <fc/optional.hpp>
16 #include <fc/uint128.hpp>
18 #include <fc/crypto/hex.hpp>
19 #include <boost/endian/buffers.hpp>
20 #include <boost/multi_index_container_fwd.hpp>
21 
22 #ifdef FC_ASSERT
23 #define _FC_ASSERT(...) FC_ASSERT( __VA_ARGS__ )
24 #else
25 // poor man's FC_ASSERT, want to avoid recursive inclusion of exception.hpp
26 namespace fc
27 {
28 void throw_assertion_failure( const std::string& message );
29 }
30 #define _FC_ASSERT( cond, msg ) { if( !(cond) ) { char t[] = #cond ": " msg; fc::throw_assertion_failure( t ); } }
31 #endif
32 
33 namespace fc
34 {
48  class variant;
49  class variant_object;
50  class mutable_variant_object;
51  class time_point;
52  class time_point_sec;
53  class microseconds;
54  template<typename T> struct safe;
55  template<typename... Types>
56  class static_variant;
57 
58  struct blob { std::vector<char> data; };
59 
60  void to_variant( const blob& var, variant& vo, uint32_t max_depth = 1);
61  void from_variant( const variant& var, blob& vo, uint32_t max_depth = 1 );
62 
63 
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 );
66 
67  template<typename T> void to_variant( const safe<T>& s, variant& v, uint32_t max_depth );
68  template<typename T> void from_variant( const variant& v, safe<T>& 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 );
71 
72  template<typename... T> void to_variant( const static_variant<T...>& s, variant& v, uint32_t max_depth );
73  template<typename... T> void from_variant( const variant& v, static_variant<T...>& s, uint32_t max_depth );
74 
75  void to_variant( const uint8_t& var, variant& vo, uint32_t max_depth = 1 );
76  void from_variant( const variant& var, uint8_t& vo, uint32_t max_depth = 1 );
77  void to_variant( const int8_t& var, variant& vo, uint32_t max_depth = 1 );
78  void from_variant( const variant& var, int8_t& vo, uint32_t max_depth = 1 );
79 
80  void to_variant( const uint16_t& var, variant& vo, uint32_t max_depth = 1 );
81  void from_variant( const variant& var, uint16_t& vo, uint32_t max_depth = 1 );
82  void to_variant( const int16_t& var, variant& vo, uint32_t max_depth = 1 );
83  void from_variant( const variant& var, int16_t& vo, uint32_t max_depth = 1 );
84 
85  void to_variant( const uint32_t& var, variant& vo, uint32_t max_depth = 1 );
87  void from_variant( const variant& var, uint32_t& vo, uint32_t max_depth = 1 );
88  void to_variant( const int32_t& var, variant& vo, uint32_t max_depth = 1 );
90  void from_variant( const variant& var, int32_t& vo, uint32_t max_depth = 1 );
91 
92  void to_variant( const uint64_t& var, variant& vo, uint32_t max_depth = 1 );
93  void to_variant( const int64_t& var, variant& vo, uint32_t max_depth = 1 );
94 
95  void to_variant( const bool& var, variant& vo, uint32_t max_depth = 1 );
96 
97  void to_variant( const variant_object& var, variant& vo, uint32_t max_depth );
98  void from_variant( const variant& var, variant_object& vo, uint32_t max_depth );
99  void to_variant( const mutable_variant_object& var, variant& vo, uint32_t max_depth );
100  void from_variant( const variant& var, mutable_variant_object& vo, uint32_t max_depth );
101  void to_variant( const std::vector<char>& var, variant& vo, uint32_t max_depth = 1 );
102  void from_variant( const variant& var, std::vector<char>& vo, uint32_t max_depth = 1 );
103 
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>
107  void from_variant( const variant& var, std::unordered_map<K,T>& vo, uint32_t max_depth );
108 
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>
112  void from_variant(const variant& var, flat_map<K, T, A...>& vo, uint32_t max_depth );
113 
114  template<typename K, typename... T>
115  void to_variant( const std::map<K, T...>& var, variant& vo, uint32_t max_depth );
116  template<typename K, typename T, typename... A>
117  void from_variant( const variant& var, std::map<K, T, A...>& vo, uint32_t max_depth );
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>
121  void from_variant( const variant& var, std::multimap<K,T>& vo, uint32_t max_depth );
122 
123 
124  template<typename T>
125  void to_variant( const std::unordered_set<T>& var, variant& vo, uint32_t max_depth );
126  template<typename T>
127  void from_variant( const variant& var, std::unordered_set<T>& vo, uint32_t max_depth );
128 
129  template<typename T>
130  void to_variant( const std::deque<T>& var, variant& vo, uint32_t max_depth );
131  template<typename T>
132  void from_variant( const variant& var, std::deque<T>& vo, uint32_t max_depth );
133 
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>
137  void from_variant( const variant& var, fc::flat_set<T, A...>& vo, uint32_t max_depth );
138 
139  template<typename T>
140  void to_variant( const std::set<T>& var, variant& vo, uint32_t max_depth );
141  template<typename T>
142  void from_variant( const variant& var, std::set<T>& vo, uint32_t max_depth );
143 
144  void to_variant( const time_point& var, variant& vo, uint32_t max_depth );
145  void from_variant( const variant& var, time_point& vo, uint32_t max_depth );
146 
147  void to_variant( const time_point_sec& var, variant& vo, uint32_t max_depth );
148  void from_variant( const variant& var, time_point_sec& vo, uint32_t max_depth );
149 
150  void to_variant( const microseconds& input_microseconds, variant& output_variant, uint32_t max_depth );
151  void from_variant( const variant& input_variant, microseconds& output_microseconds, uint32_t max_depth );
152 
153  void to_variant( const uint128_t& var, variant& vo, uint32_t max_depth = 1 );
154  void from_variant( const variant& var, uint128_t& vo, uint32_t max_depth = 1 );
155 
156  #if defined(__APPLE__) or defined(__OpenBSD__)
157  void to_variant( size_t s, variant& v, uint32_t max_depth = 1 );
158  #elif !defined(_WIN32)
159  void to_variant( long long int s, variant& v, uint32_t max_depth = 1 );
160  void to_variant( unsigned long long int s, variant& v, uint32_t max_depth = 1 );
161  #endif
162  void to_variant( const std::string& s, variant& v, uint32_t max_depth = 1 );
163 
164  template<typename T>
165  void to_variant( const std::shared_ptr<T>& var, variant& vo, uint32_t max_depth );
166 
167  template<typename T>
168  void from_variant( const variant& var, std::shared_ptr<T>& vo, uint32_t max_depth );
169 
170  typedef std::vector<variant> variants;
171  template<typename A, typename B>
172  void to_variant( const std::pair<A,B>& t, variant& v, uint32_t max_depth );
173  template<typename A, typename B>
174  void from_variant( const variant& v, std::pair<A,B>& p, uint32_t max_depth );
175 
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 )
178  {
179  to_variant( var.value(), vo, max_depth );
180  }
181  template<boost::endian::order O, class T, std::size_t N, boost::endian::align A>
182  void from_variant( const variant& var, boost::endian::endian_buffer<O,T,N,A>& vo, uint32_t max_depth )
183  {
184  T tmp;
185  from_variant( var, tmp, max_depth );
186  vo = tmp;
187  }
188 
198  class variant
199  {
200  public:
201  enum type_id
202  {
203  null_type = 0,
212  };
213 
215  variant();
217  variant( std::nullptr_t, uint32_t max_depth = 1 );
218 
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 );
235 #endif
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 );
239  variant( blob val, uint32_t max_depth = 1 );
240  variant( std::string val, uint32_t max_depth = 1 );
241  variant( variant_object, uint32_t max_depth = 1 );
242  variant( mutable_variant_object, uint32_t max_depth = 1 );
243  variant( variants, uint32_t max_depth = 1 );
244  variant( const variant&, uint32_t max_depth = 1 );
245  variant( variant&&, uint32_t max_depth = 1 );
246  ~variant();
247 
251  class visitor
252  {
253  public:
254  virtual ~visitor(){}
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;
262  virtual void handle( const variant_object& v)const = 0;
263  virtual void handle( const variants& v)const = 0;
264  };
265 
266  void visit( const visitor& v )const;
267 
268  type_id get_type()const;
269 
270  bool is_null()const;
271  bool is_string()const;
272  bool is_bool()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;
278  bool is_blob()const;
282  bool is_numeric()const;
286  bool is_integer()const;
287 
288  int64_t as_int64()const;
289  uint64_t as_uint64()const;
290  bool as_bool()const;
291  double as_double()const;
292 
293  blob& get_blob();
294  const blob& get_blob()const;
295  blob as_blob()const;
296 
300  std::string as_string()const;
301 
303  const std::string& get_string()const;
304 
306  variants& get_array();
307 
309  const variants& get_array()const;
310 
313 
315  const variant_object& get_object()const;
316 
318  const variant& operator[]( const char* )const;
320  const variant& operator[]( size_t pos )const;
322  size_t size()const;
323 
336  template<typename T>
337  T as( uint32_t max_depth )const
338  {
339  T tmp;
340  from_variant( *this, tmp, max_depth );
341  return tmp;
342  }
343 
344  template<typename T>
345  void as( T& v, uint32_t max_depth )const
346  {
347  from_variant( *this, v, max_depth );
348  }
349 
350  variant& operator=( variant&& v );
351  variant& operator=( const variant& v );
352 
353  template<typename T>
354  variant& operator=( T&& v )
355  {
356  return *this = variant( std::forward<T>(v) );
357  }
358 
359  template<typename T>
360  variant( const optional<T>& v, uint32_t max_depth )
361  {
362  _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
363  memset( this, 0, sizeof(*this) );
364  if( v.valid() ) *this = variant( *v, max_depth - 1 );
365  }
366 
367  template<typename T>
368  variant( const T& val, uint32_t max_depth );
369 
370 
371  void clear();
372  private:
373  void init();
374  double _data;
375  char _type[sizeof(void*)];
376  };
378 
380  void from_variant( const variant& var, std::string& vo, uint32_t max_depth = 1 );
382  void from_variant( const variant& var, variants& vo, uint32_t max_depth );
383  void from_variant( const variant& var, variant& vo, uint32_t max_depth );
385  void from_variant( const variant& var, int64_t& vo, uint32_t max_depth = 1 );
387  void from_variant( const variant& var, uint64_t& vo, uint32_t max_depth = 1 );
389  void from_variant( const variant& var, bool& vo, uint32_t max_depth = 1 );
391  void from_variant( const variant& var, double& vo, uint32_t max_depth = 1 );
393  void from_variant( const variant& var, float& vo, uint32_t max_depth = 1 );
395  template<typename T>
396  void from_variant( const variant& var, optional<T>& vo, uint32_t max_depth )
397  {
398  if( var.is_null() ) vo = optional<T>();
399  else
400  {
401  _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
402  vo = T();
403  from_variant( var, *vo, max_depth - 1 );
404  }
405  }
406  template<typename T>
407  void to_variant( const std::unordered_set<T>& var, variant& vo, uint32_t max_depth )
408  {
409  _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
410  std::vector<variant> vars(var.size());
411  size_t i = 0;
412  for( const auto& item : var )
413  vars[i++] = variant( item, max_depth - 1 );
414  vo = vars;
415  }
416  template<typename T>
417  void from_variant( const variant& var, std::unordered_set<T>& vo, uint32_t max_depth )
418  {
419  _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
420  const variants& vars = var.get_array();
421  vo.clear();
422  vo.reserve( vars.size() );
423  for( const auto& item : vars )
424  vo.insert( item.as<T>( max_depth - 1 ) );
425  }
426 
427 
428  template<typename K, typename T>
429  void to_variant( const std::unordered_map<K, T>& var, variant& vo, uint32_t max_depth )
430  {
431  _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
432  std::vector< variant > vars(var.size());
433  size_t i = 0;
434  for( const auto& key_value : var )
435  vars[i++] = fc::variant( key_value, max_depth - 1 );
436  vo = vars;
437  }
438  template<typename K, typename T>
439  void from_variant( const variant& var, std::unordered_map<K, T>& vo, uint32_t max_depth )
440  {
441  _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
442  const variants& vars = var.get_array();
443  vo.clear();
444  vo.reserve( vars.size() );
445  for( const auto& item : vars )
446  vo.insert( item.as< std::pair<K,T> >( max_depth - 1 ) );
447  }
448  template<typename K, typename... T>
449  void to_variant( const std::map<K, T...>& var, variant& vo, uint32_t max_depth )
450  {
451  _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
452  std::vector< variant > vars(var.size());
453  size_t i = 0;
454  for( const auto& key_value : var )
455  vars[i++] = fc::variant( key_value, max_depth - 1 );
456  vo = vars;
457  }
458  template<typename K, typename T, typename... A>
459  void from_variant( const variant& var, std::map<K, T, A...>& vo, uint32_t max_depth )
460  {
461  _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
462  const variants& vars = var.get_array();
463  vo.clear();
464  for( const auto& item : vars )
465  vo.insert( item.as< std::pair<K,T> >( max_depth - 1 ) );
466  }
467 
468  template<typename K, typename T>
469  void to_variant( const std::multimap<K, T>& var, variant& vo, uint32_t max_depth )
470  {
471  _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
472  std::vector< variant > vars(var.size());
473  size_t i = 0;
474  for( const auto& key_value : var )
475  vars[i++] = fc::variant( key_value, max_depth - 1 );
476  vo = vars;
477  }
478  template<typename K, typename T>
479  void from_variant( const variant& var, std::multimap<K, T>& vo, uint32_t max_depth )
480  {
481  _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
482  const variants& vars = var.get_array();
483  vo.clear();
484  for( auto item : vars )
485  vo.insert( item.as< std::pair<K,T> >( max_depth - 1 ) );
486  }
487 
488 
489  template<typename T>
490  void to_variant( const std::set<T>& var, variant& vo, uint32_t max_depth )
491  {
492  _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
493  std::vector<variant> vars(var.size());
494  size_t i = 0;
495  for( const auto& item : var )
496  vars[i++] = fc::variant( item, max_depth - 1 );
497  vo = vars;
498  }
499  template<typename T>
500  void from_variant( const variant& var, std::set<T>& vo, uint32_t max_depth )
501  {
502  _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
503  const variants& vars = var.get_array();
504  vo.clear();
505  for( const auto& item : vars )
506  vo.insert( item.as<T>( max_depth - 1 ) );
507  }
508 
510  template<typename T>
511  void from_variant( const variant& var, std::deque<T>& dest, uint32_t max_depth )
512  {
513  _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
514  const variants& vars = var.get_array();
515  dest.clear();
516  dest.resize( vars.size() );
517  for( const auto& item : vars )
518  dest.push_back( item.as<T>( max_depth - 1 ) );
519  }
520 
522  template<typename T>
523  void to_variant( const std::deque<T>& src, variant& v, uint32_t max_depth )
524  {
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 );
529  v = std::move(vars);
530  }
531 
532 
534  template<typename T>
535  void from_variant( const variant& var, std::vector<T>& dest, uint32_t max_depth )
536  {
537  _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
538  const variants& vars = var.get_array();
539  dest.clear();
540  dest.reserve( vars.size() );
541  for( const auto& item : vars )
542  dest.push_back( item.as<T>( max_depth - 1 ) );
543  }
544 
546  template<typename T>
547  void to_variant( const std::vector<T>& t, variant& v, uint32_t max_depth )
548  {
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 );
553  v = std::move(vars);
554  }
555 
556 
558  template<typename A, typename B>
559  void to_variant( const std::pair<A,B>& t, variant& v, uint32_t max_depth )
560  {
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 );
565  v = vars;
566  }
567  template<typename A, typename B>
568  void from_variant( const variant& v, std::pair<A,B>& p, uint32_t max_depth )
569  {
570  _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
571  const variants& vars = v.get_array();
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 );
576  }
577 
578 
579  template<typename T>
580  variant::variant( const T& val, uint32_t max_depth )
581  {
582  memset( this, 0, sizeof(*this) );
583  to_variant( val, *this, max_depth );
584  }
585 
586  template<typename T>
587  void to_variant( const std::shared_ptr<T>& var, variant& vo, uint32_t max_depth )
588  {
589  if( var )
590  {
591  _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
592  to_variant( *var, vo, max_depth - 1 );
593  }
594  else vo = nullptr;
595  }
596 
597  template<typename T>
598  void from_variant( const variant& var, std::shared_ptr<T>& vo, uint32_t max_depth )
599  {
600  if( var.is_null() ) vo = nullptr;
601  else
602  {
603  _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
604  if( !vo ) vo = std::make_shared<T>();
605  from_variant( var, *vo, max_depth - 1 );
606  }
607  }
608  template<typename T>
609  void to_variant( const std::unique_ptr<T>& var, variant& vo, uint32_t max_depth )
610  {
611  if( var )
612  {
613  _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
614  to_variant( *var, vo, max_depth - 1 );
615  }
616  else vo = nullptr;
617  }
618 
619  template<typename T>
620  void from_variant( const variant& var, std::unique_ptr<T>& vo, uint32_t max_depth )
621  {
622  if( var.is_null() ) vo.reset();
623  else
624  {
625  _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
626  if( !vo ) vo.reset( new T() );
627  from_variant( var, *vo, max_depth - 1 );
628  }
629  }
630 
631 
632  template<typename T>
633  void to_variant( const safe<T>& s, variant& v, uint32_t max_depth ) {
634  to_variant( static_cast<T>(s.value), v, max_depth );
635  }
636 
637  template<typename T>
638  void from_variant( const variant& v, safe<T>& s, uint32_t max_depth ) {
639  s.value = v.as<T>( max_depth );
640  }
641 
642  template<typename T, typename... Args>
643  void to_variant( const boost::multi_index_container<T,Args...>& c, variant& v, uint32_t max_depth )
644  {
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 ) );
650  v = std::move(vars);
651  }
652 
653  template<typename T, typename... Args>
654  void from_variant( const variant& v, boost::multi_index_container<T,Args...>& c, uint32_t max_depth )
655  {
656  _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
657  const variants& vars = v.get_array();
658  c.clear();
659  for( const auto& item : vars )
660  c.insert( item.as<T>( max_depth - 1 ) );
661  }
662 
663  template<size_t N>
664  void to_variant( const std::array<char,N>& bi, variant& v, uint32_t max_depth = 1 )
665  {
666  v = variant( to_hex( bi.data(), N ) );
667  }
668  template<size_t N>
669  void from_variant( const variant& v, std::array<char,N>& bi, uint32_t max_depth = 1 )
670  {
671  std::string ve = v.as_string();
672  if( ve.size() )
673  from_hex( ve, bi.data(), std::min<size_t>( ve.size() / 2, bi.size() ) );
674  else
675  memset( bi.data(), 0, bi.size() );
676  }
677 
678  template<size_t N>
679  void to_variant( const std::array<unsigned char,N>& bi, variant& v, uint32_t max_depth = 1 )
680  {
681  v = variant( to_hex( (char*) bi.data(), N ) );
682  }
683  template<size_t N>
684  void from_variant( const variant& v, std::array<unsigned char,N>& bi, uint32_t max_depth = 1 )
685  {
686  std::string ve = v.as_string();
687  if( ve.size() )
688  from_hex( ve, (char*)bi.data(), std::min<size_t>( ve.size() / 2, bi.size() ) );
689  else
690  memset( bi.data(), 0, bi.size() );
691  }
692 
693  variant operator + ( const variant& a, const variant& b );
694  variant operator - ( const variant& a, const variant& b );
695  variant operator * ( const variant& a, const variant& b );
696  variant operator / ( const variant& a, const variant& b );
697  bool operator == ( const variant& a, const variant& b );
698  bool operator != ( const variant& a, const variant& b );
699  bool operator < ( const variant& a, const variant& b );
700  bool operator > ( const variant& a, const variant& b );
701  bool operator ! ( const variant& a );
702 } // namespace fc
703 
704 #include <fc/reflect/reflect.hpp>
706 FC_REFLECT_ENUM( fc::variant::type_id, (null_type)(int64_type)(uint64_type)(double_type)(bool_type)(string_type)(array_type)(object_type)(blob_type) )
707 FC_REFLECT( fc::blob, (data) )
fc::variant::is_integer
bool is_integer() const
Definition: variant.cpp:335
fc::variant::get_type
type_id get_type() const
Definition: variant.cpp:304
fc::variant_object
An order-perserving dictionary of variant's.
Definition: variant_object.hpp:20
uint128.hpp
fc::variant::visitor::handle
virtual void handle() const =0
handles null_type variants
fc::variant::array_type
@ array_type
Definition: variant.hpp:209
fc::operator>
bool operator>(const variant &a, const variant &b)
Definition: variant.cpp:743
fc::variant::is_string
bool is_string() const
Definition: variant.cpp:314
fc::variant::is_uint64
bool is_uint64() const
Definition: variant.cpp:326
fc::variant::get_array
variants & get_array()
Definition: variant.cpp:496
fc::operator/
variant operator/(const variant &a, const variant &b)
Definition: variant.cpp:840
fc::mutable_variant_object
An order-perserving dictionary of variant's.
Definition: variant_object.hpp:108
fc::from_hex
uint8_t from_hex(char c)
Definition: hex.cpp:6
fc::variant::visitor
Definition: variant.hpp:251
fc::static_variant
Definition: raw_fwd.hpp:27
fc::variant::as_uint64
uint64_t as_uint64() const
Definition: variant.cpp:398
FC_REFLECT_TYPENAME
FC_REFLECT_TYPENAME(fc::log_message)
fc
Definition: api.hpp:15
fc::variant::is_numeric
bool is_numeric() const
Definition: variant.cpp:348
fc::variant::get_string
const std::string & get_string() const
Definition: variant.cpp:575
hex.hpp
fc::variant::is_array
bool is_array() const
Definition: variant.cpp:368
fc::variant::as_string
std::string as_string() const
Definition: variant.cpp:469
fc::operator<
bool operator<(const variant &a, const variant &b)
Definition: variant.cpp:734
fc::variant::blob_type
@ blob_type
Definition: variant.hpp:211
fc::variant::object_type
@ object_type
Definition: variant.hpp:210
fc::variant::is_bool
bool is_bool() const
Definition: variant.cpp:318
fc::variant::string_type
@ string_type
Definition: variant.hpp:208
fc::from_variant
void from_variant(const variant &var, flat_set< T, A... > &vo, uint32_t _max_depth)
Definition: flat.hpp:116
fc::variant::variant
variant(const optional< T > &v, uint32_t max_depth)
Definition: variant.hpp:360
reflect.hpp
Defines types and macros used to provide reflection.
fc::variant::double_type
@ double_type
Definition: variant.hpp:206
fc::to_hex
std::string to_hex(const char *d, uint32_t s)
Definition: hex.cpp:17
flat_fwd.hpp
fc::variant::as_bool
bool as_bool() const
Definition: variant.cpp:441
fc::variant::visitor::~visitor
virtual ~visitor()
Definition: variant.hpp:254
fc::variant::null_type
@ null_type
Definition: variant.hpp:203
fc::throw_assertion_failure
void throw_assertion_failure(const std::string &message)
Definition: exception.cpp:308
fc::variant::bool_type
@ bool_type
Definition: variant.hpp:207
fc::variant::is_blob
bool is_blob() const
Definition: variant.cpp:372
fc::optional::valid
bool valid() const
Definition: optional.hpp:186
fc::operator!
bool operator!(const variant &a)
Definition: variant.cpp:729
fc::variants
std::vector< variant > variants
Definition: variant.hpp:170
fc::variant::as
void as(T &v, uint32_t max_depth) const
Definition: variant.hpp:345
fc::variant::size
size_t size() const
Definition: variant.cpp:570
fc::time_point_sec
Definition: time.hpp:74
fc::variant::as
T as(uint32_t max_depth) const
Definition: variant.hpp:337
fc::variant::operator=
variant & operator=(T &&v)
Definition: variant.hpp:354
fc::variant::is_object
bool is_object() const
Definition: variant.cpp:363
fc::to_variant
void to_variant(const flat_set< T, A... > &var, variant &vo, uint32_t _max_depth)
Definition: flat.hpp:105
fc::ovariant
optional< variant > ovariant
Definition: variant.hpp:377
_FC_ASSERT
#define _FC_ASSERT(cond, msg)
Definition: variant.hpp:30
fc::variant::is_int64
bool is_int64() const
Definition: variant.cpp:330
fc::blob::data
std::vector< char > data
Definition: variant.hpp:58
fc::variant::visit
void visit(const visitor &v) const
Definition: variant.cpp:271
fc::variant::as_blob
blob as_blob() const
Definition: variant.cpp:518
fc::variant::as_double
double as_double() const
Definition: variant.cpp:420
fc::operator-
auto operator-(const fwd< T, S, A > &x, U &&u) -> typename detail::sub< T, U >::type
Definition: fwd_impl.hpp:47
fc::microseconds
Definition: time.hpp:12
fc::variant::operator[]
const variant & operator[](const char *) const
Definition: variant.cpp:561
FC_REFLECT_ENUM
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
Definition: core_messages.hpp:404
fc::variant::as_int64
int64_t as_int64() const
Definition: variant.cpp:377
fc::variant::get_object
variant_object & get_object()
Definition: variant.cpp:554
fc::variant
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition: variant.hpp:198
fc::time_point
Definition: time.hpp:44
fc::operator+
auto operator+(const fwd< T, S, A > &x, U &&u) -> typename detail::add< T, U >::type
Definition: fwd_impl.hpp:44
fc::variant::is_null
bool is_null() const
Definition: variant.cpp:309
fc::operator*
variant operator*(const variant &a, const variant &b)
Definition: variant.cpp:815
fc::variant::get_blob
blob & get_blob()
Definition: variant.cpp:503
fc::operator!=
bool operator!=(const optional< T > &left, const optional< T > &right)
Definition: optional.hpp:257
fc::variant::is_double
bool is_double() const
Definition: variant.cpp:322
fc::variant::uint64_type
@ uint64_type
Definition: variant.hpp:205
fc::variant::operator=
variant & operator=(variant &&v)
Definition: variant.cpp:235
fc::blob
Definition: variant.hpp:58
fc::variant::type_id
type_id
Definition: variant.hpp:201
FC_REFLECT
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition: reflect.hpp:388
fc::optional
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
fc::variant::~variant
~variant()
Definition: variant.cpp:230
fc::safe::value
T value
Definition: safe.hpp:28
fc::operator==
bool operator==(const optional< T > &left, const optional< T > &right)
Definition: optional.hpp:249
fc::variant::clear
void clear()
Definition: variant.cpp:181
fc::variant::variant
variant()
Constructs a null_type variant.
Definition: variant.cpp:30
fc::variant::int64_type
@ int64_type
Definition: variant.hpp:204
fc::safe
Definition: safe.hpp:26
optional.hpp