rippled
STVector256.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_STVECTOR256_H_INCLUDED
21 #define RIPPLE_PROTOCOL_STVECTOR256_H_INCLUDED
22 
23 #include <ripple/basics/CountedObject.h>
24 #include <ripple/protocol/STBase.h>
25 #include <ripple/protocol/STBitString.h>
26 #include <ripple/protocol/STInteger.h>
27 
28 namespace ripple {
29 
30 class STVector256 : public STBase, public CountedObject<STVector256>
31 {
33 
34 public:
36 
37  STVector256() = default;
38 
39  explicit STVector256(SField const& n);
40  explicit STVector256(std::vector<uint256> const& vector);
41  STVector256(SField const& n, std::vector<uint256> const& vector);
42  STVector256(SerialIter& sit, SField const& name);
43 
45  getSType() const override;
46 
47  void
48  add(Serializer& s) const override;
49 
50  Json::Value getJson(JsonOptions) const override;
51 
52  bool
53  isEquivalent(const STBase& t) const override;
54 
55  bool
56  isDefault() const override;
57 
60 
63 
64  void
65  setValue(const STVector256& v);
66 
68  explicit operator std::vector<uint256>() const;
69 
71  size() const;
72 
73  void
75 
76  bool
77  empty() const;
78 
81 
84 
86  value() const;
87 
90 
93 
94  void
95  push_back(uint256 const& v);
96 
98  begin();
99 
101  begin() const;
102 
104  end();
105 
107  end() const;
108 
111 
112  void
113  clear() noexcept;
114 
115 private:
116  STBase*
117  copy(std::size_t n, void* buf) const override;
118  STBase*
119  move(std::size_t n, void* buf) override;
120 
121  friend class detail::STVar;
122 };
123 
124 inline STVector256::STVector256(SField const& n) : STBase(n)
125 {
126 }
127 
129  : mValue(vector)
130 {
131 }
132 
134  SField const& n,
135  std::vector<uint256> const& vector)
136  : STBase(n), mValue(vector)
137 {
138 }
139 
140 inline STVector256&
142 {
143  mValue = v;
144  return *this;
145 }
146 
147 inline STVector256&
149 {
150  mValue = std::move(v);
151  return *this;
152 }
153 
154 inline void
156 {
157  mValue = v.mValue;
158 }
159 
161 inline STVector256::operator std::vector<uint256>() const
162 {
163  return mValue;
164 }
165 
166 inline std::size_t
168 {
169  return mValue.size();
170 }
171 
172 inline void
174 {
175  return mValue.resize(n);
176 }
177 
178 inline bool
180 {
181  return mValue.empty();
182 }
183 
186 {
187  return mValue[n];
188 }
189 
192 {
193  return mValue[n];
194 }
195 
196 inline std::vector<uint256> const&
198 {
199  return mValue;
200 }
201 
205  uint256 const& value)
206 {
207  return mValue.insert(pos, value);
208 }
209 
212 {
213  return mValue.insert(pos, std::move(value));
214 }
215 
216 inline void
218 {
219  mValue.push_back(v);
220 }
221 
224 {
225  return mValue.begin();
226 }
227 
229 STVector256::begin() const
230 {
231  return mValue.begin();
232 }
233 
236 {
237  return mValue.end();
238 }
239 
241 STVector256::end() const
242 {
243  return mValue.end();
244 }
245 
248 {
249  return mValue.erase(position);
250 }
251 
252 inline void
254 {
255  return mValue.clear();
256 }
257 
258 } // namespace ripple
259 
260 #endif
ripple::STVector256::erase
std::vector< uint256 >::iterator erase(std::vector< uint256 >::iterator position)
Definition: STVector256.h:247
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:124
ripple::STVector256::operator=
STVector256 & operator=(std::vector< uint256 > const &v)
Definition: STVector256.h:141
std::vector
STL class.
ripple::STVector256::push_back
void push_back(uint256 const &v)
Definition: STVector256.h:217
ripple::STVector256::clear
void clear() noexcept
Definition: STVector256.h:253
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:104
ripple::STVector256::end
std::vector< uint256 >::iterator end()
Definition: STVector256.h:235
ripple::STVector256::move
STBase * move(std::size_t n, void *buf) override
Definition: STVector256.cpp:51
ripple::STVector256::setValue
void setValue(const STVector256 &v)
Definition: STVector256.h:155
ripple::STVector256::isDefault
bool isDefault() const override
Definition: STVector256.cpp:63
ripple::STVector256::empty
bool empty() const
Definition: STVector256.h:179
ripple::STVector256::begin
std::vector< uint256 >::iterator begin()
Definition: STVector256.h:223
ripple::STVector256::value
std::vector< uint256 > const & value() const
Definition: STVector256.h:197
ripple::STVector256::getSType
SerializedTypeID getSType() const override
Definition: STVector256.cpp:57
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:82
ripple::STVector256::add
void add(Serializer &s) const override
Definition: STVector256.cpp:69
ripple::STVector256::isEquivalent
bool isEquivalent(const STBase &t) const override
Definition: STVector256.cpp:77
ripple::STVector256::operator[]
std::vector< uint256 >::reference operator[](std::vector< uint256 >::size_type n)
Definition: STVector256.h:185
ripple::STVector256::size
std::size_t size() const
Definition: STVector256.h:167
ripple::SerialIter
Definition: Serializer.h:311
ripple::STVector256::insert
std::vector< uint256 >::iterator insert(std::vector< uint256 >::const_iterator pos, uint256 const &value)
Definition: STVector256.h:203
ripple::STVector256::mValue
std::vector< uint256 > mValue
Definition: STVector256.h:32
ripple::Serializer
Definition: Serializer.h:40
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::JsonOptions
Note, should be treated as flags that can be | and &.
Definition: STBase.h:35
ripple::STVector256::copy
STBase * copy(std::size_t n, void *buf) const override
Definition: STVector256.cpp:45
ripple::STVector256::STVector256
STVector256()=default
ripple::SField
Identifies fields.
Definition: SField.h:139
ripple::STBase
A type which can be exported to a well known binary format.
Definition: STBase.h:121
std
STL namespace.
ripple::STVector256
Definition: STVector256.h:30
std::size_t
ripple::STVector256::resize
void resize(std::size_t n)
Definition: STVector256.h:173
ripple::STVector256::getJson
Json::Value getJson(JsonOptions) const override
Definition: STVector256.cpp:83
Json::Value
Represents a JSON value.
Definition: json_value.h:145