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