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_)
43  : in (in_)
44  , out (out_)
45  {
46  }
47 };
48 
49 bool
50 isConsistent (Book const& book);
51 
53 to_string (Book const& book);
54 
56 operator<< (std::ostream& os, Book const& x);
57 
58 template <class Hasher>
59 void
60 hash_append (Hasher& h, Book const& b)
61 {
62  using beast::hash_append;
63  hash_append(h, b.in, b.out);
64 }
65 
66 Book
67 reversed (Book const& book);
68 
70 int
71 compare (Book const& lhs, Book const& rhs);
72 
75 bool
76 operator== (Book const& lhs, Book const& rhs);
77 bool
78 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);
89 bool
90 operator<= (Book const& lhs, Book const& rhs);
93 }
94 
95 //------------------------------------------------------------------------------
96 
97 namespace std {
98 
99 template <>
100 struct hash <ripple::Issue>
101  : private boost::base_from_member <std::hash <ripple::Currency>, 0>
102  , private boost::base_from_member <std::hash <ripple::AccountID>, 1>
103 {
104 private:
105  using currency_hash_type = boost::base_from_member <
107  using issuer_hash_type = boost::base_from_member <
109 
110 public:
111  explicit hash() = default;
112 
115 
117  {
118  value_type result (currency_hash_type::member (value.currency));
119  if (!isXRP (value.currency))
120  boost::hash_combine (result,
121  issuer_hash_type::member (value.account));
122  return result;
123  }
124 };
125 
126 //------------------------------------------------------------------------------
127 
128 template <>
129 struct hash <ripple::Book>
130 {
131 private:
133 
135 
136 public:
137  explicit hash() = default;
138 
141 
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 }
151 
152 //------------------------------------------------------------------------------
153 
154 namespace boost {
155 
156 template <>
157 struct hash <ripple::Issue>
158  : std::hash <ripple::Issue>
159 {
160  explicit hash() = default;
161 
163  // VFALCO NOTE broken in vs2012
164  //using Base::Base; // inherit ctors
165 };
166 
167 template <>
168 struct hash <ripple::Book>
169  : std::hash <ripple::Book>
170 {
171  explicit hash() = default;
172 
174  // VFALCO NOTE broken in vs2012
175  //using Base::Base; // inherit ctors
176 };
177 
178 }
179 
180 #endif
std::hash< ripple::Issue >::currency_hash_type
boost::base_from_member< std::hash< ripple::Currency >, 0 > currency_hash_type
Definition: Book.h:106
std::hash::operator()
T operator()(T... args)
ripple::operator>
bool operator>(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition: base_uint.h:470
std::hash< ripple::Issue >::issuer_hash_type
boost::base_from_member< std::hash< ripple::AccountID >, 1 > issuer_hash_type
Definition: Book.h:108
ripple::Issue
A currency issued by an account.
Definition: Issue.h:34
std::string
STL class.
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
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:477
ripple::Issue::currency
Currency currency
Definition: Issue.h:37
boost
Definition: IPAddress.h:127
ripple::to_string
std::string to_string(ListDisposition disposition)
Definition: ValidatorList.cpp:41
ripple::operator<<
std::ostream & operator<<(std::ostream &os, TOffer< TIn, TOut > const &offer)
Definition: Offer.h:237
ripple::operator==
bool operator==(Manifest const &lhs, Manifest const &rhs)
Definition: Manifest.h:148
ripple::operator<=
bool operator<=(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition: base_uint.h:463
std::hash< ripple::Currency >
Definition: UintTypes.h:96
std::hash< ripple::Book >
Definition: Book.h:129
std::ostream
STL class.
ripple::compare
int compare(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition: base_uint.h:439
ripple::reversed
Book reversed(Book const &book)
Definition: Book.cpp:45
ripple::operator!=
bool operator!=(Manifest const &lhs, Manifest const &rhs)
Definition: Manifest.h:161
std::hash< ripple::Book >::m_hasher
hasher m_hasher
Definition: Book.h:134
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
std::hash< ripple::AccountID >
Definition: AccountID.h:188
std
STL namespace.
ripple::hash_append
void hash_append(Hasher &h, Slice const &v)
Definition: Slice.h:151
std::size_t
ripple::Book
Specifies an order book.
Definition: Book.h:32
ripple::Book::Book
Book()
Definition: Book.h:38
ripple::operator<
bool operator<(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition: base_uint.h:456
ripple::Book::Book
Book(Issue const &in_, Issue const &out_)
Definition: Book.h:42
std::hash< ripple::Issue >
Definition: Book.h:100
ripple::Book::in
Issue in
Definition: Book.h:35
ripple::Issue::account
AccountID account
Definition: Issue.h:38
std::hash