OpenMS
ExposedVector.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2023.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Chris Bielow $
32 // $Authors: Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 
38 #include <cstddef> // for size_t
39 #include <vector>
40 
41 namespace OpenMS
42 {
43 
45 #define EXPOSED_VECTOR_INTERFACE(InnerElement) \
46  using ExpVec = ExposedVector< InnerElement >; \
47  using ExpVec::ExposedVector; \
48  using value_type = typename ExpVec::value_type; \
49  using iterator = typename ExpVec::iterator; \
50  using const_iterator = typename ExpVec::const_iterator; \
51  using reverse_iterator = typename ExpVec::reverse_iterator; \
52  using const_reverse_iterator = typename ExpVec::const_reverse_iterator; \
53  using size_type = typename ExpVec::size_type; \
54  using pointer = typename ExpVec::pointer; \
55  using reference = typename ExpVec::reference; \
56  using const_reference = typename ExpVec::const_reference; \
57  using difference_type = typename ExpVec::difference_type; \
58 
59 
79  template<class VectorElement>
81  {
82  public:
83  using VecMember = std::vector<VectorElement>;
84 
85  // types
86  using value_type = typename VecMember::value_type;
87  using iterator = typename VecMember::iterator;
88  using const_iterator = typename VecMember::const_iterator;
89  using reverse_iterator = typename VecMember::reverse_iterator;
90  using const_reverse_iterator = typename VecMember::const_reverse_iterator;
91  using size_type = typename VecMember::size_type;
92  using pointer = typename VecMember::pointer;
93  using reference = typename VecMember::reference;
94  using const_reference = typename VecMember::const_reference;
95  using difference_type = typename VecMember::difference_type;
96 
97  protected:
99 
100  public:
101  ExposedVector() = default;
102  explicit ExposedVector(const size_t n)
103  : data_(n)
104  {
105  }
106  ExposedVector(const size_t n, const VectorElement& val) : data_(n, val)
107  {
108  }
109  template <class Iter> ExposedVector(Iter begin, Iter end)
110  : data_(begin, end)
111  {
112  }
114  ExposedVector(const ExposedVector& rhs) = default;
116  ExposedVector(ExposedVector&& rhs) noexcept = default;
117 
119  ExposedVector& operator=(const ExposedVector& rhs) = default;
121  ExposedVector& operator=(ExposedVector&& rhs) noexcept = default;
122 
123  iterator begin() noexcept
124  {
125  return data_.begin();
126  }
127  iterator end() noexcept
128  {
129  return data_.end();
130  }
131  const_iterator begin() const noexcept
132  {
133  return data_.begin();
134  }
135  const_iterator end() const noexcept
136  {
137  return data_.end();
138  }
139  const_iterator cbegin() const noexcept
140  {
141  return data_.cbegin();
142  }
143  const_iterator cend() const noexcept
144  {
145  return data_.cend();
146  }
147  size_t size() const noexcept
148  {
149  return data_.size();
150  }
151  void resize(const size_t new_size)
152  {
153  data_.resize(new_size);
154  }
155  void reserve(const size_t new_size)
156  {
157  data_.reserve(new_size);
158  }
159  bool empty() const noexcept
160  {
161  return data_.empty();
162  }
163  VectorElement& operator[](size_t i) noexcept
164  {
165  return data_[i];
166  }
167  const VectorElement& operator[](size_t i) const noexcept
168  {
169  return data_[i];
170  }
171  VectorElement& at(size_t i)
172  {
173  return data_.at(i);
174  }
175  const VectorElement& at(size_t i) const
176  {
177  return data_.at(i);
178  }
179  VectorElement& back() noexcept
180  {
181  return data_.back();
182  }
183  const VectorElement& back() const noexcept
184  {
185  return data_.back();
186  }
187  void push_back(const VectorElement& f)
188  {
189  data_.push_back(f);
190  }
191  void push_back(VectorElement&& f)
192  {
193  data_.push_back(std::move(f));
194  }
195  template<typename... Args>
196  decltype(auto) emplace_back(Args&&... args)
197  {
198  return data_.emplace_back(std::forward<Args>(args)...);
199  }
200  void pop_back() noexcept
201  {
202  data_.pop_back();
203  }
204  iterator erase(const_iterator where) noexcept
205  {
206  return data_.erase(where);
207  }
209  {
210  return data_.erase(from, to);
211  }
212  template<typename T>
213  iterator insert(const_iterator where, T from, T to)
214  {
215  return data_.insert(where, from, to);
216  }
217 
219  const VecMember& getData() const
220  {
221  return data_;
222  }
225  {
226  return data_;
227  }
228  };
229 
230 } // namespace OpenMS
Makes a vector<VectorElement> available in the derived class and exposed commonly used vector member ...
Definition: ExposedVector.h:81
iterator insert(const_iterator where, T from, T to)
Definition: ExposedVector.h:213
std::vector< VectorElement > VecMember
Definition: ExposedVector.h:83
typename VecMember::iterator iterator
Definition: ExposedVector.h:87
const_iterator begin() const noexcept
Definition: ExposedVector.h:131
typename VecMember::const_iterator const_iterator
Definition: ExposedVector.h:88
void reserve(const size_t new_size)
Definition: ExposedVector.h:155
typename VecMember::pointer pointer
Definition: ExposedVector.h:92
size_t size() const noexcept
Definition: ExposedVector.h:147
bool empty() const noexcept
Definition: ExposedVector.h:159
ExposedVector(const size_t n)
Definition: ExposedVector.h:102
decltype(auto) emplace_back(Args &&... args)
Definition: ExposedVector.h:196
typename VecMember::size_type size_type
Definition: ExposedVector.h:91
VectorElement & back() noexcept
Definition: ExposedVector.h:179
typename VecMember::value_type value_type
Definition: ExposedVector.h:86
const_iterator end() const noexcept
Definition: ExposedVector.h:135
typename VecMember::reverse_iterator reverse_iterator
Definition: ExposedVector.h:89
typename VecMember::const_reference const_reference
Definition: ExposedVector.h:94
ExposedVector(ExposedVector &&rhs) noexcept=default
Move C'tor.
const VectorElement & back() const noexcept
Definition: ExposedVector.h:183
typename VecMember::difference_type difference_type
Definition: ExposedVector.h:95
VecMember data_
the container which holds all the data
Definition: ExposedVector.h:98
ExposedVector & operator=(ExposedVector &&rhs) noexcept=default
Move Assignment.
const VectorElement & operator[](size_t i) const noexcept
Definition: ExposedVector.h:167
void pop_back() noexcept
Definition: ExposedVector.h:200
iterator begin() noexcept
Definition: ExposedVector.h:123
const_iterator cend() const noexcept
Definition: ExposedVector.h:143
void resize(const size_t new_size)
Definition: ExposedVector.h:151
void push_back(VectorElement &&f)
Definition: ExposedVector.h:191
ExposedVector & operator=(const ExposedVector &rhs)=default
Assignment.
VectorElement & at(size_t i)
Definition: ExposedVector.h:171
typename VecMember::reference reference
Definition: ExposedVector.h:93
VectorElement & operator[](size_t i) noexcept
Definition: ExposedVector.h:163
const VectorElement & at(size_t i) const
Definition: ExposedVector.h:175
ExposedVector(const size_t n, const VectorElement &val)
Definition: ExposedVector.h:106
const_iterator cbegin() const noexcept
Definition: ExposedVector.h:139
void push_back(const VectorElement &f)
Definition: ExposedVector.h:187
VecMember & getData()
read access to the underlying data
Definition: ExposedVector.h:224
ExposedVector(const ExposedVector &rhs)=default
Copy C'tor.
ExposedVector(Iter begin, Iter end)
Definition: ExposedVector.h:109
typename VecMember::const_reverse_iterator const_reverse_iterator
Definition: ExposedVector.h:90
const VecMember & getData() const
read-only access to the underlying data
Definition: ExposedVector.h:219
iterator erase(const_iterator where) noexcept
Definition: ExposedVector.h:204
iterator erase(const_iterator from, const_iterator to) noexcept
Definition: ExposedVector.h:208
iterator end() noexcept
Definition: ExposedVector.h:127
custom arguments to allow for looping calls
Definition: WizardHelper.h:73
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48