rippled
Book.cpp
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 #include <ripple/protocol/Book.h>
21 
22 namespace ripple {
23 
24 bool
25 isConsistent(Book const& book)
26 {
27  return isConsistent(book.in) && isConsistent(book.out) &&
28  book.in != book.out;
29 }
30 
32 to_string(Book const& book)
33 {
34  return to_string(book.in) + "->" + to_string(book.out);
35 }
36 
39 {
40  os << to_string(x);
41  return os;
42 }
43 
44 Book
45 reversed(Book const& book)
46 {
47  return Book(book.out, book.in);
48 }
49 
51 int
52 compare(Book const& lhs, Book const& rhs)
53 {
54  int const diff(compare(lhs.in, rhs.in));
55  if (diff != 0)
56  return diff;
57  return compare(lhs.out, rhs.out);
58 }
59 
62 bool
63 operator==(Book const& lhs, Book const& rhs)
64 {
65  return (lhs.in == rhs.in) && (lhs.out == rhs.out);
66 }
67 
68 bool
69 operator!=(Book const& lhs, Book const& rhs)
70 {
71  return (lhs.in != rhs.in) || (lhs.out != rhs.out);
72 }
77 bool
78 operator<(Book const& lhs, Book const& rhs)
79 {
80  int const diff(compare(lhs.in, rhs.in));
81  if (diff != 0)
82  return diff < 0;
83  return lhs.out < rhs.out;
84 }
85 
86 bool
87 operator>(Book const& lhs, Book const& rhs)
88 {
89  return rhs < lhs;
90 }
91 
92 bool
93 operator>=(Book const& lhs, Book const& rhs)
94 {
95  return !(lhs < rhs);
96 }
97 
98 bool
99 operator<=(Book const& lhs, Book const& rhs)
100 {
101  return !(rhs < lhs);
102 }
103 
104 } // namespace ripple
ripple::operator>
bool operator>(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition: base_uint.h:492
std::string
STL class.
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:499
ripple::SBoxCmp::diff
@ diff
ripple::to_string
std::string to_string(ListDisposition disposition)
Definition: ValidatorList.cpp:42
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:155
ripple::operator<=
bool operator<=(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition: base_uint.h:485
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:461
ripple::reversed
Book reversed(Book const &book)
Definition: Book.cpp:45
ripple::operator!=
bool operator!=(Manifest const &lhs, Manifest const &rhs)
Definition: Manifest.h:165
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Book
Specifies an order book.
Definition: Book.h:32
ripple::Book::in
Issue in
Definition: Book.h:35