From 3508e0c034180c2f27031c406a392530c3ccaf8e Mon Sep 17 00:00:00 2001 From: Eric Frias Date: Tue, 19 May 2015 10:02:37 -0400 Subject: [PATCH] Add overloads of comparison operators to allow comparison of safe/uint128 and native integer classes --- CMakeLists.txt | 5 +++++ include/fc/safe.hpp | 48 ++++++++++++++++++++++++++++++++++++++++++ include/fc/uint128.hpp | 8 ++++++- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e75f58..7761879 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -258,6 +258,11 @@ target_include_directories(fc #target_link_libraries( fc PUBLIC easylzma_static scrypt udt ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library}) target_link_libraries( fc PUBLIC easylzma_static udt ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library} ${readline_libraries}) +if(MSVC) + set_source_files_properties( src/network/http/websocket.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) +endif(MSVC) + + IF(NOT Boost_UNIT_TEST_FRAMEWORK_LIBRARY MATCHES "\\.(a|lib)$") IF(WIN32) add_definitions(/DBOOST_TEST_DYN_LINK) diff --git a/include/fc/safe.hpp b/include/fc/safe.hpp index 0c1a12e..7d876c0 100644 --- a/include/fc/safe.hpp +++ b/include/fc/safe.hpp @@ -64,26 +64,74 @@ namespace fc { { return a.value == b.value; } + friend bool operator == ( const safe& a, const T& b ) + { + return a.value == b; + } + friend bool operator == ( const T& a, const safe& b ) + { + return a == b.value; + } friend bool operator != ( const safe& a, const safe& b ) { return a.value != b.value; } + friend bool operator != ( const safe& a, const T& b ) + { + return a.value != b; + } + friend bool operator != ( const T& a, const safe& b ) + { + return a != b.value; + } friend bool operator < ( const safe& a, const safe& b ) { return a.value < b.value; } + friend bool operator < ( const safe& a, const T& b ) + { + return a.value < b; + } + friend bool operator < ( const T& a, const safe& b ) + { + return a < b.value; + } friend bool operator > ( const safe& a, const safe& b ) { return a.value > b.value; } + friend bool operator > ( const safe& a, const T& b ) + { + return a.value > b; + } + friend bool operator > ( const T& a, const safe& b ) + { + return a > b.value; + } friend bool operator >= ( const safe& a, const safe& b ) { return a.value >= b.value; } + friend bool operator >= ( const safe& a, const T& b ) + { + return a.value >= b; + } + friend bool operator >= ( const T& a, const safe& b ) + { + return a >= b.value; + } friend bool operator <= ( const safe& a, const safe& b ) { return a.value <= b.value; } + friend bool operator <= ( const safe& a, const T& b ) + { + return a.value <= b; + } + friend bool operator <= ( const T& a, const safe& b ) + { + return a <= b.value; + } T value = 0; }; diff --git a/include/fc/uint128.hpp b/include/fc/uint128.hpp index 41e6925..2e79a56 100644 --- a/include/fc/uint128.hpp +++ b/include/fc/uint128.hpp @@ -39,6 +39,7 @@ namespace fc bool operator == ( const uint128& o )const{ return hi == o.hi && lo == o.lo; } bool operator != ( const uint128& o )const{ return hi != o.hi || lo != o.lo; } bool operator < ( const uint128& o )const { return (hi == o.hi) ? lo < o.lo : hi < o.hi; } + bool operator < ( const int64_t& o )const { return *this < uint128(o); } bool operator !()const { return !(hi !=0 || lo != 0); } uint128 operator -()const { return ++uint128( ~hi, ~lo ); } uint128 operator ~()const { return uint128( ~hi, ~lo ); } @@ -72,10 +73,15 @@ namespace fc friend uint128 operator << ( const uint128& l, const uint128& r ) { return uint128(l)<<=r; } friend uint128 operator >> ( const uint128& l, const uint128& r ) { return uint128(l)>>=r; } friend bool operator > ( const uint128& l, const uint128& r ) { return r < l; } - + friend bool operator > ( const uint128& l, const int64_t& r ) { return uint128(r) < l; } + friend bool operator > ( const int64_t& l, const uint128& r ) { return r < uint128(l); } friend bool operator >= ( const uint128& l, const uint128& r ) { return l == r || l > r; } + friend bool operator >= ( const uint128& l, const int64_t& r ) { return l >= uint128(r); } + friend bool operator >= ( const int64_t& l, const uint128& r ) { return uint128(l) >= r; } friend bool operator <= ( const uint128& l, const uint128& r ) { return l == r || l < r; } + friend bool operator <= ( const uint128& l, const int64_t& r ) { return l <= uint128(r); } + friend bool operator <= ( const int64_t& l, const uint128& r ) { return uint128(l) <= r; } friend std::size_t hash_value( const uint128& v ) { return city_hash_size_t((const char*)&v, sizeof(v)); }