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/STBitString.h>
24 #include <ripple/protocol/STInteger.h>
25 #include <ripple/protocol/STBase.h>
26 
27 namespace ripple {
28 
30  : public STBase
31 {
32 public:
34 
35  STVector256 () = default;
36 
37  explicit STVector256 (SField const& n)
38  : STBase (n)
39  { }
40 
41  explicit STVector256 (std::vector<uint256> const& vector)
42  : mValue (vector)
43  { }
44 
45  STVector256 (SField const& n, std::vector<uint256> const& vector)
46  : STBase (n), mValue (vector)
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 
73  getJson (JsonOptions) const override;
74 
75  bool
76  isEquivalent (const STBase& t) const override;
77 
78  bool
79  isDefault () const override
80  {
81  return mValue.empty ();
82  }
83 
86  {
87  mValue = v;
88  return *this;
89  }
90 
93  {
94  mValue = std::move(v);
95  return *this;
96  }
97 
98  void
99  setValue (const STVector256& v)
100  {
101  mValue = v.mValue;
102  }
103 
105  explicit
106  operator std::vector<uint256> () const
107  {
108  return mValue;
109  }
110 
112  size () const
113  {
114  return mValue.size ();
115  }
116 
117  void
119  {
120  return mValue.resize (n);
121  }
122 
123  bool
124  empty () const
125  {
126  return mValue.empty ();
127  }
128 
131  {
132  return mValue[n];
133  }
134 
137  {
138  return mValue[n];
139  }
140 
141  std::vector<uint256> const&
142  value() const
143  {
144  return mValue;
145  }
146 
149  {
150  return mValue.insert(pos, value);
151  }
152 
155  {
156  return mValue.insert(pos, std::move(value));
157  }
158 
159  void
160  push_back (uint256 const& v)
161  {
162  mValue.push_back (v);
163  }
164 
167  {
168  return mValue.begin ();
169  }
170 
172  begin() const
173  {
174  return mValue.begin ();
175  }
176 
178  end()
179  {
180  return mValue.end ();
181  }
182 
184  end() const
185  {
186  return mValue.end ();
187  }
188 
191  {
192  return mValue.erase (position);
193  }
194 
195  void
196  clear () noexcept
197  {
198  return mValue.clear ();
199  }
200 
201 private:
203 };
204 
205 } // ripple
206 
207 #endif
ripple::STVector256::STVector256
STVector256(SField const &n)
Definition: STVector256.h:37
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:148
ripple::STVector256::end
std::vector< uint256 >::iterator end()
Definition: STVector256.h:178
ripple::STVector256::begin
std::vector< uint256 >::iterator begin()
Definition: STVector256.h:166
std::vector
STL class.
ripple::STVector256::push_back
void push_back(uint256 const &v)
Definition: STVector256.h:160
ripple::STVector256::clear
void clear() noexcept
Definition: STVector256.h:196
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:52
ripple::STVector256::STVector256
STVector256(std::vector< uint256 > const &vector)
Definition: STVector256.h:41
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:99
ripple::STVector256::isDefault
bool isDefault() const override
Definition: STVector256.h:79
ripple::STVector256::empty
bool empty() const
Definition: STVector256.h:124
ripple::STVector256::insert
std::vector< uint256 >::iterator insert(std::vector< uint256 >::const_iterator pos, uint256 &&value)
Definition: STVector256.h:154
ripple::STVector256::STVector256
STVector256(SField const &n, std::vector< uint256 > const &vector)
Definition: STVector256.h:45
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:161
ripple::base_uint
Definition: base_uint.h:65
ripple::STVector256::operator=
STVector256 & operator=(std::vector< uint256 > const &v)
Definition: STVector256.h:85
ripple::STVector256::add
void add(Serializer &s) const override
Definition: STVector256.cpp:46
ripple::STVector256::operator[]
std::vector< uint256 >::reference operator[](std::vector< uint256 >::size_type n)
Definition: STVector256.h:130
ripple::STVector256::isEquivalent
bool isEquivalent(const STBase &t) const override
Definition: STVector256.cpp:54
ripple::STVector256::begin
std::vector< uint256 >::const_iterator begin() const
Definition: STVector256.h:172
ripple::STVector256::size
std::size_t size() const
Definition: STVector256.h:112
ripple::SerialIter
Definition: Serializer.h:311
ripple::STI_VECTOR256
@ STI_VECTOR256
Definition: SField.h:76
ripple::STVector256::mValue
std::vector< uint256 > mValue
Definition: STVector256.h:202
ripple::STVector256::end
std::vector< uint256 >::const_iterator end() const
Definition: STVector256.h:184
ripple::Serializer
Definition: Serializer.h:43
ripple::STVector256::erase
std::vector< uint256 >::iterator erase(std::vector< uint256 >::iterator position)
Definition: STVector256.h:190
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:112
ripple::STBase
A type which can be exported to a well known binary format.
Definition: STBase.h:65
ripple::STVector256
Definition: STVector256.h:29
std::size_t
ripple::STVector256::resize
void resize(std::size_t n)
Definition: STVector256.h:118
ripple::STVector256::value
std::vector< uint256 > const & value() const
Definition: STVector256.h:142
ripple::STVector256::getJson
Json::Value getJson(JsonOptions) const override
Definition: STVector256.cpp:61
Json::Value
Represents a JSON value.
Definition: json_value.h:141