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