mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-29 07:25:51 +00:00
Remove BookRef and IssueRef (RIPD-1028)
This commit is contained in:
committed by
Vinnie Falco
parent
6db0ceaf81
commit
3af0c38315
@@ -2749,6 +2749,10 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
||||
</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">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|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)'=='release|x64'">True</ExcludedFromBuild>
|
||||
</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">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
||||
|
||||
@@ -3468,6 +3468,9 @@
|
||||
<ClCompile Include="..\..\src\ripple\protocol\impl\AccountID.cpp">
|
||||
<Filter>ripple\protocol\impl</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\ripple\protocol\impl\Book.cpp">
|
||||
<Filter>ripple\protocol\impl</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\ripple\protocol\impl\BuildInfo.cpp">
|
||||
<Filter>ripple\protocol\impl</Filter>
|
||||
</ClCompile>
|
||||
@@ -3495,6 +3498,9 @@
|
||||
<ClCompile Include="..\..\src\ripple\protocol\impl\IOUAmount.cpp">
|
||||
<Filter>ripple\protocol\impl</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\ripple\protocol\impl\Issue.cpp">
|
||||
<Filter>ripple\protocol\impl</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\ripple\protocol\impl\Keylet.cpp">
|
||||
<Filter>ripple\protocol\impl</Filter>
|
||||
</ClCompile>
|
||||
|
||||
@@ -2650,7 +2650,7 @@ void NetworkOPsImp::getBookPage (
|
||||
{
|
||||
// If either asset is globally frozen, consider all offers
|
||||
// that aren't ours to be totally unfunded
|
||||
saOwnerFunds.clear (IssueRef (book.out.currency, book.out.account));
|
||||
saOwnerFunds.clear (book.out);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2817,7 +2817,7 @@ void NetworkOPsImp::getBookPage (
|
||||
{
|
||||
// If either asset is globally frozen, consider all offers
|
||||
// that aren't ours to be totally unfunded
|
||||
saOwnerFunds.clear (IssueRef (book.out.currency, book.out.account));
|
||||
saOwnerFunds.clear (book.out);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
BookTip::BookTip (ApplyView& view, BookRef book)
|
||||
BookTip::BookTip (ApplyView& view, Book const& book)
|
||||
: view_ (view)
|
||||
, m_valid (false)
|
||||
, m_book (getBookBase (book))
|
||||
|
||||
@@ -49,7 +49,7 @@ private:
|
||||
|
||||
public:
|
||||
/** Create the iterator. */
|
||||
BookTip (ApplyView& view, BookRef book);
|
||||
BookTip (ApplyView& view, Book const& book);
|
||||
|
||||
uint256 const&
|
||||
dir() const noexcept
|
||||
|
||||
@@ -131,7 +131,7 @@ CreateOffer::preflight (PreflightContext const& ctx)
|
||||
}
|
||||
|
||||
TER
|
||||
CreateOffer::checkAcceptAsset(IssueRef issue) const
|
||||
CreateOffer::checkAcceptAsset(Issue const& issue) const
|
||||
{
|
||||
// Only valid for custom currencies
|
||||
assert (!isXRP (issue.currency));
|
||||
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
private:
|
||||
/** Determine if we are authorized to hold the asset we want to get */
|
||||
TER
|
||||
checkAcceptAsset(IssueRef issue) const;
|
||||
checkAcceptAsset(Issue const& issue) const;
|
||||
|
||||
bool
|
||||
dry_offer (ApplyView& view, Offer const& offer);
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
namespace ripple {
|
||||
|
||||
OfferStream::OfferStream (ApplyView& view, ApplyView& cancelView,
|
||||
BookRef book, Clock::time_point when,
|
||||
Book const& book, Clock::time_point when,
|
||||
StepCounter& counter, beast::Journal journal)
|
||||
: j_ (journal)
|
||||
, view_ (view)
|
||||
|
||||
@@ -92,7 +92,7 @@ private:
|
||||
|
||||
public:
|
||||
OfferStream (ApplyView& view, ApplyView& cancelView,
|
||||
BookRef book, Clock::time_point when,
|
||||
Book const& book, Clock::time_point when,
|
||||
StepCounter& counter, beast::Journal journal);
|
||||
|
||||
/** Returns the offer at the tip of the order book.
|
||||
|
||||
@@ -136,7 +136,7 @@ accountHolds (ReadView const& view,
|
||||
else if ((zeroIfFrozen == fhZERO_IF_FROZEN) &&
|
||||
isFrozen(view, account, currency, issuer))
|
||||
{
|
||||
amount.clear (IssueRef (currency, issuer));
|
||||
amount.clear (Issue (currency, issuer));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -29,154 +29,75 @@ namespace ripple {
|
||||
The order book is a pair of Issues called in and out.
|
||||
@see Issue.
|
||||
*/
|
||||
template <bool ByValue>
|
||||
class BookType
|
||||
class Book
|
||||
{
|
||||
public:
|
||||
using Issue = IssueType <ByValue>;
|
||||
|
||||
Issue in;
|
||||
Issue out;
|
||||
|
||||
BookType ()
|
||||
Book ()
|
||||
{
|
||||
}
|
||||
|
||||
BookType (Issue const& in_, Issue const& out_)
|
||||
Book (Issue const& in_, Issue const& out_)
|
||||
: in (in_)
|
||||
, 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 isConsistent(BookType<ByValue> const& book)
|
||||
{
|
||||
return isConsistent(book.in) && isConsistent (book.out)
|
||||
&& book.in != book.out;
|
||||
}
|
||||
bool
|
||||
isConsistent (Book const& book);
|
||||
|
||||
template <bool ByValue>
|
||||
std::string to_string (BookType<ByValue> const& book)
|
||||
{
|
||||
return to_string(book.in) + "->" + to_string(book.out);
|
||||
}
|
||||
std::string
|
||||
to_string (Book const& book);
|
||||
|
||||
template <bool ByValue>
|
||||
std::ostream& operator<<(std::ostream& os, BookType<ByValue> const& x)
|
||||
{
|
||||
os << to_string (x);
|
||||
return os;
|
||||
}
|
||||
std::ostream&
|
||||
operator<< (std::ostream& os, Book const& x);
|
||||
|
||||
template <bool ByValue, class Hasher>
|
||||
void hash_append (Hasher& h, BookType<ByValue> const& b)
|
||||
template <class Hasher>
|
||||
void
|
||||
hash_append (Hasher& h, Book const& b)
|
||||
{
|
||||
using beast::hash_append;
|
||||
hash_append (h, b.in, b.out);
|
||||
hash_append(h, b.in, b.out);
|
||||
}
|
||||
|
||||
template <bool ByValue>
|
||||
BookType<ByValue> reversed (BookType<ByValue> const& book)
|
||||
{
|
||||
return BookType<ByValue> (book.out, book.in);
|
||||
}
|
||||
Book
|
||||
reversed (Book const& book);
|
||||
|
||||
/** Ordered comparison. */
|
||||
template <bool LhsByValue, bool RhsByValue>
|
||||
int compare (BookType <LhsByValue> const& lhs,
|
||||
BookType <RhsByValue> const& rhs)
|
||||
{
|
||||
int const diff (compare (lhs.in, rhs.in));
|
||||
if (diff != 0)
|
||||
return diff;
|
||||
return compare (lhs.out, rhs.out);
|
||||
}
|
||||
int
|
||||
compare (Book const& lhs, Book const& rhs);
|
||||
|
||||
/** Equality comparison. */
|
||||
/** @{ */
|
||||
template <bool LhsByValue, bool RhsByValue>
|
||||
bool operator== (BookType <LhsByValue> const& lhs,
|
||||
BookType <RhsByValue> 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);
|
||||
}
|
||||
bool
|
||||
operator== (Book const& lhs, Book const& rhs);
|
||||
bool
|
||||
operator!= (Book const& lhs, Book const& rhs);
|
||||
/** @} */
|
||||
|
||||
/** Strict weak ordering. */
|
||||
/** @{ */
|
||||
template <bool LhsByValue, bool RhsByValue>
|
||||
bool operator< (BookType <LhsByValue> const& lhs,
|
||||
BookType <RhsByValue> const& rhs)
|
||||
{
|
||||
int const diff (compare (lhs.in, rhs.in));
|
||||
if (diff != 0)
|
||||
return diff < 0;
|
||||
return lhs.out < rhs.out;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
bool
|
||||
operator< (Book const& lhs,Book const& rhs);
|
||||
bool
|
||||
operator> (Book const& lhs, Book const& rhs);
|
||||
bool
|
||||
operator>= (Book const& lhs, Book const& rhs);
|
||||
bool
|
||||
operator<= (Book const& lhs, Book const& rhs);
|
||||
/** @} */
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using Book = BookType <true>;
|
||||
using BookRef = BookType <false>;
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace std {
|
||||
|
||||
template <bool ByValue>
|
||||
struct hash <ripple::IssueType <ByValue>>
|
||||
template <>
|
||||
struct hash <ripple::Issue>
|
||||
: private boost::base_from_member <std::hash <ripple::Currency>, 0>
|
||||
, private boost::base_from_member <std::hash <ripple::AccountID>, 1>
|
||||
{
|
||||
@@ -188,7 +109,7 @@ private:
|
||||
|
||||
public:
|
||||
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
|
||||
{
|
||||
@@ -202,17 +123,17 @@ public:
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template <bool ByValue>
|
||||
struct hash <ripple::BookType <ByValue>>
|
||||
template <>
|
||||
struct hash <ripple::Book>
|
||||
{
|
||||
private:
|
||||
using hasher = std::hash <ripple::IssueType <ByValue>>;
|
||||
using hasher = std::hash <ripple::Issue>;
|
||||
|
||||
hasher m_hasher;
|
||||
|
||||
public:
|
||||
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
|
||||
{
|
||||
@@ -228,20 +149,20 @@ public:
|
||||
|
||||
namespace boost {
|
||||
|
||||
template <bool ByValue>
|
||||
struct hash <ripple::IssueType <ByValue>>
|
||||
: std::hash <ripple::IssueType <ByValue>>
|
||||
template <>
|
||||
struct hash <ripple::Issue>
|
||||
: std::hash <ripple::Issue>
|
||||
{
|
||||
using Base = std::hash <ripple::IssueType <ByValue>>;
|
||||
using Base = std::hash <ripple::Issue>;
|
||||
// VFALCO NOTE broken in vs2012
|
||||
//using Base::Base; // inherit ctors
|
||||
};
|
||||
|
||||
template <bool ByValue>
|
||||
struct hash <ripple::BookType <ByValue>>
|
||||
: std::hash <ripple::BookType <ByValue>>
|
||||
template <>
|
||||
struct hash <ripple::Book>
|
||||
: std::hash <ripple::Book>
|
||||
{
|
||||
using Base = std::hash <ripple::BookType <ByValue>>;
|
||||
using Base = std::hash <ripple::Book>;
|
||||
// VFALCO NOTE broken in vs2012
|
||||
//using Base::Base; // inherit ctors
|
||||
};
|
||||
|
||||
@@ -29,153 +29,70 @@
|
||||
namespace ripple {
|
||||
|
||||
/** A currency issued by an account.
|
||||
|
||||
When ByValue is `false`, this only stores references, and the caller
|
||||
is responsible for managing object lifetime.
|
||||
|
||||
@see Currency, AccountID, Issue, IssueRef, Book
|
||||
@see Currency, AccountID, Issue, Book
|
||||
*/
|
||||
template <bool ByValue>
|
||||
class IssueType
|
||||
class Issue
|
||||
{
|
||||
public:
|
||||
using IssueCurrency = typename
|
||||
std::conditional <ByValue, Currency, Currency const&>::type;
|
||||
Currency currency;
|
||||
AccountID account;
|
||||
|
||||
using IssueAccount = typename
|
||||
std::conditional <ByValue, AccountID, AccountID const&>::type;
|
||||
|
||||
IssueCurrency currency;
|
||||
IssueAccount account;
|
||||
|
||||
IssueType ()
|
||||
Issue ()
|
||||
{
|
||||
}
|
||||
|
||||
IssueType (Currency const& c, AccountID const& a)
|
||||
Issue (Currency const& c, AccountID const& 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 isConsistent(IssueType<ByValue> const& ac)
|
||||
{
|
||||
return isXRP (ac.currency) == isXRP (ac.account);
|
||||
}
|
||||
bool
|
||||
isConsistent (Issue const& ac);
|
||||
|
||||
template <bool ByValue>
|
||||
std::string to_string (IssueType<ByValue> const& ac)
|
||||
{
|
||||
if (isXRP (ac.account))
|
||||
return to_string (ac.currency);
|
||||
std::string
|
||||
to_string (Issue const& ac);
|
||||
|
||||
return to_string(ac.account) + "/" + to_string(ac.currency);
|
||||
}
|
||||
std::ostream&
|
||||
operator<< (std::ostream& os, Issue const& x);
|
||||
|
||||
template <bool ByValue>
|
||||
std::ostream& operator<< (
|
||||
std::ostream& os, IssueType<ByValue> const& x)
|
||||
{
|
||||
os << to_string (x);
|
||||
return os;
|
||||
}
|
||||
|
||||
template <bool ByValue, class Hasher>
|
||||
void hash_append (Hasher& h, IssueType<ByValue> const& r)
|
||||
template <class Hasher>
|
||||
void
|
||||
hash_append(Hasher& h, Issue const& r)
|
||||
{
|
||||
using beast::hash_append;
|
||||
hash_append (h, r.currency, r.account);
|
||||
hash_append(h, r.currency, r.account);
|
||||
}
|
||||
|
||||
/** Ordered comparison.
|
||||
The assets are ordered first by currency and then by account,
|
||||
if the currency is not XRP.
|
||||
*/
|
||||
template <bool LhsByValue, bool RhsByValue>
|
||||
int compare (IssueType <LhsByValue> const& lhs,
|
||||
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);
|
||||
}
|
||||
int
|
||||
compare (Issue const& lhs, Issue const& rhs);
|
||||
|
||||
/** Equality comparison. */
|
||||
/** @{ */
|
||||
template <bool LhsByValue, bool RhsByValue>
|
||||
bool operator== (IssueType <LhsByValue> const& lhs,
|
||||
IssueType <RhsByValue> 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);
|
||||
}
|
||||
bool
|
||||
operator== (Issue const& lhs, Issue const& rhs);
|
||||
bool
|
||||
operator!= (Issue const& lhs, Issue const& rhs);
|
||||
/** @} */
|
||||
|
||||
/** Strict weak ordering. */
|
||||
/** @{ */
|
||||
template <bool LhsByValue, bool RhsByValue>
|
||||
bool operator< (IssueType <LhsByValue> const& lhs,
|
||||
IssueType <RhsByValue> const& rhs)
|
||||
{
|
||||
return compare (lhs, rhs) < 0;
|
||||
}
|
||||
|
||||
template <bool LhsByValue, bool RhsByValue>
|
||||
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);
|
||||
}
|
||||
bool
|
||||
operator< (Issue const& lhs, Issue const& rhs);
|
||||
bool
|
||||
operator> (Issue const& lhs, Issue const& rhs);
|
||||
bool
|
||||
operator>= (Issue const& lhs, Issue const& rhs);
|
||||
bool
|
||||
operator<= (Issue const& lhs, Issue const& rhs);
|
||||
/** @} */
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using Issue = IssueType <true>;
|
||||
using IssueRef = IssueType <false>;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** Returns an asset specifier that represents XRP. */
|
||||
inline Issue const& xrpIssue ()
|
||||
{
|
||||
|
||||
106
src/ripple/protocol/impl/Book.cpp
Normal file
106
src/ripple/protocol/impl/Book.cpp
Normal 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
|
||||
102
src/ripple/protocol/impl/Issue.cpp
Normal file
102
src/ripple/protocol/impl/Issue.cpp
Normal 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
|
||||
@@ -75,9 +75,9 @@ public:
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
// Comparison, hash tests for IssueType
|
||||
// Comparison, hash tests for Issue
|
||||
template <class Issue>
|
||||
void testIssueType ()
|
||||
void testIssue ()
|
||||
{
|
||||
Currency const c1 (1); AccountID const i1 (1);
|
||||
Currency const c2 (2); AccountID const i2 (2);
|
||||
@@ -128,8 +128,8 @@ public:
|
||||
AccountID const i1 (1);
|
||||
Currency const c2 (2);
|
||||
AccountID const i2 (2);
|
||||
IssueRef const a1 (c1, i1);
|
||||
IssueRef const a2 (c2, i2);
|
||||
Issue const a1 (c1, i1);
|
||||
Issue const a2 (c2, i2);
|
||||
|
||||
{
|
||||
Set c;
|
||||
@@ -153,9 +153,9 @@ public:
|
||||
c.insert (a2);
|
||||
if (! expect (c.size () == 2)) return;
|
||||
|
||||
if (! expect (c.erase (IssueRef (c1, i2)) == 0)) return;
|
||||
if (! expect (c.erase (IssueRef (c1, i1)) == 1)) return;
|
||||
if (! expect (c.erase (IssueRef (c2, i2)) == 1)) return;
|
||||
if (! expect (c.erase (Issue (c1, i2)) == 0)) return;
|
||||
if (! expect (c.erase (Issue (c1, i1)) == 1)) return;
|
||||
if (! expect (c.erase (Issue (c2, i2)) == 1)) return;
|
||||
if (! expect (c.empty ())) return;
|
||||
|
||||
#if STL_SET_HAS_EMPLACE
|
||||
@@ -174,8 +174,8 @@ public:
|
||||
AccountID const i1 (1);
|
||||
Currency const c2 (2);
|
||||
AccountID const i2 (2);
|
||||
IssueRef const a1 (c1, i1);
|
||||
IssueRef const a2 (c2, i2);
|
||||
Issue const a1 (c1, i1);
|
||||
Issue const a2 (c2, i2);
|
||||
|
||||
{
|
||||
Map c;
|
||||
@@ -199,9 +199,9 @@ public:
|
||||
c.insert (std::make_pair (a2, 2));
|
||||
if (! expect (c.size () == 2)) return;
|
||||
|
||||
if (! expect (c.erase (IssueRef (c1, i2)) == 0)) return;
|
||||
if (! expect (c.erase (IssueRef (c1, i1)) == 1)) return;
|
||||
if (! expect (c.erase (IssueRef (c2, i2)) == 1)) return;
|
||||
if (! expect (c.erase (Issue (c1, i2)) == 0)) return;
|
||||
if (! expect (c.erase (Issue (c1, i1)) == 1)) return;
|
||||
if (! expect (c.erase (Issue (c2, i2)) == 1)) return;
|
||||
if (! expect (c.empty ())) return;
|
||||
}
|
||||
}
|
||||
@@ -211,22 +211,22 @@ public:
|
||||
testcase ("std::set <Issue>");
|
||||
testIssueSet <std::set <Issue>> ();
|
||||
|
||||
testcase ("std::set <IssueRef>");
|
||||
testIssueSet <std::set <IssueRef>> ();
|
||||
testcase ("std::set <Issue>");
|
||||
testIssueSet <std::set <Issue>> ();
|
||||
|
||||
#if RIPPLE_ASSETS_ENABLE_STD_HASH
|
||||
testcase ("std::unordered_set <Issue>");
|
||||
testIssueSet <std::unordered_set <Issue>> ();
|
||||
|
||||
testcase ("std::unordered_set <IssueRef>");
|
||||
testIssueSet <std::unordered_set <IssueRef>> ();
|
||||
testcase ("std::unordered_set <Issue>");
|
||||
testIssueSet <std::unordered_set <Issue>> ();
|
||||
#endif
|
||||
|
||||
testcase ("hash_set <Issue>");
|
||||
testIssueSet <hash_set <Issue>> ();
|
||||
|
||||
testcase ("hash_set <IssueRef>");
|
||||
testIssueSet <hash_set <IssueRef>> ();
|
||||
testcase ("hash_set <Issue>");
|
||||
testIssueSet <hash_set <Issue>> ();
|
||||
}
|
||||
|
||||
void testIssueMaps ()
|
||||
@@ -234,28 +234,28 @@ public:
|
||||
testcase ("std::map <Issue, int>");
|
||||
testIssueMap <std::map <Issue, int>> ();
|
||||
|
||||
testcase ("std::map <IssueRef, int>");
|
||||
testIssueMap <std::map <IssueRef, int>> ();
|
||||
testcase ("std::map <Issue, int>");
|
||||
testIssueMap <std::map <Issue, int>> ();
|
||||
|
||||
#if RIPPLE_ASSETS_ENABLE_STD_HASH
|
||||
testcase ("std::unordered_map <Issue, int>");
|
||||
testIssueMap <std::unordered_map <Issue, int>> ();
|
||||
|
||||
testcase ("std::unordered_map <IssueRef, int>");
|
||||
testIssueMap <std::unordered_map <IssueRef, int>> ();
|
||||
testcase ("std::unordered_map <Issue, int>");
|
||||
testIssueMap <std::unordered_map <Issue, int>> ();
|
||||
|
||||
testcase ("hash_map <Issue, int>");
|
||||
testIssueMap <hash_map <Issue, int>> ();
|
||||
|
||||
testcase ("hash_map <IssueRef, int>");
|
||||
testIssueMap <hash_map <IssueRef, int>> ();
|
||||
testcase ("hash_map <Issue, int>");
|
||||
testIssueMap <hash_map <Issue, int>> ();
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
// Comparison, hash tests for BookType
|
||||
// Comparison, hash tests for Book
|
||||
template <class Book>
|
||||
void testBook ()
|
||||
{
|
||||
@@ -320,10 +320,10 @@ public:
|
||||
AccountID const i1 (1);
|
||||
Currency const c2 (2);
|
||||
AccountID const i2 (2);
|
||||
IssueRef const a1 (c1, i1);
|
||||
IssueRef const a2 (c2, i2);
|
||||
BookRef const b1 (a1, a2);
|
||||
BookRef const b2 (a2, a1);
|
||||
Issue const a1 (c1, i1);
|
||||
Issue const a2 (c2, i2);
|
||||
Book const b1 (a1, a2);
|
||||
Book const b2 (a2, a1);
|
||||
|
||||
{
|
||||
Set c;
|
||||
@@ -347,9 +347,9 @@ public:
|
||||
c.insert (b2);
|
||||
if (! expect (c.size () == 2)) return;
|
||||
|
||||
if (! expect (c.erase (BookRef (a1, a1)) == 0)) return;
|
||||
if (! expect (c.erase (BookRef (a1, a2)) == 1)) return;
|
||||
if (! expect (c.erase (BookRef (a2, a1)) == 1)) return;
|
||||
if (! expect (c.erase (Book (a1, a1)) == 0)) return;
|
||||
if (! expect (c.erase (Book (a1, a2)) == 1)) return;
|
||||
if (! expect (c.erase (Book (a2, a1)) == 1)) return;
|
||||
if (! expect (c.empty ())) return;
|
||||
|
||||
#if STL_SET_HAS_EMPLACE
|
||||
@@ -368,13 +368,13 @@ public:
|
||||
AccountID const i1 (1);
|
||||
Currency const c2 (2);
|
||||
AccountID const i2 (2);
|
||||
IssueRef const a1 (c1, i1);
|
||||
IssueRef const a2 (c2, i2);
|
||||
BookRef const b1 (a1, a2);
|
||||
BookRef const b2 (a2, a1);
|
||||
Issue const a1 (c1, i1);
|
||||
Issue const a2 (c2, i2);
|
||||
Book const b1 (a1, a2);
|
||||
Book const b2 (a2, a1);
|
||||
|
||||
//typename Map::value_type value_type;
|
||||
//std::pair <BookRef const, int> value_type;
|
||||
//std::pair <Book const, int> value_type;
|
||||
|
||||
{
|
||||
Map c;
|
||||
@@ -402,9 +402,9 @@ public:
|
||||
c.insert (std::make_pair (b2, 1));
|
||||
if (! expect (c.size () == 2)) return;
|
||||
|
||||
if (! expect (c.erase (BookRef (a1, a1)) == 0)) return;
|
||||
if (! expect (c.erase (BookRef (a1, a2)) == 1)) return;
|
||||
if (! expect (c.erase (BookRef (a2, a1)) == 1)) return;
|
||||
if (! expect (c.erase (Book (a1, a1)) == 0)) return;
|
||||
if (! expect (c.erase (Book (a1, a2)) == 1)) return;
|
||||
if (! expect (c.erase (Book (a2, a1)) == 1)) return;
|
||||
if (! expect (c.empty ())) return;
|
||||
}
|
||||
}
|
||||
@@ -414,22 +414,22 @@ public:
|
||||
testcase ("std::set <Book>");
|
||||
testBookSet <std::set <Book>> ();
|
||||
|
||||
testcase ("std::set <BookRef>");
|
||||
testBookSet <std::set <BookRef>> ();
|
||||
testcase ("std::set <Book>");
|
||||
testBookSet <std::set <Book>> ();
|
||||
|
||||
#if RIPPLE_ASSETS_ENABLE_STD_HASH
|
||||
testcase ("std::unordered_set <Book>");
|
||||
testBookSet <std::unordered_set <Book>> ();
|
||||
|
||||
testcase ("std::unordered_set <BookRef>");
|
||||
testBookSet <std::unordered_set <BookRef>> ();
|
||||
testcase ("std::unordered_set <Book>");
|
||||
testBookSet <std::unordered_set <Book>> ();
|
||||
#endif
|
||||
|
||||
testcase ("hash_set <Book>");
|
||||
testBookSet <hash_set <Book>> ();
|
||||
|
||||
testcase ("hash_set <BookRef>");
|
||||
testBookSet <hash_set <BookRef>> ();
|
||||
testcase ("hash_set <Book>");
|
||||
testBookSet <hash_set <Book>> ();
|
||||
}
|
||||
|
||||
void testBookMaps ()
|
||||
@@ -437,21 +437,21 @@ public:
|
||||
testcase ("std::map <Book, int>");
|
||||
testBookMap <std::map <Book, int>> ();
|
||||
|
||||
testcase ("std::map <BookRef, int>");
|
||||
testBookMap <std::map <BookRef, int>> ();
|
||||
testcase ("std::map <Book, int>");
|
||||
testBookMap <std::map <Book, int>> ();
|
||||
|
||||
#if RIPPLE_ASSETS_ENABLE_STD_HASH
|
||||
testcase ("std::unordered_map <Book, int>");
|
||||
testBookMap <std::unordered_map <Book, int>> ();
|
||||
|
||||
testcase ("std::unordered_map <BookRef, int>");
|
||||
testBookMap <std::unordered_map <BookRef, int>> ();
|
||||
testcase ("std::unordered_map <Book, int>");
|
||||
testBookMap <std::unordered_map <Book, int>> ();
|
||||
|
||||
testcase ("hash_map <Book, int>");
|
||||
testBookMap <hash_map <Book, int>> ();
|
||||
|
||||
testcase ("hash_map <BookRef, int>");
|
||||
testBookMap <hash_map <BookRef, int>> ();
|
||||
testcase ("hash_map <Book, int>");
|
||||
testBookMap <hash_map <Book, int>> ();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -468,10 +468,10 @@ public:
|
||||
// ---
|
||||
|
||||
testcase ("Issue");
|
||||
testIssueType <Issue> ();
|
||||
testIssue <Issue> ();
|
||||
|
||||
testcase ("IssueRef");
|
||||
testIssueType <IssueRef> ();
|
||||
testcase ("Issue");
|
||||
testIssue <Issue> ();
|
||||
|
||||
testIssueSets ();
|
||||
testIssueMaps ();
|
||||
@@ -481,8 +481,8 @@ public:
|
||||
testcase ("Book");
|
||||
testBook <Book> ();
|
||||
|
||||
testcase ("BookRef");
|
||||
testBook <BookRef> ();
|
||||
testcase ("Book");
|
||||
testBook <Book> ();
|
||||
|
||||
testBookSets ();
|
||||
testBookMaps ();
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <BeastConfig.h>
|
||||
|
||||
#include <ripple/protocol/impl/AccountID.cpp>
|
||||
#include <ripple/protocol/impl/Book.cpp>
|
||||
#include <ripple/protocol/impl/BuildInfo.cpp>
|
||||
#include <ripple/protocol/impl/ByteOrder.cpp>
|
||||
#include <ripple/protocol/impl/digest.cpp>
|
||||
@@ -27,6 +28,7 @@
|
||||
#include <ripple/protocol/impl/Feature.cpp>
|
||||
#include <ripple/protocol/impl/HashPrefix.cpp>
|
||||
#include <ripple/protocol/impl/Indexes.cpp>
|
||||
#include <ripple/protocol/impl/Issue.cpp>
|
||||
#include <ripple/protocol/impl/Keylet.cpp>
|
||||
#include <ripple/protocol/impl/LedgerFormats.cpp>
|
||||
#include <ripple/protocol/impl/PublicKey.cpp>
|
||||
|
||||
Reference in New Issue
Block a user