xrpld
Loading...
Searching...
No Matches
STBase.cpp
1#include <xrpl/protocol/STBase.h>
2
3#include <xrpl/beast/utility/instrumentation.h>
4#include <xrpl/json/json_value.h>
5#include <xrpl/protocol/SField.h>
6#include <xrpl/protocol/Serializer.h>
7
8#include <cstddef>
9#include <ostream>
10#include <string>
11#include <utility>
12
13namespace xrpl {
14
18
20{
21 XRPL_ASSERT(fName_, "xrpl::STBase::STBase : field is set");
22}
23
24STBase&
26{
27 if (this == &t)
28 return *this;
29
30 if (!fName_->isUseful())
31 fName_ = t.fName_;
32 return *this;
33}
34
35bool
37{
38 return (getSType() == t.getSType()) && isEquivalent(t);
39}
40
41bool
43{
44 return (getSType() != t.getSType()) || !isEquivalent(t);
45}
46
47STBase*
48STBase::copy(std::size_t n, void* buf) const
49{
50 return emplace(n, buf, *this);
51}
52
53STBase*
55{
56 return emplace(n, buf, std::move(*this));
57}
58
61{
62 return STI_NOTPRESENT;
63}
64
67{
68 std::string ret;
69
70 if (getSType() != STI_NOTPRESENT)
71 {
72 if (fName_->hasName())
73 {
74 ret = fName_->fieldName;
75 ret += " = ";
76 }
77
78 ret += getText();
79 }
80
81 return ret;
82}
83
86{
87 return std::string();
88}
89
91STBase::getJson(JsonOptions /*options*/) const
92{
93 return getText();
94}
95
96void
98{
99 // Should never be called
100 // LCOV_EXCL_START
101 UNREACHABLE("xrpl::STBase::add : not implemented");
102 // LCOV_EXCL_STOP
103}
104
105bool
107{
108 XRPL_ASSERT(getSType() == STI_NOTPRESENT, "xrpl::STBase::isEquivalent : type not present");
109 return t.getSType() == STI_NOTPRESENT;
110}
111
112bool
114{
115 return true;
116}
117
118void
120{
121 fName_ = &n;
122 XRPL_ASSERT(fName_, "xrpl::STBase::setFName : field is set");
123}
124
125SField const&
128 return *fName_;
129}
131void
133{
134 XRPL_ASSERT(fName_->isBinary(), "xrpl::STBase::addFieldID : field is binary");
135 s.addFieldID(fName_->fieldType, fName_->fieldValue);
136}
137
138//------------------------------------------------------------------------------
139
141operator<<(std::ostream& out, STBase const& t)
142{
143 return out << t.getFullText();
144}
145
146} // namespace xrpl
Represents a JSON value.
Definition json_value.h:130
Identifies fields.
Definition SField.h:130
A type which can be exported to a well known binary format.
Definition STBase.h:117
SField const & getFName() const
Definition STBase.cpp:126
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition STBase.h:215
virtual bool isEquivalent(STBase const &t) const
Definition STBase.cpp:106
virtual std::string getFullText() const
Definition STBase.cpp:66
STBase & operator=(STBase const &t)
Definition STBase.cpp:25
bool operator!=(STBase const &t) const
Definition STBase.cpp:42
virtual STBase * copy(std::size_t n, void *buf) const
Definition STBase.cpp:48
virtual SerializedTypeID getSType() const
Definition STBase.cpp:60
SField const * fName_
Definition STBase.h:118
void setFName(SField const &n)
A STBase is a field.
Definition STBase.cpp:119
virtual bool isDefault() const
Definition STBase.cpp:113
bool operator==(STBase const &t) const
Definition STBase.cpp:36
virtual json::Value getJson(JsonOptions=JsonOptions::Values::None) const
Definition STBase.cpp:91
virtual STBase * move(std::size_t n, void *buf)
Definition STBase.cpp:54
virtual std::string getText() const
Definition STBase.cpp:85
void addFieldID(Serializer &s) const
Definition STBase.cpp:132
virtual void add(Serializer &s) const
Definition STBase.cpp:97
int addFieldID(int type, int name)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
SField const sfGeneric
std::ostream & operator<<(std::ostream &out, BaseUInt< Bits, Tag > const &u)
Definition base_uint.h:648
SerializedTypeID
Definition SField.h:93
Note, should be treated as flags that can be | and &.
Definition STBase.h:17