xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
protocol
SOTemplate.h
1
#pragma once
2
3
#include <xrpl/basics/contract.h>
4
#include <xrpl/protocol/SField.h>
5
6
#include <
cstddef
>
7
#include <
functional
>
8
#include <
initializer_list
>
9
#include <
stdexcept
>
10
#include <
string
>
11
#include <
vector
>
12
13
namespace
xrpl
{
14
18
// 2026 usages, 129 files
19
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
20
enum
SOEStyle
{
21
SoeInvalid
= -1,
22
SoeRequired
= 0,
// required
23
SoeOptional
= 1,
// optional, may be present with default value
24
SoeDefault
= 2,
// optional, if present, must not have default value
25
// inner object with the default fields has to be
26
// constructed with STObject::makeInnerObject()
27
};
28
29
// Part of a Python-parsed DSL (transactions.macro); bare enumerator names required by the parser
33
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
34
enum
SOETxMPTIssue
{
SoeMptNone
,
SoeMptSupported
,
SoeMptNotSupported
};
35
36
//------------------------------------------------------------------------------
37
41
class
SOElement
42
{
43
// Use std::reference_wrapper so SOElement can be stored in a std::vector.
44
std::reference_wrapper<SField const>
sField_
;
45
SOEStyle
style_
;
46
SOETxMPTIssue
supportMpt_
=
SoeMptNone
;
47
48
private
:
49
void
50
init
(
SField
const
& fieldName)
const
51
{
52
if
(!
sField_
.get().isUseful())
53
{
54
auto
nm =
std::to_string
(fieldName.
getCode
());
55
if
(fieldName.
hasName
())
56
nm +=
": '"
+ fieldName.
getName
() +
"'"
;
57
Throw<std::runtime_error>
(
"SField ("
+ nm +
") in SOElement must be useful."
);
58
}
59
}
60
61
public
:
62
SOElement
(
SField
const
& fieldName,
SOEStyle
style
) :
sField_
(fieldName),
style_
(
style
)
63
{
64
init
(fieldName);
65
}
66
67
template
<
typename
T>
68
requires
(
std::is_same_v<T, STAmount>
||
std::is_same_v<T, STIssue>
)
69
SOElement
(
70
TypedField<T>
const
& fieldName,
71
SOEStyle
style
,
72
SOETxMPTIssue
supportMpt =
SoeMptNotSupported
)
73
:
sField_
(fieldName),
style_
(
style
),
supportMpt_
(supportMpt)
74
{
75
init
(fieldName);
76
}
77
78
[[nodiscard]]
SField
const
&
79
sField
()
const
80
{
81
return
sField_
.get();
82
}
83
84
[[nodiscard]]
SOEStyle
85
style
()
const
86
{
87
return
style_
;
88
}
89
90
[[nodiscard]]
SOETxMPTIssue
91
supportMPT
()
const
92
{
93
return
supportMpt_
;
94
}
95
};
96
97
//------------------------------------------------------------------------------
98
104
class
SOTemplate
105
{
106
public
:
107
// Copying vectors is expensive. Make this a move-only type until
108
// there is motivation to change that.
109
SOTemplate
(
SOTemplate
&& other) =
default
;
110
SOTemplate
&
111
operator=
(
SOTemplate
&& other) =
default
;
112
117
SOTemplate
(
std::vector<SOElement>
uniqueFields,
std::vector<SOElement>
commonFields = {});
118
123
SOTemplate
(
124
std::initializer_list<SOElement>
uniqueFields,
125
std::initializer_list<SOElement>
commonFields = {});
126
127
/* Provide for the enumeration of fields */
128
[[nodiscard]] std::vector<SOElement>::const_iterator
129
begin
()
const
130
{
131
return
elements_
.cbegin();
132
}
133
134
[[nodiscard]] std::vector<SOElement>::const_iterator
135
cbegin
()
const
136
{
137
return
begin
();
138
}
139
140
[[nodiscard]] std::vector<SOElement>::const_iterator
141
end
()
const
142
{
143
return
elements_
.cend();
144
}
145
146
[[nodiscard]] std::vector<SOElement>::const_iterator
147
cend
()
const
148
{
149
return
end
();
150
}
151
155
[[nodiscard]]
std::size_t
156
size
()
const
157
{
158
return
elements_
.size();
159
}
160
164
[[nodiscard]]
int
165
getIndex
(
SField
const
&)
const
;
166
167
[[nodiscard]]
SOEStyle
168
style
(
SField
const
& sf)
const
169
{
170
return
elements_
[
indices_
[sf.
getNum
()]].style();
171
}
172
173
private
:
174
std::vector<SOElement>
elements_
;
175
std::vector<int>
indices_
;
// field num -> index
176
};
177
178
}
// namespace xrpl
xrpl::SField
Identifies fields.
Definition
SField.h:132
xrpl::SField::hasName
bool hasName() const
Definition
SField.h:204
xrpl::SField::getCode
int getCode() const
Definition
SField.h:249
xrpl::SField::getNum
int getNum() const
Definition
SField.h:254
xrpl::SField::getName
std::string const & getName() const
Definition
SField.h:198
xrpl::SOElement::init
void init(SField const &fieldName) const
Definition
SOTemplate.h:50
xrpl::SOElement::style_
SOEStyle style_
Definition
SOTemplate.h:45
xrpl::SOElement::supportMPT
SOETxMPTIssue supportMPT() const
Definition
SOTemplate.h:91
xrpl::SOElement::supportMpt_
SOETxMPTIssue supportMpt_
Definition
SOTemplate.h:46
xrpl::SOElement::SOElement
SOElement(TypedField< T > const &fieldName, SOEStyle style, SOETxMPTIssue supportMpt=SoeMptNotSupported)
Definition
SOTemplate.h:69
xrpl::SOElement::sField
SField const & sField() const
Definition
SOTemplate.h:79
xrpl::SOElement::sField_
std::reference_wrapper< SField const > sField_
Definition
SOTemplate.h:44
xrpl::SOElement::style
SOEStyle style() const
Definition
SOTemplate.h:85
xrpl::SOElement::SOElement
SOElement(SField const &fieldName, SOEStyle style)
Definition
SOTemplate.h:62
xrpl::SOTemplate::indices_
std::vector< int > indices_
Definition
SOTemplate.h:175
xrpl::SOTemplate::getIndex
int getIndex(SField const &) const
Retrieve the position of a named field.
Definition
SOTemplate.cpp:55
xrpl::SOTemplate::end
std::vector< SOElement >::const_iterator end() const
Definition
SOTemplate.h:141
xrpl::SOTemplate::SOTemplate
SOTemplate(SOTemplate &&other)=default
xrpl::SOTemplate::cend
std::vector< SOElement >::const_iterator cend() const
Definition
SOTemplate.h:147
xrpl::SOTemplate::style
SOEStyle style(SField const &sf) const
Definition
SOTemplate.h:168
xrpl::SOTemplate::size
std::size_t size() const
The number of entries in this template.
Definition
SOTemplate.h:156
xrpl::SOTemplate::cbegin
std::vector< SOElement >::const_iterator cbegin() const
Definition
SOTemplate.h:135
xrpl::SOTemplate::begin
std::vector< SOElement >::const_iterator begin() const
Definition
SOTemplate.h:129
xrpl::SOTemplate::elements_
std::vector< SOElement > elements_
Definition
SOTemplate.h:174
xrpl::SOTemplate::operator=
SOTemplate & operator=(SOTemplate &&other)=default
cstddef
functional
initializer_list
std::is_same_v
T is_same_v
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::SOEStyle
SOEStyle
Kind of element in each entry of an SOTemplate.
Definition
SOTemplate.h:20
xrpl::SoeDefault
@ SoeDefault
Definition
SOTemplate.h:24
xrpl::SoeInvalid
@ SoeInvalid
Definition
SOTemplate.h:21
xrpl::SoeOptional
@ SoeOptional
Definition
SOTemplate.h:23
xrpl::SoeRequired
@ SoeRequired
Definition
SOTemplate.h:22
xrpl::SOETxMPTIssue
SOETxMPTIssue
Amount fields that can support MPT.
Definition
SOTemplate.h:34
xrpl::SoeMptNotSupported
@ SoeMptNotSupported
Definition
SOTemplate.h:34
xrpl::SoeMptNone
@ SoeMptNone
Definition
SOTemplate.h:34
xrpl::SoeMptSupported
@ SoeMptSupported
Definition
SOTemplate.h:34
xrpl::Throw
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition
contract.h:52
std::reference_wrapper
std::size_t
stdexcept
string
xrpl::TypedField
A field with a type known at compile time.
Definition
SField.h:308
std::to_string
T to_string(T... args)
vector
Generated by
1.17.0