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/protocol/STBase.h>
24 #include <ripple/protocol/STBitString.h>
25 #include <ripple/protocol/STInteger.h>
26 
27 namespace ripple {
28 
29 class STVector256 : public STBase
30 {
32 
33 public:
35 
36  STVector256() = default;
37 
38  explicit STVector256(SField const& n);
39  explicit STVector256(std::vector<uint256> const& vector);
40  STVector256(SField const& n, std::vector<uint256> const& vector);
41  STVector256(SerialIter& sit, SField const& name);
42 
44  getSType() const override;
45 
46  void
47  add(Serializer& s) const override;
48 
49  Json::Value getJson(JsonOptions) const override;
50 
51  bool
52  isEquivalent(const STBase& t) const override;
53 
54  bool
55  isDefault() const override;
56 
59 
62 
63  void
64  setValue(const STVector256& v);
65 
67  explicit operator std::vector<uint256>() const;
68 
70  size() const;
71 
72  void
74 
75  bool
76  empty() const;
77 
80 
83 
85  value() const;
86 
89 
92 
93  void
94  push_back(uint256 const& v);
95 
97  begin();
98 
100  begin() const;
101 
103  end();
104 
106  end() const;
107 
110 
111  void
112  clear() noexcept;
113 
114 private:
115  STBase*
116  copy(std::size_t n, void* buf) const override;
117  STBase*
118  move(std::size_t n, void* buf) override;
119 
120  friend class detail::STVar;
121 };
122 
123 inline STVector256::STVector256(SField const& n) : STBase(n)
124 {
125 }
126 
128  : mValue(vector)
129 {
130 }
131 
133  SField const& n,
134  std::vector<uint256> const& vector)
135  : STBase(n), mValue(vector)
136 {
137 }
138 
139 inline STVector256&
141 {
142  mValue = v;
143  return *this;
144 }
145 
146 inline STVector256&
148 {
149  mValue = std::move(v);
150  return *this;
151 }
152 
153 inline void
155 {
156  mValue = v.mValue;
157 }
158 
160 inline STVector256::operator std::vector<uint256>() const
161 {
162  return mValue;
163 }
164 
165 inline std::size_t
167 {
168  return mValue.size();
169 }
170 
171 inline void
173 {
174  return mValue.resize(n);
175 }
176 
177 inline bool
179 {
180  return mValue.empty();
181 }
182 
185 {
186  return mValue[n];
187 }
188 
191 {
192  return mValue[n];
193 }
194 
195 inline std::vector<uint256> const&
197 {
198  return mValue;
199 }
200 
204  uint256 const& value)
205 {
206  return mValue.insert(pos, value);
207 }
208 
211 {
212  return mValue.insert(pos, std::move(value));
213 }
214 
215 inline void
217 {
218  mValue.push_back(v);
219 }
220 
223 {
224  return mValue.begin();
225 }
226 
228 STVector256::begin() const
229 {
230  return mValue.begin();
231 }
232 
235 {
236  return mValue.end();
237 }
238 
240 STVector256::end() const
241 {
242  return mValue.end();
243 }
244 
247 {
248  return mValue.erase(position);
249 }
250 
251 inline void
253 {
254  return mValue.clear();
255 }
256 
257 } // namespace ripple
258 
259 #endif
ripple::STVector256::erase
std::vector< uint256 >::iterator erase(std::vector< uint256 >::iterator position)
Definition: STVector256.h:246
ripple::STVector256::operator=
STVector256 & operator=(std::vector< uint256 > const &v)
Definition: STVector256.h:140
ripple::JsonOptions
JsonOptions
Definition: STBase.h:34
std::vector
STL class.
ripple::STVector256::push_back
void push_back(uint256 const &v)
Definition: STVector256.h:216
ripple::STVector256::clear
void clear() noexcept
Definition: STVector256.h:252
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:52
ripple::STVector256::end
std::vector< uint256 >::iterator end()
Definition: STVector256.h:234
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:154
ripple::STVector256::isDefault
bool isDefault() const override
Definition: STVector256.cpp:63
ripple::STVector256::empty
bool empty() const
Definition: STVector256.h:178
ripple::STVector256::begin
std::vector< uint256 >::iterator begin()
Definition: STVector256.h:222
ripple::STVector256::value
std::vector< uint256 > const & value() const
Definition: STVector256.h:196
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:184
ripple::STVector256::size
std::size_t size() const
Definition: STVector256.h:166
ripple::SerialIter
Definition: Serializer.h:310
ripple::STVector256::insert
std::vector< uint256 >::iterator insert(std::vector< uint256 >::const_iterator pos, uint256 const &value)
Definition: STVector256.h:202
ripple::STVector256::mValue
std::vector< uint256 > mValue
Definition: STVector256.h:31
ripple::Serializer
Definition: Serializer.h:39
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
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:112
ripple::STBase
A type which can be exported to a well known binary format.
Definition: STBase.h:66
std
STL namespace.
ripple::STVector256
Definition: STVector256.h:29
std::size_t
ripple::STVector256::resize
void resize(std::size_t n)
Definition: STVector256.h:172
ripple::STVector256::getJson
Json::Value getJson(JsonOptions) const override
Definition: STVector256.cpp:83
Json::Value
Represents a JSON value.
Definition: json_value.h:145