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
41STBase*
42STBase::copy(std::size_t n, void* buf) const
43{
44 return emplace(n, buf, *this);
45}
46
47STBase*
49{
50 return emplace(n, buf, std::move(*this));
51}
52
55{
56 return STI_NOTPRESENT;
57}
58
61{
62 std::string ret;
63
64 if (getSType() != STI_NOTPRESENT)
65 {
66 if (fName_->hasName())
67 {
68 ret = fName_->fieldName;
69 ret += " = ";
70 }
71
72 ret += getText();
73 }
74
75 return ret;
76}
77
80{
81 return std::string();
82}
83
85STBase::getJson(JsonOptions /*options*/) const
86{
87 return getText();
88}
89
90void
92{
93 // Should never be called
94 // LCOV_EXCL_START
95 UNREACHABLE("xrpl::STBase::add : not implemented");
96 // LCOV_EXCL_STOP
97}
98
99bool
101{
102 XRPL_ASSERT(getSType() == STI_NOTPRESENT, "xrpl::STBase::isEquivalent : type not present");
103 return t.getSType() == STI_NOTPRESENT;
104}
105
106bool
108{
109 return true;
110}
111
112void
114{
115 fName_ = &n;
116 XRPL_ASSERT(fName_, "xrpl::STBase::setFName : field is set");
117}
118
119SField const&
121{
122 return *fName_;
123}
124
125void
127{
128 XRPL_ASSERT(fName_->isBinary(), "xrpl::STBase::addFieldID : field is binary");
129 s.addFieldID(fName_->fieldType, fName_->fieldValue);
130}
131
132//------------------------------------------------------------------------------
133
135operator<<(std::ostream& out, STBase const& t)
136{
137 return out << t.getFullText();
138}
140} // namespace xrpl
Represents a JSON value.
Definition json_value.h:117
Identifies fields.
Definition SField.h:132
A type which can be exported to a well known binary format.
Definition STBase.h:129
SField const & getFName() const
Definition STBase.cpp:120
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition STBase.h:226
virtual bool isEquivalent(STBase const &t) const
Definition STBase.cpp:100
virtual std::string getFullText() const
Definition STBase.cpp:60
STBase & operator=(STBase const &t)
Definition STBase.cpp:25
virtual STBase * copy(std::size_t n, void *buf) const
Definition STBase.cpp:42
virtual SerializedTypeID getSType() const
Definition STBase.cpp:54
SField const * fName_
Definition STBase.h:130
void setFName(SField const &n)
A STBase is a field.
Definition STBase.cpp:113
virtual bool isDefault() const
Definition STBase.cpp:107
bool operator==(STBase const &t) const
Definition STBase.cpp:36
virtual json::Value getJson(JsonOptions=JsonOptions::Values::None) const
Definition STBase.cpp:85
virtual STBase * move(std::size_t n, void *buf)
Definition STBase.cpp:48
virtual std::string getText() const
Definition STBase.cpp:79
void addFieldID(Serializer &s) const
Definition STBase.cpp:126
virtual void add(Serializer &s) const
Definition STBase.cpp:91
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:666
SerializedTypeID
Definition SField.h:94
Note, should be treated as flags that can be | and &.
Definition STBase.h:22