xrpld
Loading...
Searching...
No Matches
STArray.h
1#pragma once
2
3#include <xrpl/basics/CountedObject.h>
4#include <xrpl/protocol/STObject.h>
5
6namespace xrpl {
7
8class STArray final : public STBase, public CountedObject<STArray>
9{
10private:
12
14
15public:
17 using size_type = list_type::size_type;
18 using iterator = list_type::iterator;
19 using const_iterator = list_type::const_iterator;
20
21 STArray() = default;
22 STArray(STArray const&) = default;
23
24 template <
25 class Iter,
26 class = std::enable_if_t<
28 explicit STArray(Iter first, Iter last);
29
30 template <
31 class Iter,
32 class = std::enable_if_t<
34 STArray(SField const& f, Iter first, Iter last);
35
36 STArray&
37 operator=(STArray const&) = default;
39 STArray&
41
42 STArray(SField const& f, std::size_t n);
43 STArray(SerialIter& sit, SField const& f, int depth = 0);
44 explicit STArray(int n);
45 explicit STArray(SField const& f);
46
49
50 STObject const&
51 operator[](std::size_t j) const;
52
54 back();
55
56 [[nodiscard]] STObject const&
57 back() const;
58
59 template <class... Args>
60 void
61 emplaceBack(Args&&... args);
62
63 void
64 pushBack(STObject const& object);
65
66 void
67 pushBack(STObject&& object);
68
69 // STL-compatible alias required by std::back_insert_iterator
70 void
71 // NOLINTNEXTLINE(readability-identifier-naming)
72 push_back(STObject const& object)
73 {
74 pushBack(object);
75 }
76
77 void
78 // NOLINTNEXTLINE(readability-identifier-naming)
80 {
81 pushBack(std::move(object));
82 }
83
85 begin();
86
88 end();
89
90 [[nodiscard]] const_iterator
91 begin() const;
92
93 [[nodiscard]] const_iterator
94 end() const;
95
96 [[nodiscard]] size_type
97 size() const;
98
99 [[nodiscard]] bool
100 empty() const;
101
102 void
103 clear();
104
105 void
107
108 void
109 swap(STArray& a) noexcept;
110
111 [[nodiscard]] std::string
112 getFullText() const override;
113
114 [[nodiscard]] std::string
115 getText() const override;
116
117 [[nodiscard]] json::Value
118 getJson(JsonOptions index) const override;
119
120 void
121 add(Serializer& s) const override;
122
123 void
124 sort(bool (*compare)(STObject const& o1, STObject const& o2));
125
126 bool
127 operator==(STArray const& s) const;
128
129 bool
130 operator!=(STArray const& s) const;
131
133 erase(iterator pos);
134
137
139 erase(iterator first, iterator last);
140
143
144 [[nodiscard]] SerializedTypeID
145 getSType() const override;
146
147 [[nodiscard]] bool
148 isEquivalent(STBase const& t) const override;
149
150 [[nodiscard]] bool
151 isDefault() const override;
152
153private:
154 STBase*
155 copy(std::size_t n, void* buf) const override;
156 STBase*
157 move(std::size_t n, void* buf) override;
158
159 friend class detail::STVar;
160};
161
162template <class Iter, class>
163STArray::STArray(Iter first, Iter last) : v_(first, last)
164{
165}
166
167template <class Iter, class>
168STArray::STArray(SField const& f, Iter first, Iter last) : STBase(f), v_(first, last)
169{
170}
171
172inline STObject&
174{
175 return v_[j];
176}
177
178inline STObject const&
180{
181 return v_[j];
182}
183
184inline STObject&
186{
187 return v_.back();
188}
189
190inline STObject const&
192{
193 return v_.back();
194}
195
196template <class... Args>
197inline void
198STArray::emplaceBack(Args&&... args)
199{
200 v_.emplace_back(std::forward<Args>(args)...);
201}
202
203inline void
205{
206 v_.push_back(object);
207}
208
209inline void
211{
212 v_.push_back(std::move(object));
213}
214
217{
218 return v_.begin();
219}
220
223{
224 return v_.end();
225}
226
229{
230 return v_.begin();
231}
232
235{
236 return v_.end();
237}
238
241{
242 return v_.size();
243}
244
245inline bool
247{
248 return v_.empty();
249}
250
251inline void
253{
254 v_.clear();
255}
256
257inline void
259{
260 v_.reserve(n);
261}
262
263inline void
265{
266 v_.swap(a.v_);
267}
268
269inline bool
271{
272 return v_ == s.v_;
273}
274
275inline bool
277{
278 return v_ != s.v_;
279}
280
283{
284 return v_.erase(pos);
285}
286
289{
290 return v_.erase(pos);
291}
292
295{
296 return v_.erase(first, last);
297}
298
301{
302 return v_.erase(first, last);
303}
304
305} // namespace xrpl
Represents a JSON value.
Definition json_value.h:130
Identifies fields.
Definition SField.h:130
STArray & operator=(STArray const &)=default
void emplaceBack(Args &&... args)
Definition STArray.h:198
STArray()=default
std::string getFullText() const override
Definition STArray.cpp:93
STObject value_type
Definition STArray.h:16
bool isEquivalent(STBase const &t) const override
Definition STArray.cpp:163
list_type::const_iterator const_iterator
Definition STArray.h:19
void clear()
Definition STArray.h:252
bool operator==(STArray const &s) const
Definition STArray.h:270
std::vector< STObject > list_type
Definition STArray.h:11
STBase * copy(std::size_t n, void *buf) const override
Definition STArray.cpp:81
list_type::size_type size_type
Definition STArray.h:17
void push_back(STObject const &object)
Definition STArray.h:72
STArray(STArray const &)=default
std::string getText() const override
Definition STArray.cpp:112
list_type v_
Definition STArray.h:13
void swap(STArray &a) noexcept
Definition STArray.h:264
SerializedTypeID getSType() const override
Definition STArray.cpp:157
size_type size() const
Definition STArray.h:240
void add(Serializer &s) const override
Definition STArray.cpp:146
void reserve(std::size_t n)
Definition STArray.h:258
iterator begin()
Definition STArray.h:216
bool operator!=(STArray const &s) const
Definition STArray.h:276
bool isDefault() const override
Definition STArray.cpp:170
STBase * move(std::size_t n, void *buf) override
Definition STArray.cpp:87
iterator erase(iterator pos)
Definition STArray.h:282
void sort(bool(*compare)(STObject const &o1, STObject const &o2))
Definition STArray.cpp:176
json::Value getJson(JsonOptions index) const override
Definition STArray.cpp:131
list_type::iterator iterator
Definition STArray.h:18
void push_back(STObject &&object)
Definition STArray.h:79
bool empty() const
Definition STArray.h:246
void pushBack(STObject const &object)
Definition STArray.h:204
iterator end()
Definition STArray.h:222
STObject & back()
Definition STArray.h:185
STObject & operator[](std::size_t j)
Definition STArray.h:173
A type which can be exported to a well known binary format.
Definition STBase.h:117
T forward(T... args)
T is_convertible_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
Dir::ConstIterator const_iterator
Definition Dir.cpp:16
SerializedTypeID
Definition SField.h:93
Note, should be treated as flags that can be | and &.
Definition STBase.h:17