rippled
Issue.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/Issue.h>
21 
22 namespace ripple {
23 
24 bool
25 isConsistent(Issue const& ac)
26 {
27  return isXRP(ac.currency) == isXRP(ac.account);
28 }
29 
31 to_string(Issue const& ac)
32 {
33  if (isXRP(ac.account))
34  return to_string(ac.currency);
35 
36  return to_string(ac.account) + "/" + to_string(ac.currency);
37 }
38 
41 {
42  os << to_string(x);
43  return os;
44 }
45 
50 int
51 compare(Issue const& lhs, Issue const& rhs)
52 {
53  int diff = compare(lhs.currency, rhs.currency);
54  if (diff != 0)
55  return diff;
56  if (isXRP(lhs.currency))
57  return 0;
58  return compare(lhs.account, rhs.account);
59 }
60 
63 bool
64 operator==(Issue const& lhs, Issue const& rhs)
65 {
66  return compare(lhs, rhs) == 0;
67 }
68 
69 bool
70 operator!=(Issue const& lhs, Issue const& rhs)
71 {
72  return !(lhs == rhs);
73 }
78 bool
79 operator<(Issue const& lhs, Issue const& rhs)
80 {
81  return compare(lhs, rhs) < 0;
82 }
83 
84 bool
85 operator>(Issue const& lhs, Issue const& rhs)
86 {
87  return rhs < lhs;
88 }
89 
90 bool
91 operator>=(Issue const& lhs, Issue const& rhs)
92 {
93  return !(lhs < rhs);
94 }
95 
96 bool
97 operator<=(Issue const& lhs, Issue const& rhs)
98 {
99  return !(rhs < lhs);
100 }
101 
102 } // namespace ripple
ripple::operator>
bool operator>(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition: base_uint.h:492
ripple::Issue
A currency issued by an account.
Definition: Issue.h:34
std::string
STL class.
ripple::isConsistent
bool isConsistent(Book const &book)
Definition: Book.cpp:25
ripple::operator>=
bool operator>=(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition: base_uint.h:499
ripple::Issue::currency
Currency currency
Definition: Issue.h:37
ripple::SBoxCmp::diff
@ diff
ripple::to_string
std::string to_string(ListDisposition disposition)
Definition: ValidatorList.cpp:45
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::operator!=
bool operator!=(Manifest const &lhs, Manifest const &rhs)
Definition: Manifest.h:165
ripple::isXRP
bool isXRP(AccountID const &c)
Definition: AccountID.h:89
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Issue::account
AccountID account
Definition: Issue.h:38