rippled
Loading...
Searching...
No Matches
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 <xrpl/basics/CountedObject.h>
24#include <xrpl/protocol/SField.h>
25#include <xrpl/protocol/STBase.h>
26#include <xrpl/protocol/Serializer.h>
27#include <xrpl/protocol/UintTypes.h>
28
29namespace ripple {
30
31class STCurrency final : public STBase
32{
33private:
35
36public:
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(STBase const& t) const override;
69
70 bool
71 isDefault() const override;
72
73private:
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
86currencyFromJson(SField const& name, Json::Value const& v);
87
88inline Currency const&
90{
91 return currency_;
92}
93
94inline Currency const&
95STCurrency::value() const noexcept
96{
97 return currency_;
98}
99
100inline void
105
106inline bool
107operator==(STCurrency const& lhs, STCurrency const& rhs)
108{
109 return lhs.currency() == rhs.currency();
110}
111
112inline bool
113operator!=(STCurrency const& lhs, STCurrency const& rhs)
114{
115 return !operator==(lhs, rhs);
116}
117
118inline bool
119operator<(STCurrency const& lhs, STCurrency const& rhs)
120{
121 return lhs.currency() < rhs.currency();
122}
123
124inline bool
125operator==(STCurrency const& lhs, Currency const& rhs)
126{
127 return lhs.currency() == rhs;
128}
129
130inline bool
131operator<(STCurrency const& lhs, Currency const& rhs)
132{
133 return lhs.currency() < rhs;
134}
135
136} // namespace ripple
137
138#endif
Identifies fields.
Definition SField.h:146
A type which can be exported to a well known binary format.
Definition STBase.h:135
bool operator==(STBase const &t) const
Definition STBase.cpp:51
bool operator!=(STBase const &t) const
Definition STBase.cpp:57
Currency const & value() const noexcept
Definition STCurrency.h:95
bool isEquivalent(STBase const &t) const override
bool isDefault() const override
friend class detail::STVar
Definition STCurrency.h:82
void add(Serializer &s) const override
SerializedTypeID getSType() const override
Json::Value getJson(JsonOptions) const override
STCurrency()=default
std::string getText() const override
static std::unique_ptr< STCurrency > construct(SerialIter &, SField const &name)
STBase * move(std::size_t n, void *buf) override
STBase * copy(std::size_t n, void *buf) const override
Currency const & currency() const
Definition STCurrency.h:89
void setCurrency(Currency const &currency)
Definition STCurrency.h:101
JSON (JavaScript Object Notation).
Definition json_errors.h:25
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
STCurrency currencyFromJson(SField const &name, Json::Value const &v)
SerializedTypeID
Definition SField.h:110
base_uint< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Definition UintTypes.h:56
bool operator<(Slice const &lhs, Slice const &rhs) noexcept
Definition Slice.h:223
STL namespace.
Note, should be treated as flags that can be | and &.
Definition STBase.h:37