Remove BookRef and IssueRef (RIPD-1028)

This commit is contained in:
Miguel Portilla
2015-09-22 16:46:09 -04:00
committed by Vinnie Falco
parent 6db0ceaf81
commit 3af0c38315
16 changed files with 364 additions and 302 deletions

View File

@@ -2749,6 +2749,10 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\Book.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\BuildInfo.cpp"> <ClCompile Include="..\..\src\ripple\protocol\impl\BuildInfo.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
@@ -2785,6 +2789,10 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\Issue.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\Keylet.cpp"> <ClCompile Include="..\..\src\ripple\protocol\impl\Keylet.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>

View File

@@ -3468,6 +3468,9 @@
<ClCompile Include="..\..\src\ripple\protocol\impl\AccountID.cpp"> <ClCompile Include="..\..\src\ripple\protocol\impl\AccountID.cpp">
<Filter>ripple\protocol\impl</Filter> <Filter>ripple\protocol\impl</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\Book.cpp">
<Filter>ripple\protocol\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\BuildInfo.cpp"> <ClCompile Include="..\..\src\ripple\protocol\impl\BuildInfo.cpp">
<Filter>ripple\protocol\impl</Filter> <Filter>ripple\protocol\impl</Filter>
</ClCompile> </ClCompile>
@@ -3495,6 +3498,9 @@
<ClCompile Include="..\..\src\ripple\protocol\impl\IOUAmount.cpp"> <ClCompile Include="..\..\src\ripple\protocol\impl\IOUAmount.cpp">
<Filter>ripple\protocol\impl</Filter> <Filter>ripple\protocol\impl</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\Issue.cpp">
<Filter>ripple\protocol\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\Keylet.cpp"> <ClCompile Include="..\..\src\ripple\protocol\impl\Keylet.cpp">
<Filter>ripple\protocol\impl</Filter> <Filter>ripple\protocol\impl</Filter>
</ClCompile> </ClCompile>

View File

@@ -2650,7 +2650,7 @@ void NetworkOPsImp::getBookPage (
{ {
// If either asset is globally frozen, consider all offers // If either asset is globally frozen, consider all offers
// that aren't ours to be totally unfunded // that aren't ours to be totally unfunded
saOwnerFunds.clear (IssueRef (book.out.currency, book.out.account)); saOwnerFunds.clear (book.out);
} }
else else
{ {
@@ -2817,7 +2817,7 @@ void NetworkOPsImp::getBookPage (
{ {
// If either asset is globally frozen, consider all offers // If either asset is globally frozen, consider all offers
// that aren't ours to be totally unfunded // that aren't ours to be totally unfunded
saOwnerFunds.clear (IssueRef (book.out.currency, book.out.account)); saOwnerFunds.clear (book.out);
} }
else else
{ {

View File

@@ -23,7 +23,7 @@
namespace ripple { namespace ripple {
BookTip::BookTip (ApplyView& view, BookRef book) BookTip::BookTip (ApplyView& view, Book const& book)
: view_ (view) : view_ (view)
, m_valid (false) , m_valid (false)
, m_book (getBookBase (book)) , m_book (getBookBase (book))

View File

@@ -49,7 +49,7 @@ private:
public: public:
/** Create the iterator. */ /** Create the iterator. */
BookTip (ApplyView& view, BookRef book); BookTip (ApplyView& view, Book const& book);
uint256 const& uint256 const&
dir() const noexcept dir() const noexcept

View File

@@ -131,7 +131,7 @@ CreateOffer::preflight (PreflightContext const& ctx)
} }
TER TER
CreateOffer::checkAcceptAsset(IssueRef issue) const CreateOffer::checkAcceptAsset(Issue const& issue) const
{ {
// Only valid for custom currencies // Only valid for custom currencies
assert (!isXRP (issue.currency)); assert (!isXRP (issue.currency));

View File

@@ -61,7 +61,7 @@ public:
private: private:
/** Determine if we are authorized to hold the asset we want to get */ /** Determine if we are authorized to hold the asset we want to get */
TER TER
checkAcceptAsset(IssueRef issue) const; checkAcceptAsset(Issue const& issue) const;
bool bool
dry_offer (ApplyView& view, Offer const& offer); dry_offer (ApplyView& view, Offer const& offer);

View File

@@ -24,7 +24,7 @@
namespace ripple { namespace ripple {
OfferStream::OfferStream (ApplyView& view, ApplyView& cancelView, OfferStream::OfferStream (ApplyView& view, ApplyView& cancelView,
BookRef book, Clock::time_point when, Book const& book, Clock::time_point when,
StepCounter& counter, beast::Journal journal) StepCounter& counter, beast::Journal journal)
: j_ (journal) : j_ (journal)
, view_ (view) , view_ (view)

View File

@@ -92,7 +92,7 @@ private:
public: public:
OfferStream (ApplyView& view, ApplyView& cancelView, OfferStream (ApplyView& view, ApplyView& cancelView,
BookRef book, Clock::time_point when, Book const& book, Clock::time_point when,
StepCounter& counter, beast::Journal journal); StepCounter& counter, beast::Journal journal);
/** Returns the offer at the tip of the order book. /** Returns the offer at the tip of the order book.

View File

@@ -136,7 +136,7 @@ accountHolds (ReadView const& view,
else if ((zeroIfFrozen == fhZERO_IF_FROZEN) && else if ((zeroIfFrozen == fhZERO_IF_FROZEN) &&
isFrozen(view, account, currency, issuer)) isFrozen(view, account, currency, issuer))
{ {
amount.clear (IssueRef (currency, issuer)); amount.clear (Issue (currency, issuer));
} }
else else
{ {

View File

@@ -29,154 +29,75 @@ namespace ripple {
The order book is a pair of Issues called in and out. The order book is a pair of Issues called in and out.
@see Issue. @see Issue.
*/ */
template <bool ByValue> class Book
class BookType
{ {
public: public:
using Issue = IssueType <ByValue>;
Issue in; Issue in;
Issue out; Issue out;
BookType () Book ()
{ {
} }
BookType (Issue const& in_, Issue const& out_) Book (Issue const& in_, Issue const& out_)
: in (in_) : in (in_)
, out (out_) , out (out_)
{ {
} }
template <bool OtherByValue>
BookType (BookType <OtherByValue> const& other)
: in (other.in)
, out (other.out)
{
}
/** Assignment.
This is only valid when ByValue == `true`
*/
template <bool OtherByValue>
BookType& operator= (BookType <OtherByValue> const& other)
{
in = other.in;
out = other.out;
return *this;
}
}; };
template <bool ByValue> bool
bool isConsistent(BookType<ByValue> const& book) isConsistent (Book const& book);
{
return isConsistent(book.in) && isConsistent (book.out)
&& book.in != book.out;
}
template <bool ByValue> std::string
std::string to_string (BookType<ByValue> const& book) to_string (Book const& book);
{
return to_string(book.in) + "->" + to_string(book.out);
}
template <bool ByValue> std::ostream&
std::ostream& operator<<(std::ostream& os, BookType<ByValue> const& x) operator<< (std::ostream& os, Book const& x);
{
os << to_string (x);
return os;
}
template <bool ByValue, class Hasher> template <class Hasher>
void hash_append (Hasher& h, BookType<ByValue> const& b) void
hash_append (Hasher& h, Book const& b)
{ {
using beast::hash_append; using beast::hash_append;
hash_append(h, b.in, b.out); hash_append(h, b.in, b.out);
} }
template <bool ByValue> Book
BookType<ByValue> reversed (BookType<ByValue> const& book) reversed (Book const& book);
{
return BookType<ByValue> (book.out, book.in);
}
/** Ordered comparison. */ /** Ordered comparison. */
template <bool LhsByValue, bool RhsByValue> int
int compare (BookType <LhsByValue> const& lhs, compare (Book const& lhs, Book const& rhs);
BookType <RhsByValue> const& rhs)
{
int const diff (compare (lhs.in, rhs.in));
if (diff != 0)
return diff;
return compare (lhs.out, rhs.out);
}
/** Equality comparison. */ /** Equality comparison. */
/** @{ */ /** @{ */
template <bool LhsByValue, bool RhsByValue> bool
bool operator== (BookType <LhsByValue> const& lhs, operator== (Book const& lhs, Book const& rhs);
BookType <RhsByValue> const& rhs) bool
{ operator!= (Book const& lhs, Book const& rhs);
return (lhs.in == rhs.in) &&
(lhs.out == rhs.out);
}
template <bool LhsByValue, bool RhsByValue>
bool operator!= (BookType <LhsByValue> const& lhs,
BookType <RhsByValue> const& rhs)
{
return (lhs.in != rhs.in) ||
(lhs.out != rhs.out);
}
/** @} */ /** @} */
/** Strict weak ordering. */ /** Strict weak ordering. */
/** @{ */ /** @{ */
template <bool LhsByValue, bool RhsByValue> bool
bool operator< (BookType <LhsByValue> const& lhs, operator< (Book const& lhs,Book const& rhs);
BookType <RhsByValue> const& rhs) bool
{ operator> (Book const& lhs, Book const& rhs);
int const diff (compare (lhs.in, rhs.in)); bool
if (diff != 0) operator>= (Book const& lhs, Book const& rhs);
return diff < 0; bool
return lhs.out < rhs.out; operator<= (Book const& lhs, Book const& rhs);
}
template <bool LhsByValue, bool RhsByValue>
bool operator> (BookType <LhsByValue> const& lhs,
BookType <RhsByValue> const& rhs)
{
return rhs < lhs;
}
template <bool LhsByValue, bool RhsByValue>
bool operator>= (BookType <LhsByValue> const& lhs,
BookType <RhsByValue> const& rhs)
{
return ! (lhs < rhs);
}
template <bool LhsByValue, bool RhsByValue>
bool operator<= (BookType <LhsByValue> const& lhs,
BookType <RhsByValue> const& rhs)
{
return ! (rhs < lhs);
}
/** @} */ /** @} */
//------------------------------------------------------------------------------
using Book = BookType <true>;
using BookRef = BookType <false>;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace std { namespace std {
template <bool ByValue> template <>
struct hash <ripple::IssueType <ByValue>> struct hash <ripple::Issue>
: private boost::base_from_member <std::hash <ripple::Currency>, 0> : private boost::base_from_member <std::hash <ripple::Currency>, 0>
, private boost::base_from_member <std::hash <ripple::AccountID>, 1> , private boost::base_from_member <std::hash <ripple::AccountID>, 1>
{ {
@@ -188,7 +109,7 @@ private:
public: public:
using value_type = std::size_t; using value_type = std::size_t;
using argument_type = ripple::IssueType <ByValue>; using argument_type = ripple::Issue;
value_type operator() (argument_type const& value) const value_type operator() (argument_type const& value) const
{ {
@@ -202,17 +123,17 @@ public:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
template <bool ByValue> template <>
struct hash <ripple::BookType <ByValue>> struct hash <ripple::Book>
{ {
private: private:
using hasher = std::hash <ripple::IssueType <ByValue>>; using hasher = std::hash <ripple::Issue>;
hasher m_hasher; hasher m_hasher;
public: public:
using value_type = std::size_t; using value_type = std::size_t;
using argument_type = ripple::BookType <ByValue>; using argument_type = ripple::Book;
value_type operator() (argument_type const& value) const value_type operator() (argument_type const& value) const
{ {
@@ -228,20 +149,20 @@ public:
namespace boost { namespace boost {
template <bool ByValue> template <>
struct hash <ripple::IssueType <ByValue>> struct hash <ripple::Issue>
: std::hash <ripple::IssueType <ByValue>> : std::hash <ripple::Issue>
{ {
using Base = std::hash <ripple::IssueType <ByValue>>; using Base = std::hash <ripple::Issue>;
// VFALCO NOTE broken in vs2012 // VFALCO NOTE broken in vs2012
//using Base::Base; // inherit ctors //using Base::Base; // inherit ctors
}; };
template <bool ByValue> template <>
struct hash <ripple::BookType <ByValue>> struct hash <ripple::Book>
: std::hash <ripple::BookType <ByValue>> : std::hash <ripple::Book>
{ {
using Base = std::hash <ripple::BookType <ByValue>>; using Base = std::hash <ripple::Book>;
// VFALCO NOTE broken in vs2012 // VFALCO NOTE broken in vs2012
//using Base::Base; // inherit ctors //using Base::Base; // inherit ctors
}; };

View File

@@ -29,77 +29,36 @@
namespace ripple { namespace ripple {
/** A currency issued by an account. /** A currency issued by an account.
@see Currency, AccountID, Issue, Book
When ByValue is `false`, this only stores references, and the caller
is responsible for managing object lifetime.
@see Currency, AccountID, Issue, IssueRef, Book
*/ */
template <bool ByValue> class Issue
class IssueType
{ {
public: public:
using IssueCurrency = typename Currency currency;
std::conditional <ByValue, Currency, Currency const&>::type; AccountID account;
using IssueAccount = typename Issue ()
std::conditional <ByValue, AccountID, AccountID const&>::type;
IssueCurrency currency;
IssueAccount account;
IssueType ()
{ {
} }
IssueType (Currency const& c, AccountID const& a) Issue (Currency const& c, AccountID const& a)
: currency (c), account (a) : currency (c), account (a)
{ {
} }
template <bool OtherByValue>
IssueType (IssueType <OtherByValue> const& other)
: currency (other.currency)
, account (other.account)
{
}
/** Assignment. */
template <bool MaybeByValue = ByValue, bool OtherByValue>
std::enable_if_t <MaybeByValue, IssueType&>
operator= (IssueType <OtherByValue> const& other)
{
currency = other.currency;
account = other.account;
return *this;
}
}; };
template <bool ByValue> bool
bool isConsistent(IssueType<ByValue> const& ac) isConsistent (Issue const& ac);
{
return isXRP (ac.currency) == isXRP (ac.account);
}
template <bool ByValue> std::string
std::string to_string (IssueType<ByValue> const& ac) to_string (Issue const& ac);
{
if (isXRP (ac.account))
return to_string (ac.currency);
return to_string(ac.account) + "/" + to_string(ac.currency); std::ostream&
} operator<< (std::ostream& os, Issue const& x);
template <bool ByValue> template <class Hasher>
std::ostream& operator<< ( void
std::ostream& os, IssueType<ByValue> const& x) hash_append(Hasher& h, Issue const& r)
{
os << to_string (x);
return os;
}
template <bool ByValue, class Hasher>
void hash_append (Hasher& h, IssueType<ByValue> const& r)
{ {
using beast::hash_append; using beast::hash_append;
hash_append(h, r.currency, r.account); hash_append(h, r.currency, r.account);
@@ -109,73 +68,31 @@ void hash_append (Hasher& h, IssueType<ByValue> const& r)
The assets are ordered first by currency and then by account, The assets are ordered first by currency and then by account,
if the currency is not XRP. if the currency is not XRP.
*/ */
template <bool LhsByValue, bool RhsByValue> int
int compare (IssueType <LhsByValue> const& lhs, compare (Issue const& lhs, Issue const& rhs);
IssueType <RhsByValue> const& rhs)
{
int diff = compare (lhs.currency, rhs.currency);
if (diff != 0)
return diff;
if (isXRP (lhs.currency))
return 0;
return compare (lhs.account, rhs.account);
}
/** Equality comparison. */ /** Equality comparison. */
/** @{ */ /** @{ */
template <bool LhsByValue, bool RhsByValue> bool
bool operator== (IssueType <LhsByValue> const& lhs, operator== (Issue const& lhs, Issue const& rhs);
IssueType <RhsByValue> const& rhs) bool
{ operator!= (Issue const& lhs, Issue const& rhs);
return compare (lhs, rhs) == 0;
}
template <bool LhsByValue, bool RhsByValue>
bool operator!= (IssueType <LhsByValue> const& lhs,
IssueType <RhsByValue> const& rhs)
{
return ! (lhs == rhs);
}
/** @} */ /** @} */
/** Strict weak ordering. */ /** Strict weak ordering. */
/** @{ */ /** @{ */
template <bool LhsByValue, bool RhsByValue> bool
bool operator< (IssueType <LhsByValue> const& lhs, operator< (Issue const& lhs, Issue const& rhs);
IssueType <RhsByValue> const& rhs) bool
{ operator> (Issue const& lhs, Issue const& rhs);
return compare (lhs, rhs) < 0; bool
} operator>= (Issue const& lhs, Issue const& rhs);
bool
template <bool LhsByValue, bool RhsByValue> operator<= (Issue const& lhs, Issue const& rhs);
bool operator> (IssueType <LhsByValue> const& lhs,
IssueType <RhsByValue> const& rhs)
{
return rhs < lhs;
}
template <bool LhsByValue, bool RhsByValue>
bool operator>= (IssueType <LhsByValue> const& lhs,
IssueType <RhsByValue> const& rhs)
{
return ! (lhs < rhs);
}
template <bool LhsByValue, bool RhsByValue>
bool operator<= (IssueType <LhsByValue> const& lhs,
IssueType <RhsByValue> const& rhs)
{
return ! (rhs < lhs);
}
/** @} */ /** @} */
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
using Issue = IssueType <true>;
using IssueRef = IssueType <false>;
//------------------------------------------------------------------------------
/** Returns an asset specifier that represents XRP. */ /** Returns an asset specifier that represents XRP. */
inline Issue const& xrpIssue () inline Issue const& xrpIssue ()
{ {

View File

@@ -0,0 +1,106 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <ripple/protocol/Book.h>
namespace ripple {
bool
isConsistent (Book const& book)
{
return isConsistent(book.in) && isConsistent (book.out)
&& book.in != book.out;
}
std::string
to_string (Book const& book)
{
return to_string(book.in) + "->" + to_string(book.out);
}
std::ostream&
operator<< (std::ostream& os, Book const& x)
{
os << to_string (x);
return os;
}
Book
reversed (Book const& book)
{
return Book (book.out, book.in);
}
/** Ordered comparison. */
int
compare (Book const& lhs, Book const& rhs)
{
int const diff (compare (lhs.in, rhs.in));
if (diff != 0)
return diff;
return compare (lhs.out, rhs.out);
}
/** Equality comparison. */
/** @{ */
bool
operator== (Book const& lhs, Book const& rhs)
{
return (lhs.in == rhs.in) &&
(lhs.out == rhs.out);
}
bool
operator!= (Book const& lhs, Book const& rhs)
{
return (lhs.in != rhs.in) ||
(lhs.out != rhs.out);
}
/** @} */
/** Strict weak ordering. */
/** @{ */
bool
operator< (Book const& lhs,Book const& rhs)
{
int const diff (compare (lhs.in, rhs.in));
if (diff != 0)
return diff < 0;
return lhs.out < rhs.out;
}
bool
operator> (Book const& lhs, Book const& rhs)
{
return rhs < lhs;
}
bool
operator>= (Book const& lhs, Book const& rhs)
{
return ! (lhs < rhs);
}
bool
operator<= (Book const& lhs, Book const& rhs)
{
return ! (rhs < lhs);
}
} // ripple

View File

@@ -0,0 +1,102 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <ripple/protocol/Issue.h>
namespace ripple {
bool
isConsistent (Issue const& ac)
{
return isXRP (ac.currency) == isXRP (ac.account);
}
std::string
to_string (Issue const& ac)
{
if (isXRP (ac.account))
return to_string (ac.currency);
return to_string(ac.account) + "/" + to_string(ac.currency);
}
std::ostream&
operator<< (std::ostream& os, Issue const& x)
{
os << to_string (x);
return os;
}
/** Ordered comparison.
The assets are ordered first by currency and then by account,
if the currency is not XRP.
*/
int
compare (Issue const& lhs, Issue const& rhs)
{
int diff = compare (lhs.currency, rhs.currency);
if (diff != 0)
return diff;
if (isXRP (lhs.currency))
return 0;
return compare (lhs.account, rhs.account);
}
/** Equality comparison. */
/** @{ */
bool
operator== (Issue const& lhs, Issue const& rhs)
{
return compare (lhs, rhs) == 0;
}
bool
operator!= (Issue const& lhs, Issue const& rhs)
{
return ! (lhs == rhs);
}
/** @} */
/** Strict weak ordering. */
/** @{ */
bool
operator< (Issue const& lhs, Issue const& rhs)
{
return compare (lhs, rhs) < 0;
}
bool
operator> (Issue const& lhs, Issue const& rhs)
{
return rhs < lhs;
}
bool
operator>= (Issue const& lhs, Issue const& rhs)
{
return ! (lhs < rhs);
}
bool
operator<= (Issue const& lhs, Issue const& rhs)
{
return ! (rhs < lhs);
}
} // ripple

View File

@@ -75,9 +75,9 @@ public:
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// Comparison, hash tests for IssueType // Comparison, hash tests for Issue
template <class Issue> template <class Issue>
void testIssueType () void testIssue ()
{ {
Currency const c1 (1); AccountID const i1 (1); Currency const c1 (1); AccountID const i1 (1);
Currency const c2 (2); AccountID const i2 (2); Currency const c2 (2); AccountID const i2 (2);
@@ -128,8 +128,8 @@ public:
AccountID const i1 (1); AccountID const i1 (1);
Currency const c2 (2); Currency const c2 (2);
AccountID const i2 (2); AccountID const i2 (2);
IssueRef const a1 (c1, i1); Issue const a1 (c1, i1);
IssueRef const a2 (c2, i2); Issue const a2 (c2, i2);
{ {
Set c; Set c;
@@ -153,9 +153,9 @@ public:
c.insert (a2); c.insert (a2);
if (! expect (c.size () == 2)) return; if (! expect (c.size () == 2)) return;
if (! expect (c.erase (IssueRef (c1, i2)) == 0)) return; if (! expect (c.erase (Issue (c1, i2)) == 0)) return;
if (! expect (c.erase (IssueRef (c1, i1)) == 1)) return; if (! expect (c.erase (Issue (c1, i1)) == 1)) return;
if (! expect (c.erase (IssueRef (c2, i2)) == 1)) return; if (! expect (c.erase (Issue (c2, i2)) == 1)) return;
if (! expect (c.empty ())) return; if (! expect (c.empty ())) return;
#if STL_SET_HAS_EMPLACE #if STL_SET_HAS_EMPLACE
@@ -174,8 +174,8 @@ public:
AccountID const i1 (1); AccountID const i1 (1);
Currency const c2 (2); Currency const c2 (2);
AccountID const i2 (2); AccountID const i2 (2);
IssueRef const a1 (c1, i1); Issue const a1 (c1, i1);
IssueRef const a2 (c2, i2); Issue const a2 (c2, i2);
{ {
Map c; Map c;
@@ -199,9 +199,9 @@ public:
c.insert (std::make_pair (a2, 2)); c.insert (std::make_pair (a2, 2));
if (! expect (c.size () == 2)) return; if (! expect (c.size () == 2)) return;
if (! expect (c.erase (IssueRef (c1, i2)) == 0)) return; if (! expect (c.erase (Issue (c1, i2)) == 0)) return;
if (! expect (c.erase (IssueRef (c1, i1)) == 1)) return; if (! expect (c.erase (Issue (c1, i1)) == 1)) return;
if (! expect (c.erase (IssueRef (c2, i2)) == 1)) return; if (! expect (c.erase (Issue (c2, i2)) == 1)) return;
if (! expect (c.empty ())) return; if (! expect (c.empty ())) return;
} }
} }
@@ -211,22 +211,22 @@ public:
testcase ("std::set <Issue>"); testcase ("std::set <Issue>");
testIssueSet <std::set <Issue>> (); testIssueSet <std::set <Issue>> ();
testcase ("std::set <IssueRef>"); testcase ("std::set <Issue>");
testIssueSet <std::set <IssueRef>> (); testIssueSet <std::set <Issue>> ();
#if RIPPLE_ASSETS_ENABLE_STD_HASH #if RIPPLE_ASSETS_ENABLE_STD_HASH
testcase ("std::unordered_set <Issue>"); testcase ("std::unordered_set <Issue>");
testIssueSet <std::unordered_set <Issue>> (); testIssueSet <std::unordered_set <Issue>> ();
testcase ("std::unordered_set <IssueRef>"); testcase ("std::unordered_set <Issue>");
testIssueSet <std::unordered_set <IssueRef>> (); testIssueSet <std::unordered_set <Issue>> ();
#endif #endif
testcase ("hash_set <Issue>"); testcase ("hash_set <Issue>");
testIssueSet <hash_set <Issue>> (); testIssueSet <hash_set <Issue>> ();
testcase ("hash_set <IssueRef>"); testcase ("hash_set <Issue>");
testIssueSet <hash_set <IssueRef>> (); testIssueSet <hash_set <Issue>> ();
} }
void testIssueMaps () void testIssueMaps ()
@@ -234,28 +234,28 @@ public:
testcase ("std::map <Issue, int>"); testcase ("std::map <Issue, int>");
testIssueMap <std::map <Issue, int>> (); testIssueMap <std::map <Issue, int>> ();
testcase ("std::map <IssueRef, int>"); testcase ("std::map <Issue, int>");
testIssueMap <std::map <IssueRef, int>> (); testIssueMap <std::map <Issue, int>> ();
#if RIPPLE_ASSETS_ENABLE_STD_HASH #if RIPPLE_ASSETS_ENABLE_STD_HASH
testcase ("std::unordered_map <Issue, int>"); testcase ("std::unordered_map <Issue, int>");
testIssueMap <std::unordered_map <Issue, int>> (); testIssueMap <std::unordered_map <Issue, int>> ();
testcase ("std::unordered_map <IssueRef, int>"); testcase ("std::unordered_map <Issue, int>");
testIssueMap <std::unordered_map <IssueRef, int>> (); testIssueMap <std::unordered_map <Issue, int>> ();
testcase ("hash_map <Issue, int>"); testcase ("hash_map <Issue, int>");
testIssueMap <hash_map <Issue, int>> (); testIssueMap <hash_map <Issue, int>> ();
testcase ("hash_map <IssueRef, int>"); testcase ("hash_map <Issue, int>");
testIssueMap <hash_map <IssueRef, int>> (); testIssueMap <hash_map <Issue, int>> ();
#endif #endif
} }
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// Comparison, hash tests for BookType // Comparison, hash tests for Book
template <class Book> template <class Book>
void testBook () void testBook ()
{ {
@@ -320,10 +320,10 @@ public:
AccountID const i1 (1); AccountID const i1 (1);
Currency const c2 (2); Currency const c2 (2);
AccountID const i2 (2); AccountID const i2 (2);
IssueRef const a1 (c1, i1); Issue const a1 (c1, i1);
IssueRef const a2 (c2, i2); Issue const a2 (c2, i2);
BookRef const b1 (a1, a2); Book const b1 (a1, a2);
BookRef const b2 (a2, a1); Book const b2 (a2, a1);
{ {
Set c; Set c;
@@ -347,9 +347,9 @@ public:
c.insert (b2); c.insert (b2);
if (! expect (c.size () == 2)) return; if (! expect (c.size () == 2)) return;
if (! expect (c.erase (BookRef (a1, a1)) == 0)) return; if (! expect (c.erase (Book (a1, a1)) == 0)) return;
if (! expect (c.erase (BookRef (a1, a2)) == 1)) return; if (! expect (c.erase (Book (a1, a2)) == 1)) return;
if (! expect (c.erase (BookRef (a2, a1)) == 1)) return; if (! expect (c.erase (Book (a2, a1)) == 1)) return;
if (! expect (c.empty ())) return; if (! expect (c.empty ())) return;
#if STL_SET_HAS_EMPLACE #if STL_SET_HAS_EMPLACE
@@ -368,13 +368,13 @@ public:
AccountID const i1 (1); AccountID const i1 (1);
Currency const c2 (2); Currency const c2 (2);
AccountID const i2 (2); AccountID const i2 (2);
IssueRef const a1 (c1, i1); Issue const a1 (c1, i1);
IssueRef const a2 (c2, i2); Issue const a2 (c2, i2);
BookRef const b1 (a1, a2); Book const b1 (a1, a2);
BookRef const b2 (a2, a1); Book const b2 (a2, a1);
//typename Map::value_type value_type; //typename Map::value_type value_type;
//std::pair <BookRef const, int> value_type; //std::pair <Book const, int> value_type;
{ {
Map c; Map c;
@@ -402,9 +402,9 @@ public:
c.insert (std::make_pair (b2, 1)); c.insert (std::make_pair (b2, 1));
if (! expect (c.size () == 2)) return; if (! expect (c.size () == 2)) return;
if (! expect (c.erase (BookRef (a1, a1)) == 0)) return; if (! expect (c.erase (Book (a1, a1)) == 0)) return;
if (! expect (c.erase (BookRef (a1, a2)) == 1)) return; if (! expect (c.erase (Book (a1, a2)) == 1)) return;
if (! expect (c.erase (BookRef (a2, a1)) == 1)) return; if (! expect (c.erase (Book (a2, a1)) == 1)) return;
if (! expect (c.empty ())) return; if (! expect (c.empty ())) return;
} }
} }
@@ -414,22 +414,22 @@ public:
testcase ("std::set <Book>"); testcase ("std::set <Book>");
testBookSet <std::set <Book>> (); testBookSet <std::set <Book>> ();
testcase ("std::set <BookRef>"); testcase ("std::set <Book>");
testBookSet <std::set <BookRef>> (); testBookSet <std::set <Book>> ();
#if RIPPLE_ASSETS_ENABLE_STD_HASH #if RIPPLE_ASSETS_ENABLE_STD_HASH
testcase ("std::unordered_set <Book>"); testcase ("std::unordered_set <Book>");
testBookSet <std::unordered_set <Book>> (); testBookSet <std::unordered_set <Book>> ();
testcase ("std::unordered_set <BookRef>"); testcase ("std::unordered_set <Book>");
testBookSet <std::unordered_set <BookRef>> (); testBookSet <std::unordered_set <Book>> ();
#endif #endif
testcase ("hash_set <Book>"); testcase ("hash_set <Book>");
testBookSet <hash_set <Book>> (); testBookSet <hash_set <Book>> ();
testcase ("hash_set <BookRef>"); testcase ("hash_set <Book>");
testBookSet <hash_set <BookRef>> (); testBookSet <hash_set <Book>> ();
} }
void testBookMaps () void testBookMaps ()
@@ -437,21 +437,21 @@ public:
testcase ("std::map <Book, int>"); testcase ("std::map <Book, int>");
testBookMap <std::map <Book, int>> (); testBookMap <std::map <Book, int>> ();
testcase ("std::map <BookRef, int>"); testcase ("std::map <Book, int>");
testBookMap <std::map <BookRef, int>> (); testBookMap <std::map <Book, int>> ();
#if RIPPLE_ASSETS_ENABLE_STD_HASH #if RIPPLE_ASSETS_ENABLE_STD_HASH
testcase ("std::unordered_map <Book, int>"); testcase ("std::unordered_map <Book, int>");
testBookMap <std::unordered_map <Book, int>> (); testBookMap <std::unordered_map <Book, int>> ();
testcase ("std::unordered_map <BookRef, int>"); testcase ("std::unordered_map <Book, int>");
testBookMap <std::unordered_map <BookRef, int>> (); testBookMap <std::unordered_map <Book, int>> ();
testcase ("hash_map <Book, int>"); testcase ("hash_map <Book, int>");
testBookMap <hash_map <Book, int>> (); testBookMap <hash_map <Book, int>> ();
testcase ("hash_map <BookRef, int>"); testcase ("hash_map <Book, int>");
testBookMap <hash_map <BookRef, int>> (); testBookMap <hash_map <Book, int>> ();
#endif #endif
} }
@@ -468,10 +468,10 @@ public:
// --- // ---
testcase ("Issue"); testcase ("Issue");
testIssueType <Issue> (); testIssue <Issue> ();
testcase ("IssueRef"); testcase ("Issue");
testIssueType <IssueRef> (); testIssue <Issue> ();
testIssueSets (); testIssueSets ();
testIssueMaps (); testIssueMaps ();
@@ -481,8 +481,8 @@ public:
testcase ("Book"); testcase ("Book");
testBook <Book> (); testBook <Book> ();
testcase ("BookRef"); testcase ("Book");
testBook <BookRef> (); testBook <Book> ();
testBookSets (); testBookSets ();
testBookMaps (); testBookMaps ();

View File

@@ -20,6 +20,7 @@
#include <BeastConfig.h> #include <BeastConfig.h>
#include <ripple/protocol/impl/AccountID.cpp> #include <ripple/protocol/impl/AccountID.cpp>
#include <ripple/protocol/impl/Book.cpp>
#include <ripple/protocol/impl/BuildInfo.cpp> #include <ripple/protocol/impl/BuildInfo.cpp>
#include <ripple/protocol/impl/ByteOrder.cpp> #include <ripple/protocol/impl/ByteOrder.cpp>
#include <ripple/protocol/impl/digest.cpp> #include <ripple/protocol/impl/digest.cpp>
@@ -27,6 +28,7 @@
#include <ripple/protocol/impl/Feature.cpp> #include <ripple/protocol/impl/Feature.cpp>
#include <ripple/protocol/impl/HashPrefix.cpp> #include <ripple/protocol/impl/HashPrefix.cpp>
#include <ripple/protocol/impl/Indexes.cpp> #include <ripple/protocol/impl/Indexes.cpp>
#include <ripple/protocol/impl/Issue.cpp>
#include <ripple/protocol/impl/Keylet.cpp> #include <ripple/protocol/impl/Keylet.cpp>
#include <ripple/protocol/impl/LedgerFormats.cpp> #include <ripple/protocol/impl/LedgerFormats.cpp>
#include <ripple/protocol/impl/PublicKey.cpp> #include <ripple/protocol/impl/PublicKey.cpp>