rippled
STCurrency.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2023 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_STCURRENCY_H_INCLUDED
21 #define RIPPLE_PROTOCOL_STCURRENCY_H_INCLUDED
22 
23 #include <ripple/basics/CountedObject.h>
24 #include <ripple/protocol/SField.h>
25 #include <ripple/protocol/STBase.h>
26 #include <ripple/protocol/Serializer.h>
27 #include <ripple/protocol/UintTypes.h>
28 
29 namespace ripple {
30 
31 class STCurrency final : public STBase
32 {
33 private:
35 
36 public:
38 
39  STCurrency() = default;
40 
41  explicit STCurrency(SerialIter& sit, SField const& name);
42 
43  explicit STCurrency(SField const& name, Currency const& currency);
44 
45  explicit STCurrency(SField const& name);
46 
47  Currency const&
48  currency() const;
49 
50  Currency const&
51  value() const noexcept;
52 
53  void
55 
57  getSType() const override;
58 
59  std::string
60  getText() const override;
61 
62  Json::Value getJson(JsonOptions) const override;
63 
64  void
65  add(Serializer& s) const override;
66 
67  bool
68  isEquivalent(const STBase& t) const override;
69 
70  bool
71  isDefault() const override;
72 
73 private:
74  static std::unique_ptr<STCurrency>
75  construct(SerialIter&, SField const& name);
76 
77  STBase*
78  copy(std::size_t n, void* buf) const override;
79  STBase*
80  move(std::size_t n, void* buf) override;
81 
82  friend class detail::STVar;
83 };
84 
86 currencyFromJson(SField const& name, Json::Value const& v);
87 
88 inline Currency const&
90 {
91  return currency_;
92 }
93 
94 inline Currency const&
95 STCurrency::value() const noexcept
96 {
97  return currency_;
98 }
99 
100 inline void
102 {
104 }
105 
106 inline bool
107 operator==(STCurrency const& lhs, STCurrency const& rhs)
108 {
109  return lhs.currency() == rhs.currency();
110 }
111 
112 inline bool
113 operator!=(STCurrency const& lhs, STCurrency const& rhs)
114 {
115  return !operator==(lhs, rhs);
116 }
117 
118 inline bool
119 operator<(STCurrency const& lhs, STCurrency const& rhs)
120 {
121  return lhs.currency() < rhs.currency();
122 }
123 
124 inline bool
125 operator==(STCurrency const& lhs, Currency const& rhs)
126 {
127  return lhs.currency() == rhs;
128 }
129 
130 inline bool
131 operator<(STCurrency const& lhs, Currency const& rhs)
132 {
133  return lhs.currency() < rhs;
134 }
135 
136 } // namespace ripple
137 
138 #endif
ripple::STCurrency::add
void add(Serializer &s) const override
Definition: STCurrency.cpp:59
ripple::STCurrency::isEquivalent
bool isEquivalent(const STBase &t) const override
Definition: STCurrency.cpp:65
ripple::currencyFromJson
STCurrency currencyFromJson(SField const &name, Json::Value const &v)
Definition: STCurrency.cpp:96
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:106
ripple::STCurrency::isDefault
bool isDefault() const override
Definition: STCurrency.cpp:72
ripple::STCurrency::getText
std::string getText() const override
Definition: STCurrency.cpp:48
ripple::base_uint< 160, detail::CurrencyTag >
Json
JSON (JavaScript Object Notation).
Definition: DeliverMax.h:28
ripple::STCurrency::STCurrency
STCurrency()=default
ripple::operator<
bool operator<(CanonicalTXSet::Key const &lhs, CanonicalTXSet::Key const &rhs)
Definition: CanonicalTXSet.cpp:25
ripple::STCurrency::currency_
Currency currency_
Definition: STCurrency.h:34
ripple::STCurrency::construct
static std::unique_ptr< STCurrency > construct(SerialIter &, SField const &name)
Definition: STCurrency.cpp:78
ripple::STCurrency::move
STBase * move(std::size_t n, void *buf) override
Definition: STCurrency.cpp:90
ripple::SerialIter
Definition: Serializer.h:311
ripple::STCurrency
Definition: STCurrency.h:31
ripple::Serializer
Definition: Serializer.h:40
ripple::STCurrency::setCurrency
void setCurrency(Currency const &currency)
Definition: STCurrency.h:101
ripple::Currency
base_uint< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Definition: UintTypes.h:56
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::JsonOptions
Note, should be treated as flags that can be | and &.
Definition: STBase.h:35
ripple::SField
Identifies fields.
Definition: SField.h:141
ripple::STBase
A type which can be exported to a well known binary format.
Definition: STBase.h:121
ripple::STBase::operator!=
bool operator!=(const STBase &t) const
Definition: STBase.cpp:51
std
STL namespace.
ripple::STCurrency::getSType
SerializedTypeID getSType() const override
Definition: STCurrency.cpp:42
ripple::STCurrency::copy
STBase * copy(std::size_t n, void *buf) const override
Definition: STCurrency.cpp:84
ripple::STCurrency::value
Currency const & value() const noexcept
Definition: STCurrency.h:95
ripple::STBase::operator==
bool operator==(const STBase &t) const
Definition: STBase.cpp:45
ripple::STCurrency::currency
Currency const & currency() const
Definition: STCurrency.h:89
ripple::STCurrency::getJson
Json::Value getJson(JsonOptions) const override
Definition: STCurrency.cpp:53