BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet 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 }
std::hash< fc::unsigned_int >::operator()
size_t operator()(const fc::unsigned_int &a) const
Definition: varint.hpp:58
fc::unsigned_int::unsigned_int
unsigned_int(uint64_t v=0)
Definition: varint.hpp:7
fc::unsigned_int::operator>=
friend bool operator>=(const uint64_t &i, const unsigned_int &v)
Definition: varint.hpp:40
fc::unsigned_int::operator==
friend bool operator==(const unsigned_int &i, const unsigned_int &v)
Definition: varint.hpp:21
fc::unsigned_int::operator!=
friend bool operator!=(const uint64_t &i, const unsigned_int &v)
Definition: varint.hpp:24
fc::unsigned_int::operator>
friend bool operator>(const unsigned_int &i, const unsigned_int &v)
Definition: varint.hpp:37
fc
Definition: api.hpp:15
fc::unsigned_int::operator==
friend bool operator==(const uint64_t &i, const unsigned_int &v)
Definition: varint.hpp:20
fc::unsigned_int::operator>
friend bool operator>(const unsigned_int &i, const uint64_t &v)
Definition: varint.hpp:35
fc::unsigned_int::operator>
friend bool operator>(const uint64_t &i, const unsigned_int &v)
Definition: varint.hpp:36
fc::unsigned_int::operator<
friend bool operator<(const unsigned_int &i, const uint64_t &v)
Definition: varint.hpp:27
fc::from_variant
void from_variant(const variant &var, flat_set< T, A... > &vo, uint32_t _max_depth)
Definition: flat.hpp:116
fc::unsigned_int::operator=
unsigned_int & operator=(uint64_t v)
Definition: varint.hpp:15
fc::unsigned_int::operator<
friend bool operator<(const unsigned_int &i, const unsigned_int &v)
Definition: varint.hpp:29
fc::unsigned_int::operator<=
friend bool operator<=(const uint64_t &i, const unsigned_int &v)
Definition: varint.hpp:32
fc::unsigned_int::operator!=
friend bool operator!=(const unsigned_int &i, const unsigned_int &v)
Definition: varint.hpp:25
fc::unsigned_int
Definition: varint.hpp:6
fc::unsigned_int::operator<
friend bool operator<(const uint64_t &i, const unsigned_int &v)
Definition: varint.hpp:28
fc::unsigned_int::operator>=
friend bool operator>=(const unsigned_int &i, const unsigned_int &v)
Definition: varint.hpp:41
fc::unsigned_int::unsigned_int
unsigned_int(T v)
Definition: varint.hpp:10
fc::to_variant
void to_variant(const flat_set< T, A... > &var, variant &vo, uint32_t _max_depth)
Definition: flat.hpp:105
fc::unsigned_int::operator<=
friend bool operator<=(const unsigned_int &i, const unsigned_int &v)
Definition: varint.hpp:33
fc::unsigned_int::operator==
friend bool operator==(const unsigned_int &i, const uint64_t &v)
Definition: varint.hpp:19
fc::unsigned_int::operator!=
friend bool operator!=(const unsigned_int &i, const uint64_t &v)
Definition: varint.hpp:23
fc::unsigned_int::value
uint64_t value
Definition: varint.hpp:17
std
Definition: zeroed_array.hpp:76
fc::unsigned_int::operator>=
friend bool operator>=(const unsigned_int &i, const uint64_t &v)
Definition: varint.hpp:39
fc::unsigned_int::operator<=
friend bool operator<=(const unsigned_int &i, const uint64_t &v)
Definition: varint.hpp:31