rippled
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 <ripple/protocol/Issue.h>
24 #include <boost/utility/base_from_member.hpp>
25 
26 namespace ripple {
27 
32 class Book
33 {
34 public:
37 
38  Book()
39  {
40  }
41 
42  Book(Issue const& in_, Issue const& out_) : in(in_), out(out_)
43  {
44  }
45 };
46 
47 bool
48 isConsistent(Book const& book);
49 
51 to_string(Book const& book);
52 
54 operator<<(std::ostream& os, Book const& x);
55 
56 template <class Hasher>
57 void
58 hash_append(Hasher& h, Book const& b)
59 {
60  using beast::hash_append;
61  hash_append(h, b.in, b.out);
62 }
63 
64 Book
65 reversed(Book const& book);
66 
68 int
69 compare(Book const& lhs, Book const& rhs);
70 
73 bool
74 operator==(Book const& lhs, Book const& rhs);
75 bool
76 operator!=(Book const& lhs, Book const& rhs);
81 bool
82 operator<(Book const& lhs, Book const& rhs);
83 bool
84 operator>(Book const& lhs, Book const& rhs);
85 bool
86 operator>=(Book const& lhs, Book const& rhs);
87 bool
88 operator<=(Book const& lhs, Book const& rhs);
91 } // namespace ripple
92 
93 //------------------------------------------------------------------------------
94 
95 namespace std {
96 
97 template <>
98 struct hash<ripple::Issue>
99  : private boost::base_from_member<std::hash<ripple::Currency>, 0>,
100  private boost::base_from_member<std::hash<ripple::AccountID>, 1>
101 {
102 private:
103  using currency_hash_type =
104  boost::base_from_member<std::hash<ripple::Currency>, 0>;
105  using issuer_hash_type =
106  boost::base_from_member<std::hash<ripple::AccountID>, 1>;
107 
108 public:
109  explicit hash() = default;
110 
113 
114  value_type
115  operator()(argument_type const& value) const
116  {
117  value_type result(currency_hash_type::member(value.currency));
118  if (!isXRP(value.currency))
119  boost::hash_combine(
120  result, issuer_hash_type::member(value.account));
121  return result;
122  }
123 };
124 
125 //------------------------------------------------------------------------------
126 
127 template <>
128 struct hash<ripple::Book>
129 {
130 private:
132 
134 
135 public:
136  explicit hash() = default;
137 
140 
141  value_type
142  operator()(argument_type const& value) const
143  {
144  value_type result(m_hasher(value.in));
145  boost::hash_combine(result, m_hasher(value.out));
146  return result;
147  }
148 };
149 
150 } // namespace std
151 
152 //------------------------------------------------------------------------------
153 
154 namespace boost {
155 
156 template <>
157 struct hash<ripple::Issue> : std::hash<ripple::Issue>
158 {
159  explicit hash() = default;
160 
162  // VFALCO NOTE broken in vs2012
163  // using Base::Base; // inherit ctors
164 };
165 
166 template <>
167 struct hash<ripple::Book> : std::hash<ripple::Book>
168 {
169  explicit hash() = default;
170 
172  // VFALCO NOTE broken in vs2012
173  // using Base::Base; // inherit ctors
174 };
175 
176 } // namespace boost
177 
178 #endif
ripple::operator>
bool operator>(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition: base_uint.h:564
ripple::Issue
A currency issued by an account.
Definition: Issue.h:34
std::string
STL class.
std::hash< ripple::Issue >::issuer_hash_type
boost::base_from_member< std::hash< ripple::AccountID >, 1 > issuer_hash_type
Definition: Book.h:106
ripple::isConsistent
bool isConsistent(Book const &book)
Definition: Book.cpp:25
ripple::Book::out
Issue out
Definition: Book.h:36
ripple::operator>=
bool operator>=(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition: base_uint.h:571
ripple::Issue::currency
Currency currency
Definition: Issue.h:37
boost
Definition: IPAddress.h:103
ripple::operator<<
std::ostream & operator<<(std::ostream &os, TOffer< TIn, TOut > const &offer)
Definition: Offer.h:242
ripple::operator==
bool operator==(Manifest const &lhs, Manifest const &rhs)
Definition: Manifest.h:159
ripple::operator<=
bool operator<=(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition: base_uint.h:557
std::hash< ripple::Book >
Definition: Book.h:128
ripple::operator<
bool operator<(CanonicalTXSet::Key const &lhs, CanonicalTXSet::Key const &rhs)
Definition: CanonicalTXSet.cpp:25
std::ostream
STL class.
ripple::compare
int compare(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition: base_uint.h:533
ripple::reversed
Book reversed(Book const &book)
Definition: Book.cpp:45
ripple::operator!=
bool operator!=(Manifest const &lhs, Manifest const &rhs)
Definition: Manifest.h:169
std::hash< ripple::Book >::m_hasher
hasher m_hasher
Definition: Book.h:133
std::hash< ripple::Book >::operator()
value_type operator()(argument_type const &value) const
Definition: Book.h:142
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
std::hash< ripple::Issue >::currency_hash_type
boost::base_from_member< std::hash< ripple::Currency >, 0 > currency_hash_type
Definition: Book.h:104
std
STL namespace.
beast::hash_append
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
std::size_t
ripple::to_string
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
Definition: app/misc/impl/Manifest.cpp:38
ripple::Book
Specifies an order book.
Definition: Book.h:32
ripple::Book::Book
Book()
Definition: Book.h:38
ripple::hash_append
void hash_append(Hasher &h, ValidatorBlobInfo const &blobInfo)
Definition: ValidatorList.h:897
ripple::Book::Book
Book(Issue const &in_, Issue const &out_)
Definition: Book.h:42
std::hash< ripple::Issue >
Definition: Book.h:98
std::hash< ripple::Issue >::operator()
value_type operator()(argument_type const &value) const
Definition: Book.h:115
ripple::Book::in
Issue in
Definition: Book.h:35
ripple::Issue::account
AccountID account
Definition: Issue.h:38
std::hash