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 {
31 public:
33 
34  STVector256() = default;
35 
36  explicit STVector256(SField const& n) : STBase(n)
37  {
38  }
39 
40  explicit STVector256(std::vector<uint256> const& vector) : mValue(vector)
41  {
42  }
43 
44  STVector256(SField const& n, std::vector<uint256> const& vector)
45  : STBase(n), mValue(vector)
46  {
47  }
48 
49  STVector256(SerialIter& sit, SField const& name);
50 
51  STBase*
52  copy(std::size_t n, void* buf) const override
53  {
54  return emplace(n, buf, *this);
55  }
56 
57  STBase*
58  move(std::size_t n, void* buf) override
59  {
60  return emplace(n, buf, std::move(*this));
61  }
62 
64  getSType() const override
65  {
66  return STI_VECTOR256;
67  }
68 
69  void
70  add(Serializer& s) const override;
71 
72  Json::Value getJson(JsonOptions) const override;
73 
74  bool
75  isEquivalent(const STBase& t) const override;
76 
77  bool
78  isDefault() const override
79  {
80  return mValue.empty();
81  }
82 
85  {
86  mValue = v;
87  return *this;
88  }
89 
92  {
93  mValue = std::move(v);
94  return *this;
95  }
96 
97  void
99  {
100  mValue = v.mValue;
101  }
102 
104  explicit operator std::vector<uint256>() const
105  {
106  return mValue;
107  }
108 
110  size() const
111  {
112  return mValue.size();
113  }
114 
115  void
117  {
118  return mValue.resize(n);
119  }
120 
121  bool
122  empty() const
123  {
124  return mValue.empty();
125  }
126 
129  {
130  return mValue[n];
131  }
132 
135  {
136  return mValue[n];
137  }
138 
139  std::vector<uint256> const&
140  value() const
141  {
142  return mValue;
143  }
144 
147  {
148  return mValue.insert(pos, value);
149  }
150 
153  {
154  return mValue.insert(pos, std::move(value));
155  }
156 
157  void
158  push_back(uint256 const& v)
159  {
160  mValue.push_back(v);
161  }
162 
165  {
166  return mValue.begin();
167  }
168 
170  begin() const
171  {
172  return mValue.begin();
173  }
174 
176  end()
177  {
178  return mValue.end();
179  }
180 
182  end() const
183  {
184  return mValue.end();
185  }
186 
189  {
190  return mValue.erase(position);
191  }
192 
193  void
194  clear() noexcept
195  {
196  return mValue.clear();
197  }
198 
199 private:
201 };
202 
203 } // namespace ripple
204 
205 #endif
ripple::STVector256::STVector256
STVector256(SField const &n)
Definition: STVector256.h:36
ripple::JsonOptions
JsonOptions
Definition: STBase.h:34
ripple::STVector256::move
STBase * move(std::size_t n, void *buf) override
Definition: STVector256.h:58
ripple::STVector256::insert
std::vector< uint256 >::iterator insert(std::vector< uint256 >::const_iterator pos, uint256 const &value)
Definition: STVector256.h:146
ripple::STVector256::end
std::vector< uint256 >::iterator end()
Definition: STVector256.h:176
ripple::STVector256::begin
std::vector< uint256 >::iterator begin()
Definition: STVector256.h:164
std::vector
STL class.
ripple::STVector256::push_back
void push_back(uint256 const &v)
Definition: STVector256.h:158
ripple::STVector256::clear
void clear() noexcept
Definition: STVector256.h:194
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:52
ripple::STVector256::STVector256
STVector256(std::vector< uint256 > const &vector)
Definition: STVector256.h:40
ripple::STVector256::copy
STBase * copy(std::size_t n, void *buf) const override
Definition: STVector256.h:52
ripple::STVector256::setValue
void setValue(const STVector256 &v)
Definition: STVector256.h:98
ripple::STVector256::isDefault
bool isDefault() const override
Definition: STVector256.h:78
ripple::STVector256::empty
bool empty() const
Definition: STVector256.h:122
ripple::STVector256::insert
std::vector< uint256 >::iterator insert(std::vector< uint256 >::const_iterator pos, uint256 &&value)
Definition: STVector256.h:152
ripple::STVector256::operator=
STVector256 & operator=(std::vector< uint256 > &&v)
Definition: STVector256.h:91
ripple::STVector256::STVector256
STVector256(SField const &n, std::vector< uint256 > const &vector)
Definition: STVector256.h:44
ripple::STVector256::getSType
SerializedTypeID getSType() const override
Definition: STVector256.h:64
ripple::STBase::emplace
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition: STBase.h:149
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:75
ripple::STVector256::operator=
STVector256 & operator=(std::vector< uint256 > const &v)
Definition: STVector256.h:84
ripple::STVector256::operator[]
std::vector< uint256 >::const_reference operator[](std::vector< uint256 >::size_type n) const
Definition: STVector256.h:134
ripple::STVector256::add
void add(Serializer &s) const override
Definition: STVector256.cpp:45
ripple::STVector256::operator[]
std::vector< uint256 >::reference operator[](std::vector< uint256 >::size_type n)
Definition: STVector256.h:128
ripple::STVector256::isEquivalent
bool isEquivalent(const STBase &t) const override
Definition: STVector256.cpp:53
ripple::STVector256::begin
std::vector< uint256 >::const_iterator begin() const
Definition: STVector256.h:170
ripple::STVector256::size
std::size_t size() const
Definition: STVector256.h:110
ripple::SerialIter
Definition: Serializer.h:310
ripple::STI_VECTOR256
@ STI_VECTOR256
Definition: SField.h:75
ripple::STVector256::mValue
std::vector< uint256 > mValue
Definition: STVector256.h:200
ripple::STVector256::end
std::vector< uint256 >::const_iterator end() const
Definition: STVector256.h:182
ripple::Serializer
Definition: Serializer.h:39
ripple::STVector256::erase
std::vector< uint256 >::iterator erase(std::vector< uint256 >::iterator position)
Definition: STVector256.h:188
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::STVector256::STVector256
STVector256()=default
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:62
ripple::STVector256
Definition: STVector256.h:29
std::size_t
ripple::STVector256::resize
void resize(std::size_t n)
Definition: STVector256.h:116
ripple::STVector256::value
std::vector< uint256 > const & value() const
Definition: STVector256.h:140
ripple::STVector256::getJson
Json::Value getJson(JsonOptions) const override
Definition: STVector256.cpp:59
Json::Value
Represents a JSON value.
Definition: json_value.h:145