rippled
Loading...
Searching...
No Matches
STArray.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_PROTOCOL_STARRAY_H_INCLUDED
21#define RIPPLE_PROTOCOL_STARRAY_H_INCLUDED
22
23#include <xrpl/basics/CountedObject.h>
24#include <xrpl/protocol/STObject.h>
25
26namespace ripple {
27
28class STArray final : public STBase, public CountedObject<STArray>
29{
30private:
32
34
35public:
37 using size_type = list_type::size_type;
38 using iterator = list_type::iterator;
39 using const_iterator = list_type::const_iterator;
40
41 STArray() = default;
42 STArray(STArray const&) = default;
43
44 template <
45 class Iter,
48 STObject>>>
49 explicit STArray(Iter first, Iter last);
50
51 template <
52 class Iter,
55 STObject>>>
56 STArray(SField const& f, Iter first, Iter last);
57
58 STArray&
59 operator=(STArray const&) = default;
61 STArray&
63
64 STArray(SField const& f, std::size_t n);
65 STArray(SerialIter& sit, SField const& f, int depth = 0);
66 explicit STArray(int n);
67 explicit STArray(SField const& f);
68
71
72 STObject const&
73 operator[](std::size_t j) const;
74
76 back();
77
78 STObject const&
79 back() const;
80
81 template <class... Args>
82 void
83 emplace_back(Args&&... args);
84
85 void
86 push_back(STObject const& object);
87
88 void
89 push_back(STObject&& object);
90
92 begin();
93
95 end();
96
98 begin() const;
99
101 end() const;
102
104 size() const;
105
106 bool
107 empty() const;
108
109 void
110 clear();
111
112 void
114
115 void
116 swap(STArray& a) noexcept;
117
119 getFullText() const override;
120
122 getText() const override;
123
125 getJson(JsonOptions index) const override;
126
127 void
128 add(Serializer& s) const override;
129
130 void
131 sort(bool (*compare)(STObject const& o1, STObject const& o2));
132
133 bool
134 operator==(STArray const& s) const;
135
136 bool
137 operator!=(STArray const& s) const;
138
140 erase(iterator pos);
141
144
146 erase(iterator first, iterator last);
147
150
152 getSType() const override;
153
154 bool
155 isEquivalent(STBase const& t) const override;
156
157 bool
158 isDefault() const override;
159
160private:
161 STBase*
162 copy(std::size_t n, void* buf) const override;
163 STBase*
164 move(std::size_t n, void* buf) override;
165
166 friend class detail::STVar;
167};
168
169template <class Iter, class>
170STArray::STArray(Iter first, Iter last) : v_(first, last)
171{
172}
173
174template <class Iter, class>
175STArray::STArray(SField const& f, Iter first, Iter last)
176 : STBase(f), v_(first, last)
177{
178}
179
180inline STObject&
182{
183 return v_[j];
184}
185
186inline STObject const&
188{
189 return v_[j];
190}
191
192inline STObject&
194{
195 return v_.back();
196}
197
198inline STObject const&
200{
201 return v_.back();
202}
203
204template <class... Args>
205inline void
207{
209}
210
211inline void
213{
214 v_.push_back(object);
215}
216
217inline void
219{
220 v_.push_back(std::move(object));
221}
222
225{
226 return v_.begin();
227}
228
231{
232 return v_.end();
233}
234
237{
238 return v_.begin();
239}
240
243{
244 return v_.end();
245}
246
249{
250 return v_.size();
251}
252
253inline bool
255{
256 return v_.empty();
257}
258
259inline void
261{
262 v_.clear();
263}
264
265inline void
270
271inline void
273{
274 v_.swap(a.v_);
275}
276
277inline bool
279{
280 return v_ == s.v_;
281}
282
283inline bool
285{
286 return v_ != s.v_;
287}
288
291{
292 return v_.erase(pos);
293}
294
297{
298 return v_.erase(pos);
299}
300
303{
304 return v_.erase(first, last);
305}
306
309{
310 return v_.erase(first, last);
311}
312
313} // namespace ripple
314
315#endif
T back(T... args)
T begin(T... args)
Represents a JSON value.
Definition json_value.h:149
Tracks the number of instances of an object.
Identifies fields.
Definition SField.h:146
bool operator!=(STArray const &s) const
Definition STArray.h:284
void sort(bool(*compare)(STObject const &o1, STObject const &o2))
Definition STArray.cpp:197
iterator end()
Definition STArray.h:230
void emplace_back(Args &&... args)
Definition STArray.h:206
bool empty() const
Definition STArray.h:254
std::string getFullText() const override
Definition STArray.cpp:114
iterator erase(iterator pos)
Definition STArray.h:290
STBase * move(std::size_t n, void *buf) override
Definition STArray.cpp:108
STBase * copy(std::size_t n, void *buf) const override
Definition STArray.cpp:102
STArray()=default
void add(Serializer &s) const override
Definition STArray.cpp:167
bool isEquivalent(STBase const &t) const override
Definition STArray.cpp:184
list_type::iterator iterator
Definition STArray.h:38
list_type::const_iterator const_iterator
Definition STArray.h:39
STObject & operator[](std::size_t j)
Definition STArray.h:181
SerializedTypeID getSType() const override
Definition STArray.cpp:178
bool operator==(STArray const &s) const
Definition STArray.h:278
void reserve(std::size_t n)
Definition STArray.h:266
Json::Value getJson(JsonOptions index) const override
Definition STArray.cpp:152
bool isDefault() const override
Definition STArray.cpp:191
list_type v_
Definition STArray.h:33
list_type::size_type size_type
Definition STArray.h:37
STArray(STArray const &)=default
STArray & operator=(STArray const &)=default
std::string getText() const override
Definition STArray.cpp:133
void push_back(STObject const &object)
Definition STArray.h:212
void swap(STArray &a) noexcept
Definition STArray.h:272
STObject & back()
Definition STArray.h:193
iterator begin()
Definition STArray.h:224
size_type size() const
Definition STArray.h:248
A type which can be exported to a well known binary format.
Definition STBase.h:135
T clear(T... args)
T emplace_back(T... args)
T empty(T... args)
T end(T... args)
T erase(T... args)
T is_convertible_v
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
SerializedTypeID
Definition SField.h:110
T push_back(T... args)
T reserve(T... args)
T size(T... args)
Note, should be treated as flags that can be | and &.
Definition STBase.h:37
T swap(T... args)