BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface software
varint.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <stdint.h>
3 
4 namespace fc {
5 
6 struct unsigned_int {
7  unsigned_int( uint64_t v = 0 ):value(v){}
8 
9  template<typename T>
10  unsigned_int( T v ):value(v){}
11 
12  template<typename T>
13  operator T()const { return static_cast<T>(value); }
14 
15  unsigned_int& operator=( uint64_t v ) { value = v; return *this; }
16 
17  uint64_t value;
18 
19  friend bool operator==( const unsigned_int& i, const uint64_t& v ) { return i.value == v; }
20  friend bool operator==( const uint64_t& i, const unsigned_int& v ) { return i == v.value; }
21  friend bool operator==( const unsigned_int& i, const unsigned_int& v ) { return i.value == v.value; }
22 
23  friend bool operator!=( const unsigned_int& i, const uint64_t& v ) { return i.value != v; }
24  friend bool operator!=( const uint64_t& i, const unsigned_int& v ) { return i != v.value; }
25  friend bool operator!=( const unsigned_int& i, const unsigned_int& v ) { return i.value != v.value; }
26 
27  friend bool operator<( const unsigned_int& i, const uint64_t& v ) { return i.value < v; }
28  friend bool operator<( const uint64_t& i, const unsigned_int& v ) { return i < v.value; }
29  friend bool operator<( const unsigned_int& i, const unsigned_int& v ) { return i.value < v.value; }
30 
31  friend bool operator<=( const unsigned_int& i, const uint64_t& v ) { return i.value <= v; }
32  friend bool operator<=( const uint64_t& i, const unsigned_int& v ) { return i <= v.value; }
33  friend bool operator<=( const unsigned_int& i, const unsigned_int& v ) { return i.value <= v.value; }
34 
35  friend bool operator>( const unsigned_int& i, const uint64_t& v ) { return i.value > v; }
36  friend bool operator>( const uint64_t& i, const unsigned_int& v ) { return i > v.value; }
37  friend bool operator>( const unsigned_int& i, const unsigned_int& v ) { return i.value > v.value; }
38 
39  friend bool operator>=( const unsigned_int& i, const uint64_t& v ) { return i.value >= v; }
40  friend bool operator>=( const uint64_t& i, const unsigned_int& v ) { return i >= v.value; }
41  friend bool operator>=( const unsigned_int& i, const unsigned_int& v ) { return i.value >= v.value; }
42 };
43 
44 class variant;
45 
46 void to_variant( const unsigned_int& var, variant& vo, uint32_t max_depth = 1 );
47 void from_variant( const variant& var, unsigned_int& vo, uint32_t max_depth = 1 );
48 
49 } // namespace fc
50 
51 #include <unordered_map>
52 namespace std
53 {
54  template<>
55  struct hash<fc::unsigned_int>
56  {
57  public:
58  size_t operator()(const fc::unsigned_int &a) const
59  {
60  return std::hash<uint64_t>()(a.value);
61  }
62  };
63 }
friend bool operator<(const unsigned_int &i, const uint64_t &v)
Definition: varint.hpp:27
friend bool operator>(const unsigned_int &i, const uint64_t &v)
Definition: varint.hpp:35
friend bool operator!=(const uint64_t &i, const unsigned_int &v)
Definition: varint.hpp:24
unsigned_int & operator=(uint64_t v)
Definition: varint.hpp:15
friend bool operator!=(const unsigned_int &i, const unsigned_int &v)
Definition: varint.hpp:25
friend bool operator>=(const unsigned_int &i, const uint64_t &v)
Definition: varint.hpp:39
friend bool operator<(const uint64_t &i, const unsigned_int &v)
Definition: varint.hpp:28
friend bool operator==(const unsigned_int &i, const unsigned_int &v)
Definition: varint.hpp:21
friend bool operator<=(const unsigned_int &i, const unsigned_int &v)
Definition: varint.hpp:33
void to_variant(const flat_set< T, A... > &var, variant &vo, uint32_t _max_depth)
Definition: flat.hpp:105
friend bool operator<=(const uint64_t &i, const unsigned_int &v)
Definition: varint.hpp:32
unsigned_int(uint64_t v=0)
Definition: varint.hpp:7
friend bool operator>=(const unsigned_int &i, const unsigned_int &v)
Definition: varint.hpp:41
unsigned_int(T v)
Definition: varint.hpp:10
friend bool operator<(const unsigned_int &i, const unsigned_int &v)
Definition: varint.hpp:29
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object&#39;s.
Definition: variant.hpp:198
friend bool operator>=(const uint64_t &i, const unsigned_int &v)
Definition: varint.hpp:40
friend bool operator!=(const unsigned_int &i, const uint64_t &v)
Definition: varint.hpp:23
void from_variant(const variant &var, flat_set< T, A... > &vo, uint32_t _max_depth)
Definition: flat.hpp:116
friend bool operator==(const unsigned_int &i, const uint64_t &v)
Definition: varint.hpp:19
friend bool operator>(const unsigned_int &i, const unsigned_int &v)
Definition: varint.hpp:37
Definition: api.hpp:15
friend bool operator==(const uint64_t &i, const unsigned_int &v)
Definition: varint.hpp:20
uint64_t value
Definition: varint.hpp:17
friend bool operator<=(const unsigned_int &i, const uint64_t &v)
Definition: varint.hpp:31
friend bool operator>(const uint64_t &i, const unsigned_int &v)
Definition: varint.hpp:36
size_t operator()(const fc::unsigned_int &a) const
Definition: varint.hpp:58