rippled
Loading...
Searching...
No Matches
Book.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_PROTOCOL_BOOK_H_INCLUDED
21#define RIPPLE_PROTOCOL_BOOK_H_INCLUDED
22
23#include <xrpl/basics/CountedObject.h>
24#include <xrpl/protocol/Issue.h>
25#include <boost/utility/base_from_member.hpp>
26
27namespace ripple {
28
33class Book final : public CountedObject<Book>
34{
35public:
38
40 {
41 }
42
43 Book(Issue const& in_, Issue const& out_) : in(in_), out(out_)
44 {
45 }
46};
47
48bool
49isConsistent(Book const& book);
50
52to_string(Book const& book);
53
55operator<<(std::ostream& os, Book const& x);
56
57template <class Hasher>
58void
59hash_append(Hasher& h, Book const& b)
60{
62 hash_append(h, b.in, b.out);
63}
64
65Book
66reversed(Book const& book);
67
70[[nodiscard]] inline constexpr bool
71operator==(Book const& lhs, Book const& rhs)
72{
73 return (lhs.in == rhs.in) && (lhs.out == rhs.out);
74}
79[[nodiscard]] inline constexpr std::weak_ordering
80operator<=>(Book const& lhs, Book const& rhs)
81{
82 if (auto const c{lhs.in <=> rhs.in}; c != 0)
83 return c;
84 return lhs.out <=> rhs.out;
85}
88} // namespace ripple
89
90//------------------------------------------------------------------------------
91
92namespace std {
93
94template <>
95struct hash<ripple::Issue>
96 : private boost::base_from_member<std::hash<ripple::Currency>, 0>,
97 private boost::base_from_member<std::hash<ripple::AccountID>, 1>
98{
99private:
101 boost::base_from_member<std::hash<ripple::Currency>, 0>;
103 boost::base_from_member<std::hash<ripple::AccountID>, 1>;
104
105public:
106 explicit hash() = default;
107
110
112 operator()(argument_type const& value) const
113 {
114 value_type result(currency_hash_type::member(value.currency));
115 if (!isXRP(value.currency))
116 boost::hash_combine(
117 result, issuer_hash_type::member(value.account));
118 return result;
119 }
120};
121
122//------------------------------------------------------------------------------
123
124template <>
125struct hash<ripple::Book>
126{
127private:
129
131
132public:
133 explicit hash() = default;
134
137
139 operator()(argument_type const& value) const
140 {
141 value_type result(m_hasher(value.in));
142 boost::hash_combine(result, m_hasher(value.out));
143 return result;
144 }
145};
146
147} // namespace std
148
149//------------------------------------------------------------------------------
150
151namespace boost {
152
153template <>
154struct hash<ripple::Issue> : std::hash<ripple::Issue>
155{
156 explicit hash() = default;
157
159 // VFALCO NOTE broken in vs2012
160 // using Base::Base; // inherit ctors
161};
162
163template <>
164struct hash<ripple::Book> : std::hash<ripple::Book>
165{
166 explicit hash() = default;
167
169 // VFALCO NOTE broken in vs2012
170 // using Base::Base; // inherit ctors
171};
172
173} // namespace boost
174
175#endif
Specifies an order book.
Definition: Book.h:34
Book()
Definition: Book.h:39
Issue in
Definition: Book.h:36
Issue out
Definition: Book.h:37
Book(Issue const &in_, Issue const &out_)
Definition: Book.h:43
Tracks the number of instances of an object.
A currency issued by an account.
Definition: Issue.h:36
AccountID account
Definition: Issue.h:39
Currency currency
Definition: Issue.h:38
std::enable_if_t< is_contiguously_hashable< T, Hasher >::value > hash_append(Hasher &h, T const &t) noexcept
Logically concatenate input data to a Hasher.
Definition: hash_append.h:236
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
void hash_append(Hasher &h, Slice const &v)
Definition: Slice.h:198
bool isConsistent(Book const &book)
Definition: Book.cpp:25
constexpr std::strong_ordering operator<=>(base_uint< Bits, Tag > const &lhs, base_uint< Bits, Tag > const &rhs)
Definition: base_uint.h:562
Book reversed(Book const &book)
Definition: Book.cpp:45
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
Definition: base_uint.h:636
std::string to_string(base_uint< Bits, Tag > const &a)
Definition: base_uint.h:629
constexpr bool operator==(base_uint< Bits, Tag > const &lhs, base_uint< Bits, Tag > const &rhs)
Definition: base_uint.h:584
STL namespace.
value_type operator()(argument_type const &value) const
Definition: Book.h:139
boost::base_from_member< std::hash< ripple::AccountID >, 1 > issuer_hash_type
Definition: Book.h:103
value_type operator()(argument_type const &value) const
Definition: Book.h:112
boost::base_from_member< std::hash< ripple::Currency >, 0 > currency_hash_type
Definition: Book.h:101