From 9483935d6446657ffc1c8d329307e08f2eb1ab05 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 18 Jul 2018 18:13:48 +0200 Subject: [PATCH] Support 64 bit values in unsigned_int object --- include/fc/container/flat.hpp | 6 +++--- include/fc/interprocess/container.hpp | 2 +- include/fc/io/raw.hpp | 18 +++++++++--------- include/fc/io/raw_variant.hpp | 2 +- include/fc/io/varint.hpp | 27 ++++++++++++--------------- src/io/varint.cpp | 2 +- 6 files changed, 27 insertions(+), 30 deletions(-) diff --git a/include/fc/container/flat.hpp b/include/fc/container/flat.hpp index 2eca459..5e6a363 100644 --- a/include/fc/container/flat.hpp +++ b/include/fc/container/flat.hpp @@ -11,7 +11,7 @@ namespace fc { inline void pack( Stream& s, const flat_set& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; - pack( s, unsigned_int((uint32_t)value.size()), _max_depth ); + pack( s, unsigned_int(value.size()), _max_depth ); auto itr = value.begin(); auto end = value.end(); while( itr != end ) { @@ -38,7 +38,7 @@ namespace fc { inline void pack( Stream& s, const flat_map& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; - pack( s, unsigned_int((uint32_t)value.size()), _max_depth ); + pack( s, unsigned_int(value.size()), _max_depth ); auto itr = value.begin(); auto end = value.end(); while( itr != end ) { @@ -67,7 +67,7 @@ namespace fc { void pack( Stream& s, const bip::vector& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; - pack( s, unsigned_int((uint32_t)value.size()), _max_depth ); + pack( s, unsigned_int(value.size()), _max_depth ); if( !std::is_fundamental::value ) { auto itr = value.begin(); auto end = value.end(); diff --git a/include/fc/interprocess/container.hpp b/include/fc/interprocess/container.hpp index 7ede74b..a00346e 100644 --- a/include/fc/interprocess/container.hpp +++ b/include/fc/interprocess/container.hpp @@ -113,7 +113,7 @@ namespace fc { inline void pack( Stream& s, const bip::vector& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; - pack( s, unsigned_int((uint32_t)value.size()), _max_depth ); + pack( s, unsigned_int(value.size()), _max_depth ); auto itr = value.begin(); auto end = value.end(); while( itr != end ) { diff --git a/include/fc/io/raw.hpp b/include/fc/io/raw.hpp index 9ef61ec..c7035ec 100644 --- a/include/fc/io/raw.hpp +++ b/include/fc/io/raw.hpp @@ -273,9 +273,9 @@ namespace fc { // std::vector template inline void pack( Stream& s, const std::vector& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth - 1 ); + fc::raw::pack( s, unsigned_int(value.size()), _max_depth - 1 ); if( value.size() ) - s.write( &value.front(), (uint32_t)value.size() ); + s.write( &value.front(), value.size() ); } template inline void unpack( Stream& s, std::vector& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); @@ -289,7 +289,7 @@ namespace fc { // fc::string template inline void pack( Stream& s, const fc::string& v, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - fc::raw::pack( s, unsigned_int((uint32_t)v.size()), _max_depth - 1 ); + fc::raw::pack( s, unsigned_int(v.size()), _max_depth - 1 ); if( v.size() ) s.write( v.c_str(), v.size() ); } @@ -433,7 +433,7 @@ namespace fc { inline void pack( Stream& s, const std::unordered_set& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; - fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth ); + fc::raw::pack( s, unsigned_int(value.size()), _max_depth ); auto itr = value.begin(); auto end = value.end(); while( itr != end ) { @@ -478,7 +478,7 @@ namespace fc { inline void pack( Stream& s, const std::unordered_map& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; - fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth ); + fc::raw::pack( s, unsigned_int(value.size()), _max_depth ); auto itr = value.begin(); auto end = value.end(); while( itr != end ) { @@ -506,7 +506,7 @@ namespace fc { inline void pack( Stream& s, const std::map& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; - fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth ); + fc::raw::pack( s, unsigned_int(value.size()), _max_depth ); auto itr = value.begin(); auto end = value.end(); while( itr != end ) { @@ -534,7 +534,7 @@ namespace fc { inline void pack( Stream& s, const std::deque& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; - fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth ); + fc::raw::pack( s, unsigned_int(value.size()), _max_depth ); auto itr = value.begin(); auto end = value.end(); while( itr != end ) { @@ -562,7 +562,7 @@ namespace fc { inline void pack( Stream& s, const std::vector& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; - fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth ); + fc::raw::pack( s, unsigned_int(value.size()), _max_depth ); auto itr = value.begin(); auto end = value.end(); while( itr != end ) { @@ -590,7 +590,7 @@ namespace fc { inline void pack( Stream& s, const std::set& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; - fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth ); + fc::raw::pack( s, unsigned_int(value.size()), _max_depth ); auto itr = value.begin(); auto end = value.end(); while( itr != end ) { diff --git a/include/fc/io/raw_variant.hpp b/include/fc/io/raw_variant.hpp index b07fbaa..59b93d9 100644 --- a/include/fc/io/raw_variant.hpp +++ b/include/fc/io/raw_variant.hpp @@ -128,7 +128,7 @@ namespace fc { namespace raw { { FC_ASSERT( _max_depth > 0 ); --_max_depth; - unsigned_int vs = (uint32_t)v.size(); + unsigned_int vs = v.size(); pack( s, vs, _max_depth ); for( auto itr = v.begin(); itr != v.end(); ++itr ) { diff --git a/include/fc/io/varint.hpp b/include/fc/io/varint.hpp index 00a8023..80082f2 100644 --- a/include/fc/io/varint.hpp +++ b/include/fc/io/varint.hpp @@ -4,35 +4,32 @@ namespace fc { struct unsigned_int { - unsigned_int( uint32_t v = 0 ):value(v){} + unsigned_int( uint64_t v = 0 ):value(v){} template unsigned_int( T v ):value(v){} - //operator uint32_t()const { return value; } - //operator uint64_t()const { return value; } - template operator T()const { return static_cast(value); } - unsigned_int& operator=( int32_t v ) { value = v; return *this; } + unsigned_int& operator=( uint64_t v ) { value = v; return *this; } - uint32_t value; + uint64_t 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 uint64_t& v ) { return i.value == v; } + friend bool operator==( const uint64_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 uint64_t& v ) { return i.value != v; } + friend bool operator!=( const uint64_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 uint64_t& v ) { return i.value < v; } + friend bool operator<( const uint64_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 uint64_t& v ) { return i.value >= v; } + friend bool operator>=( const uint64_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; } }; @@ -95,7 +92,7 @@ namespace std public: size_t operator()(const fc::signed_int &a) const { - return std::hash()(a.value); + return std::hash()(a.value); } }; } diff --git a/src/io/varint.cpp b/src/io/varint.cpp index 6d5df6c..6384eec 100644 --- a/src/io/varint.cpp +++ b/src/io/varint.cpp @@ -6,5 +6,5 @@ namespace fc void to_variant( const signed_int& var, variant& vo, uint32_t max_depth ) { vo = var.value; } void from_variant( const variant& var, signed_int& vo, uint32_t max_depth ) { vo.value = static_cast(var.as_int64()); } void to_variant( const unsigned_int& var, variant& vo, uint32_t max_depth ) { vo = var.value; } -void from_variant( const variant& var, unsigned_int& vo, uint32_t max_depth ) { vo.value = static_cast(var.as_uint64()); } +void from_variant( const variant& var, unsigned_int& vo, uint32_t max_depth ) { vo.value = var.as_uint64(); } }