2013-06-05 19:19:00 +00:00
|
|
|
#pragma once
|
2012-09-18 03:04:42 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
namespace fc {
|
|
|
|
|
|
|
|
|
|
struct unsigned_int {
|
|
|
|
|
unsigned_int( uint32_t v = 0 ):value(v){}
|
|
|
|
|
|
2013-07-25 14:49:13 +00:00
|
|
|
template<typename T>
|
|
|
|
|
unsigned_int( T v ):value(v){}
|
|
|
|
|
|
|
|
|
|
//operator uint32_t()const { return value; }
|
|
|
|
|
//operator uint64_t()const { return value; }
|
2012-09-18 03:04:42 +00:00
|
|
|
|
|
|
|
|
template<typename T>
|
2013-07-25 14:49:13 +00:00
|
|
|
operator T()const { return static_cast<T>(value); }
|
|
|
|
|
|
|
|
|
|
unsigned_int& operator=( int32_t v ) { value = v; return *this; }
|
2012-09-18 03:04:42 +00:00
|
|
|
|
|
|
|
|
uint32_t value;
|
2013-07-14 21:58:27 +00:00
|
|
|
|
2014-06-26 19:51:35 +00:00
|
|
|
friend bool operator==( const unsigned_int& i, const uint32_t& v ) { return i.value == v; }
|
|
|
|
|
friend bool operator==( const uint32_t& i, const unsigned_int& v ) { return i == v.value; }
|
|
|
|
|
friend bool operator==( const unsigned_int& i, const unsigned_int& v ) { return i.value == v.value; }
|
|
|
|
|
|
|
|
|
|
friend bool operator!=( const unsigned_int& i, const uint32_t& v ) { return i.value != v; }
|
|
|
|
|
friend bool operator!=( const uint32_t& i, const unsigned_int& v ) { return i != v.value; }
|
|
|
|
|
friend bool operator!=( const unsigned_int& i, const unsigned_int& v ) { return i.value != v.value; }
|
|
|
|
|
|
|
|
|
|
friend bool operator<( const unsigned_int& i, const uint32_t& v ) { return i.value < v; }
|
|
|
|
|
friend bool operator<( const uint32_t& i, const unsigned_int& v ) { return i < v.value; }
|
|
|
|
|
friend bool operator<( const unsigned_int& i, const unsigned_int& v ) { return i.value < v.value; }
|
|
|
|
|
|
|
|
|
|
friend bool operator>=( const unsigned_int& i, const uint32_t& v ) { return i.value >= v; }
|
|
|
|
|
friend bool operator>=( const uint32_t& i, const unsigned_int& v ) { return i >= v.value; }
|
|
|
|
|
friend bool operator>=( const unsigned_int& i, const unsigned_int& v ) { return i.value >= v.value; }
|
2012-09-18 03:04:42 +00:00
|
|
|
};
|
|
|
|
|
|
2014-04-22 14:22:17 +00:00
|
|
|
/**
|
|
|
|
|
* @brief serializes a 32 bit signed interger in as few bytes as possible
|
|
|
|
|
*
|
|
|
|
|
* Uses the google protobuf algorithm for seralizing signed numbers
|
|
|
|
|
*/
|
2012-09-18 03:04:42 +00:00
|
|
|
struct signed_int {
|
2014-05-15 18:14:27 +00:00
|
|
|
signed_int( int32_t v = 0 ):value(v){}
|
2012-09-18 03:04:42 +00:00
|
|
|
operator int32_t()const { return value; }
|
|
|
|
|
template<typename T>
|
|
|
|
|
signed_int& operator=( const T& v ) { value = v; return *this; }
|
2014-10-27 20:37:20 +00:00
|
|
|
signed_int operator++(int) { return value++; }
|
2014-05-08 01:27:37 +00:00
|
|
|
signed_int& operator++(){ ++value; return *this; }
|
2012-09-18 03:04:42 +00:00
|
|
|
|
|
|
|
|
int32_t value;
|
2014-06-26 19:51:35 +00:00
|
|
|
|
|
|
|
|
friend bool operator==( const signed_int& i, const int32_t& v ) { return i.value == v; }
|
|
|
|
|
friend bool operator==( const int32_t& i, const signed_int& v ) { return i == v.value; }
|
|
|
|
|
friend bool operator==( const signed_int& i, const signed_int& v ) { return i.value == v.value; }
|
|
|
|
|
|
|
|
|
|
friend bool operator!=( const signed_int& i, const int32_t& v ) { return i.value != v; }
|
|
|
|
|
friend bool operator!=( const int32_t& i, const signed_int& v ) { return i != v.value; }
|
|
|
|
|
friend bool operator!=( const signed_int& i, const signed_int& v ) { return i.value != v.value; }
|
|
|
|
|
|
|
|
|
|
friend bool operator<( const signed_int& i, const int32_t& v ) { return i.value < v; }
|
|
|
|
|
friend bool operator<( const int32_t& i, const signed_int& v ) { return i < v.value; }
|
|
|
|
|
friend bool operator<( const signed_int& i, const signed_int& v ) { return i.value < v.value; }
|
|
|
|
|
|
|
|
|
|
friend bool operator>=( const signed_int& i, const int32_t& v ) { return i.value >= v; }
|
|
|
|
|
friend bool operator>=( const int32_t& i, const signed_int& v ) { return i >= v.value; }
|
|
|
|
|
friend bool operator>=( const signed_int& i, const signed_int& v ) { return i.value >= v.value; }
|
2012-09-18 03:04:42 +00:00
|
|
|
};
|
|
|
|
|
|
2013-06-05 19:19:00 +00:00
|
|
|
class variant;
|
|
|
|
|
|
|
|
|
|
void to_variant( const signed_int& var, variant& vo );
|
|
|
|
|
void from_variant( const variant& var, signed_int& vo );
|
|
|
|
|
void to_variant( const unsigned_int& var, variant& vo );
|
|
|
|
|
void from_variant( const variant& var, unsigned_int& vo );
|
|
|
|
|
|
2012-09-18 03:04:42 +00:00
|
|
|
} // namespace fc
|
|
|
|
|
|
2014-05-08 01:27:37 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
|
namespace std
|
|
|
|
|
{
|
|
|
|
|
template<>
|
|
|
|
|
struct hash<fc::signed_int>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
size_t operator()(const fc::signed_int &a) const
|
|
|
|
|
{
|
|
|
|
|
return std::hash<int32_t>()(a.value);
|
|
|
|
|
}
|
|
|
|
|
};
|
2014-06-26 19:51:35 +00:00
|
|
|
template<>
|
|
|
|
|
struct hash<fc::unsigned_int>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
size_t operator()(const fc::signed_int &a) const
|
|
|
|
|
{
|
|
|
|
|
return std::hash<uint32_t>()(a.value);
|
|
|
|
|
}
|
|
|
|
|
};
|
2014-05-08 01:27:37 +00:00
|
|
|
}
|