xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
protocol
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
13
namespace
xrpl
{
14
15
STBase::STBase
() :
fName_
(&
sfGeneric
)
16
{
17
}
18
19
STBase::STBase
(
SField
const
& n) :
fName_
(&n)
20
{
21
XRPL_ASSERT(
fName_
,
"xrpl::STBase::STBase : field is set"
);
22
}
23
24
STBase
&
25
STBase::operator=
(
STBase
const
& t)
26
{
27
if
(
this
== &t)
28
return
*
this
;
29
30
if
(!
fName_
->isUseful())
31
fName_
= t.
fName_
;
32
return
*
this
;
33
}
34
35
bool
36
STBase::operator==
(
STBase
const
& t)
const
37
{
38
return
(
getSType
() == t.
getSType
()) &&
isEquivalent
(t);
39
}
40
41
STBase
*
42
STBase::copy
(
std::size_t
n,
void
* buf)
const
43
{
44
return
emplace
(n, buf, *
this
);
45
}
46
47
STBase
*
48
STBase::move
(
std::size_t
n,
void
* buf)
49
{
50
return
emplace
(n, buf, std::move(*
this
));
51
}
52
53
SerializedTypeID
54
STBase::getSType
()
const
55
{
56
return
STI_NOTPRESENT;
57
}
58
59
std::string
60
STBase::getFullText
()
const
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
78
std::string
79
STBase::getText
()
const
80
{
81
return
std::string
();
82
}
83
84
json::Value
85
STBase::getJson
(
JsonOptions
/*options*/
)
const
86
{
87
return
getText
();
88
}
89
90
void
91
STBase::add
(
Serializer
& s)
const
92
{
93
// Should never be called
94
// LCOV_EXCL_START
95
UNREACHABLE(
"xrpl::STBase::add : not implemented"
);
96
// LCOV_EXCL_STOP
97
}
98
99
bool
100
STBase::isEquivalent
(
STBase
const
& t)
const
101
{
102
XRPL_ASSERT(
getSType
() == STI_NOTPRESENT,
"xrpl::STBase::isEquivalent : type not present"
);
103
return
t.
getSType
() == STI_NOTPRESENT;
104
}
105
106
bool
107
STBase::isDefault
()
const
108
{
109
return
true
;
110
}
111
112
void
113
STBase::setFName
(
SField
const
& n)
114
{
115
fName_
= &n;
116
XRPL_ASSERT(
fName_
,
"xrpl::STBase::setFName : field is set"
);
117
}
118
119
SField
const
&
120
STBase::getFName
()
const
121
{
122
return
*
fName_
;
123
}
124
125
void
126
STBase::addFieldID
(
Serializer
& s)
const
127
{
128
XRPL_ASSERT(
fName_
->isBinary(),
"xrpl::STBase::addFieldID : field is binary"
);
129
s.
addFieldID
(
fName_
->fieldType,
fName_
->fieldValue);
130
}
131
132
//------------------------------------------------------------------------------
133
134
std::ostream
&
135
operator<<
(
std::ostream
& out,
STBase
const
& t)
136
{
137
return
out << t.
getFullText
();
138
}
139
140
}
// namespace xrpl
std::ostream
std::string
json::Value
Represents a JSON value.
Definition
json_value.h:117
xrpl::SField
Identifies fields.
Definition
SField.h:132
xrpl::STBase
A type which can be exported to a well known binary format.
Definition
STBase.h:129
xrpl::STBase::getFName
SField const & getFName() const
Definition
STBase.cpp:120
xrpl::STBase::emplace
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition
STBase.h:226
xrpl::STBase::isEquivalent
virtual bool isEquivalent(STBase const &t) const
Definition
STBase.cpp:100
xrpl::STBase::getFullText
virtual std::string getFullText() const
Definition
STBase.cpp:60
xrpl::STBase::operator=
STBase & operator=(STBase const &t)
Definition
STBase.cpp:25
xrpl::STBase::STBase
STBase()
Definition
STBase.cpp:15
xrpl::STBase::copy
virtual STBase * copy(std::size_t n, void *buf) const
Definition
STBase.cpp:42
xrpl::STBase::getSType
virtual SerializedTypeID getSType() const
Definition
STBase.cpp:54
xrpl::STBase::fName_
SField const * fName_
Definition
STBase.h:130
xrpl::STBase::setFName
void setFName(SField const &n)
A STBase is a field.
Definition
STBase.cpp:113
xrpl::STBase::isDefault
virtual bool isDefault() const
Definition
STBase.cpp:107
xrpl::STBase::operator==
bool operator==(STBase const &t) const
Definition
STBase.cpp:36
xrpl::STBase::getJson
virtual json::Value getJson(JsonOptions=JsonOptions::Values::None) const
Definition
STBase.cpp:85
xrpl::STBase::move
virtual STBase * move(std::size_t n, void *buf)
Definition
STBase.cpp:48
xrpl::STBase::getText
virtual std::string getText() const
Definition
STBase.cpp:79
xrpl::STBase::addFieldID
void addFieldID(Serializer &s) const
Definition
STBase.cpp:126
xrpl::STBase::add
virtual void add(Serializer &s) const
Definition
STBase.cpp:91
xrpl::STTakesAsset::STBase
STBase()
Definition
STBase.cpp:15
xrpl::Serializer
Definition
Serializer.h:23
xrpl::Serializer::addFieldID
int addFieldID(int type, int name)
Definition
libxrpl/protocol/Serializer.cpp:107
cstddef
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::sfGeneric
SField const sfGeneric
xrpl::operator<<
std::ostream & operator<<(std::ostream &out, BaseUInt< Bits, Tag > const &u)
Definition
base_uint.h:672
xrpl::SerializedTypeID
SerializedTypeID
Definition
SField.h:94
ostream
std::size_t
string
xrpl::JsonOptions
Note, should be treated as flags that can be | and &.
Definition
STBase.h:22
utility
Generated by
1.17.0