rippled
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 <ripple/basics/CountedObject.h>
24 #include <ripple/protocol/STObject.h>
25 
26 namespace ripple {
27 
28 class STArray final : public STBase, public CountedObject<STArray>
29 {
30 private:
32 
34 
35 public:
36  using size_type = list_type::size_type;
37  using iterator = list_type::iterator;
38  using const_iterator = list_type::const_iterator;
39 
40  STArray() = default;
41  STArray(STArray const&) = default;
42  STArray&
43  operator=(STArray const&) = default;
44  STArray(STArray&&);
45  STArray&
46  operator=(STArray&&);
47 
48  STArray(SField const& f, int n);
49  STArray(SerialIter& sit, SField const& f, int depth = 0);
50  explicit STArray(int n);
51  explicit STArray(SField const& f);
52 
53  STObject&
55 
56  STObject const&
57  operator[](std::size_t j) const;
58 
59  STObject&
60  back();
61 
62  STObject const&
63  back() const;
64 
65  template <class... Args>
66  void
67  emplace_back(Args&&... args);
68 
69  void
70  push_back(STObject const& object);
71 
72  void
73  push_back(STObject&& object);
74 
75  iterator
76  begin();
77 
78  iterator
79  end();
80 
82  begin() const;
83 
85  end() const;
86 
87  size_type
88  size() const;
89 
90  bool
91  empty() const;
92 
93  void
94  clear();
95 
96  void
98 
99  void
100  swap(STArray& a) noexcept;
101 
103  getFullText() const override;
104 
106  getText() const override;
107 
109  getJson(JsonOptions index) const override;
110 
111  void
112  add(Serializer& s) const override;
113 
114  void
115  sort(bool (*compare)(const STObject& o1, const STObject& o2));
116 
117  bool
118  operator==(const STArray& s) const;
119 
120  bool
121  operator!=(const STArray& s) const;
122 
124  getSType() const override;
125 
126  bool
127  isEquivalent(const STBase& t) const override;
128 
129  bool
130  isDefault() const override;
131 
132 private:
133  STBase*
134  copy(std::size_t n, void* buf) const override;
135  STBase*
136  move(std::size_t n, void* buf) override;
137 
138  friend class detail::STVar;
139 };
140 
141 inline STObject&
143 {
144  return v_[j];
145 }
146 
147 inline STObject const&
149 {
150  return v_[j];
151 }
152 
153 inline STObject&
155 {
156  return v_.back();
157 }
158 
159 inline STObject const&
160 STArray::back() const
161 {
162  return v_.back();
163 }
164 
165 template <class... Args>
166 inline void
167 STArray::emplace_back(Args&&... args)
168 {
169  v_.emplace_back(std::forward<Args>(args)...);
170 }
171 
172 inline void
174 {
175  v_.push_back(object);
176 }
177 
178 inline void
180 {
181  v_.push_back(std::move(object));
182 }
183 
184 inline STArray::iterator
186 {
187  return v_.begin();
188 }
189 
190 inline STArray::iterator
192 {
193  return v_.end();
194 }
195 
197 STArray::begin() const
198 {
199  return v_.begin();
200 }
201 
203 STArray::end() const
204 {
205  return v_.end();
206 }
207 
208 inline STArray::size_type
210 {
211  return v_.size();
212 }
213 
214 inline bool
216 {
217  return v_.empty();
218 }
219 
220 inline void
222 {
223  v_.clear();
224 }
225 
226 inline void
228 {
229  v_.reserve(n);
230 }
231 
232 inline void
233 STArray::swap(STArray& a) noexcept
234 {
235  v_.swap(a.v_);
236 }
237 
238 inline bool
240 {
241  return v_ == s.v_;
242 }
243 
244 inline bool
246 {
247  return v_ != s.v_;
248 }
249 
250 } // namespace ripple
251 
252 #endif
ripple::STArray::empty
bool empty() const
Definition: STArray.h:215
ripple::STArray::size
size_type size() const
Definition: STArray.h:209
ripple::STArray::operator==
bool operator==(const STArray &s) const
Definition: STArray.h:239
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:124
std::string
STL class.
ripple::JsonOptions
JsonOptions
Definition: STBase.h:34
ripple::STArray::iterator
list_type::iterator iterator
Definition: STArray.h:37
std::vector::reserve
T reserve(T... args)
std::vector< STObject >
std::vector::size
T size(T... args)
ripple::STArray::isEquivalent
bool isEquivalent(const STBase &t) const override
Definition: STArray.cpp:175
ripple::STArray::getJson
Json::Value getJson(JsonOptions index) const override
Definition: STArray.cpp:143
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:52
ripple::STArray::push_back
void push_back(STObject const &object)
Definition: STArray.h:173
ripple::STArray::copy
STBase * copy(std::size_t n, void *buf) const override
Definition: STArray.cpp:93
ripple::STArray::STArray
STArray()=default
std::vector::back
T back(T... args)
ripple::STArray::const_iterator
list_type::const_iterator const_iterator
Definition: STArray.h:38
ripple::STArray::getSType
SerializedTypeID getSType() const override
Definition: STArray.cpp:169
std::vector::clear
T clear(T... args)
std::vector::push_back
T push_back(T... args)
ripple::STArray::clear
void clear()
Definition: STArray.h:221
ripple::STArray::size_type
list_type::size_type size_type
Definition: STArray.h:36
ripple::compare
int compare(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition: base_uint.h:533
ripple::STArray::operator!=
bool operator!=(const STArray &s) const
Definition: STArray.h:245
ripple::STArray::isDefault
bool isDefault() const override
Definition: STArray.cpp:182
ripple::STArray
Definition: STArray.h:28
ripple::STArray::operator=
STArray & operator=(STArray const &)=default
ripple::STArray::swap
void swap(STArray &a) noexcept
Definition: STArray.h:233
ripple::SerialIter
Definition: Serializer.h:310
ripple::STArray::getFullText
std::string getFullText() const override
Definition: STArray.cpp:105
ripple::STArray::sort
void sort(bool(*compare)(const STObject &o1, const STObject &o2))
Definition: STArray.cpp:188
std::vector::swap
T swap(T... args)
ripple::STArray::getText
std::string getText() const override
Definition: STArray.cpp:124
ripple::STArray::begin
iterator begin()
Definition: STArray.h:185
ripple::Serializer
Definition: Serializer.h:39
ripple::STObject
Definition: STObject.h:51
std::vector::emplace_back
T emplace_back(T... args)
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::STArray::operator[]
STObject & operator[](std::size_t j)
Definition: STArray.h:142
ripple::SField
Identifies fields.
Definition: SField.h:109
ripple::STBase
A type which can be exported to a well known binary format.
Definition: STBase.h:66
ripple::STArray::emplace_back
void emplace_back(Args &&... args)
Definition: STArray.h:167
std::vector::begin
T begin(T... args)
std::vector::empty
T empty(T... args)
ripple::STArray::back
STObject & back()
Definition: STArray.h:154
std::size_t
std::vector::end
T end(T... args)
ripple::STArray::move
STBase * move(std::size_t n, void *buf) override
Definition: STArray.cpp:99
ripple::STArray::v_
list_type v_
Definition: STArray.h:33
ripple::detail::STVar
Definition: STVar.h:49
ripple::STArray::end
iterator end()
Definition: STArray.h:191
ripple::STArray::add
void add(Serializer &s) const override
Definition: STArray.cpp:158
ripple::STArray::reserve
void reserve(std::size_t n)
Definition: STArray.h:227
Json::Value
Represents a JSON value.
Definition: json_value.h:145