From 4ef5481e78549fee71a0391f0fa41c7709c67708 Mon Sep 17 00:00:00 2001 From: Tom Ritchford Date: Thu, 29 May 2014 13:42:45 -0400 Subject: [PATCH] base_uint now compares and assigns with beast::Zero. --- src/ripple/types/api/base_uint.h | 44 ++++++++++++++++++++++++++++--- src/ripple_basics/ripple_basics.h | 4 --- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/ripple/types/api/base_uint.h b/src/ripple/types/api/base_uint.h index 6f1cd40b540..2b6f85e1b3e 100644 --- a/src/ripple/types/api/base_uint.h +++ b/src/ripple/types/api/base_uint.h @@ -28,8 +28,12 @@ #include "Blob.h" #include "strHex.h" #include "ByteOrder.h" - + #include "../../../beast/beast/container/hardened_hash.h" +#include "../../../beast/beast/utility/Zero.h" + +using beast::zero; +using beast::Zero; #include @@ -147,7 +151,7 @@ class base_uint } base_uint (base_uint const& other) = default; - + /* Construct from a raw pointer. The buffer pointed to by `data` must be at least Bits/8 bytes. */ @@ -385,6 +389,12 @@ class base_uint { memset (&pn[0], 0, sizeof (pn)); } + + base_uint& operator=(Zero) + { + zero(); + return *this; + } }; typedef base_uint<128> uint128; @@ -396,9 +406,37 @@ extern std::size_t hash_value (uint128 const&); extern std::size_t hash_value (uint160 const&); extern std::size_t hash_value (uint256 const&); + +//------------------------------------------------------------------------------ + +template +bool operator==(base_uint const& u, Zero) +{ + return u.isZero(); +} + +template +bool operator==(Zero, base_uint const& u) +{ + return u == zero; +} + +template +bool operator!=(base_uint const& u, Zero) +{ + return !(u == zero); +} + +template +bool operator!=(Zero, base_uint const& u) +{ + return !(u == zero); +} + + //------------------------------------------------------------------------------ template -int +int compare (base_uint const& a, base_uint const& b) { auto ret = std::mismatch (a.cbegin (), a.cend (), b.cbegin ()); diff --git a/src/ripple_basics/ripple_basics.h b/src/ripple_basics/ripple_basics.h index f50a680458e..76f196e2b74 100644 --- a/src/ripple_basics/ripple_basics.h +++ b/src/ripple_basics/ripple_basics.h @@ -27,10 +27,6 @@ #include #include "../../beast/beast/cxx14/memory.h" -#include "../../beast/beast/utility/Zero.h" - -using beast::zero; -using beast::Zero; #ifndef RIPPLE_TRACK_MUTEXES # define RIPPLE_TRACK_MUTEXES 0