Replace base_uint(string) with from_hex_text<> (RIPD-897)

Removes the base_uint constructor that took a string.  Replaces
that functionality with two free functions named from_hex_text<>.
Use of from_hex_text<> looks like this:

auto v = from_hex_text<uint256>("AAA555");
static_assert (std::is_same<decltype(v), uint256>::value, "Huh!");

from_hex_text<> only operates on base_uint types.  At the moment the
list of those types include:

 o uint128,
 o uint160,
 o uint256,
 o Directory,
 o Account,
 o Currency, and
 o NodeID.

Using from_hex_text<> with any other types will not compile due to
an enable_if.
This commit is contained in:
Scott Schurr
2015-05-29 10:31:13 -07:00
committed by Vinnie Falco
parent d7def5509d
commit 4515ac0bca
9 changed files with 48 additions and 25 deletions

View File

@@ -19,6 +19,7 @@
#include <BeastConfig.h>
#include <ripple/protocol/Indexes.h>
#include <beast/utility/static_initializer.h>
namespace ripple {
@@ -168,8 +169,10 @@ getQualityIndex (uint256 const& uBase, const std::uint64_t uNodeDir)
uint256
getQualityNext (uint256 const& uBase)
{
static uint256 uNext ("10000000000000000");
return uBase + uNext;
static beast::static_initializer<uint256> const uNext (
from_hex_text<uint256>("10000000000000000"));
return uBase + *uNext;
}
std::uint64_t

View File

@@ -22,6 +22,7 @@
#include <ripple/protocol/SystemParameters.h>
#include <ripple/protocol/RippleAddress.h>
#include <ripple/protocol/UintTypes.h>
#include <beast/utility/static_initializer.h>
namespace ripple {
@@ -32,8 +33,6 @@ std::string to_string(Account const& account)
std::string to_string(Currency const& currency)
{
static Currency const sIsoBits ("FFFFFFFFFFFFFFFFFFFFFFFF000000FFFFFFFFFF");
// Characters we are willing to allow in the ASCII representation of a
// three-letter currency code.
static std::string const allowed_characters =
@@ -48,7 +47,10 @@ std::string to_string(Currency const& currency)
if (currency == noCurrency())
return "1";
if ((currency & sIsoBits).isZero ())
static beast::static_initializer<Currency> const sIsoBits (
from_hex_text<Currency>("FFFFFFFFFFFFFFFFFFFFFFFF000000FFFFFFFFFF"));
if ((currency & *sIsoBits).isZero ())
{
// The offset of the 3 character ISO code in the currency descriptor
int const isoOffset = 12;