rippled
STIssue.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_STISSUE_H_INCLUDED
21 #define RIPPLE_PROTOCOL_STISSUE_H_INCLUDED
22 
23 #include <ripple/basics/CountedObject.h>
24 #include <ripple/protocol/Issue.h>
25 #include <ripple/protocol/SField.h>
26 #include <ripple/protocol/STBase.h>
27 #include <ripple/protocol/Serializer.h>
28 
29 namespace ripple {
30 
31 class STIssue final : public STBase
32 {
33 private:
35 
36 public:
37  using value_type = Issue;
38 
39  STIssue() = default;
40 
41  explicit STIssue(SerialIter& sit, SField const& name);
42 
43  explicit STIssue(SField const& name, Issue const& issue);
44 
45  explicit STIssue(SField const& name);
46 
47  Issue const&
48  issue() const;
49 
50  Issue const&
51  value() const noexcept;
52 
53  void
54  setIssue(Issue const& issue);
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<STIssue>
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 
85 STIssue
86 issueFromJson(SField const& name, Json::Value const& v);
87 
88 inline Issue const&
89 STIssue::issue() const
90 {
91  return issue_;
92 }
93 
94 inline Issue const&
95 STIssue::value() const noexcept
96 {
97  return issue_;
98 }
99 
100 inline void
102 {
103  issue_ = issue;
104 }
105 
106 inline bool
107 operator==(STIssue const& lhs, STIssue const& rhs)
108 {
109  return lhs.issue() == rhs.issue();
110 }
111 
112 inline bool
113 operator!=(STIssue const& lhs, STIssue const& rhs)
114 {
115  return !operator==(lhs, rhs);
116 }
117 
118 inline bool
119 operator<(STIssue const& lhs, STIssue const& rhs)
120 {
121  return lhs.issue() < rhs.issue();
122 }
123 
124 inline bool
125 operator==(STIssue const& lhs, Issue const& rhs)
126 {
127  return lhs.issue() == rhs;
128 }
129 
130 inline bool
131 operator<(STIssue const& lhs, Issue const& rhs)
132 {
133  return lhs.issue() < rhs;
134 }
135 
136 } // namespace ripple
137 
138 #endif
ripple::STIssue::issue_
Issue issue_
Definition: STIssue.h:34
ripple::STIssue::add
void add(Serializer &s) const override
Definition: STIssue.cpp:69
ripple::STIssue::issue
Issue const & issue() const
Definition: STIssue.h:89
ripple::Issue
A currency issued by an account.
Definition: Issue.h:35
ripple::JsonOptions
JsonOptions
Definition: STBase.h:34
ripple::STIssue::copy
STBase * copy(std::size_t n, void *buf) const override
Definition: STIssue.cpp:96
ripple::STIssue::STIssue
STIssue()=default
ripple::STIssue::getSType
SerializedTypeID getSType() const override
Definition: STIssue.cpp:52
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:54
ripple::STIssue::getJson
Json::Value getJson(JsonOptions) const override
Definition: STIssue.cpp:63
Json
JSON (JavaScript Object Notation).
Definition: json_reader.cpp:29
ripple::operator<
bool operator<(CanonicalTXSet::Key const &lhs, CanonicalTXSet::Key const &rhs)
Definition: CanonicalTXSet.cpp:25
ripple::STIssue::isEquivalent
bool isEquivalent(const STBase &t) const override
Definition: STIssue.cpp:77
ripple::SerialIter
Definition: Serializer.h:311
ripple::issueFromJson
Issue issueFromJson(Json::Value const &v)
Definition: Issue.cpp:78
ripple::STIssue::value
Issue const & value() const noexcept
Definition: STIssue.h:95
ripple::STIssue::construct
static std::unique_ptr< STIssue > construct(SerialIter &, SField const &name)
Definition: STIssue.cpp:90
ripple::STIssue
Definition: STIssue.h:31
ripple::Serializer
Definition: Serializer.h:40
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::SField
Identifies fields.
Definition: SField.h:115
ripple::STBase
A type which can be exported to a well known binary format.
Definition: STBase.h:66
ripple::STBase::operator!=
bool operator!=(const STBase &t) const
Definition: STBase.cpp:51
ripple::STIssue::setIssue
void setIssue(Issue const &issue)
Definition: STIssue.h:101
std
STL namespace.
ripple::xrpIssue
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
Definition: Issue.h:105
ripple::STBase::operator==
bool operator==(const STBase &t) const
Definition: STBase.cpp:45
ripple::STIssue::getText
std::string getText() const override
Definition: STIssue.cpp:58
ripple::STIssue::isDefault
bool isDefault() const override
Definition: STIssue.cpp:84
ripple::STIssue::move
STBase * move(std::size_t n, void *buf) override
Definition: STIssue.cpp:102