OpenMS
ExposedVector.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Chris Bielow $
6 // $Authors: Chris Bielow $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 
12 #include <cstddef> // for size_t
13 #include <vector>
14 
15 namespace OpenMS
16 {
17 
19 #define EXPOSED_VECTOR_INTERFACE(InnerElement) \
20  using ExpVec = ExposedVector< InnerElement >; \
21  using ExpVec::ExposedVector; \
22  using value_type = typename ExpVec::value_type; \
23  using iterator = typename ExpVec::iterator; \
24  using const_iterator = typename ExpVec::const_iterator; \
25  using reverse_iterator = typename ExpVec::reverse_iterator; \
26  using const_reverse_iterator = typename ExpVec::const_reverse_iterator; \
27  using size_type = typename ExpVec::size_type; \
28  using pointer = typename ExpVec::pointer; \
29  using reference = typename ExpVec::reference; \
30  using const_reference = typename ExpVec::const_reference; \
31  using difference_type = typename ExpVec::difference_type; \
32 
33 
53  template<class VectorElement>
55  {
56  public:
57  using VecMember = std::vector<VectorElement>;
58 
59  // types
60  using value_type = typename VecMember::value_type;
61  using iterator = typename VecMember::iterator;
62  using const_iterator = typename VecMember::const_iterator;
63  using reverse_iterator = typename VecMember::reverse_iterator;
64  using const_reverse_iterator = typename VecMember::const_reverse_iterator;
65  using size_type = typename VecMember::size_type;
66  using pointer = typename VecMember::pointer;
67  using reference = typename VecMember::reference;
68  using const_reference = typename VecMember::const_reference;
69  using difference_type = typename VecMember::difference_type;
70 
71  protected:
73 
74  public:
75  ExposedVector() = default;
76  explicit ExposedVector(const size_t n)
77  : data_(n)
78  {
79  }
80  ExposedVector(const size_t n, const VectorElement& val) : data_(n, val)
81  {
82  }
83  template <class Iter> ExposedVector(Iter begin, Iter end)
84  : data_(begin, end)
85  {
86  }
88  ExposedVector(const ExposedVector& rhs) = default;
90  ExposedVector(ExposedVector&& rhs) noexcept = default;
91 
93  ExposedVector& operator=(const ExposedVector& rhs) = default;
95  ExposedVector& operator=(ExposedVector&& rhs) noexcept = default;
96 
97  iterator begin() noexcept
98  {
99  return data_.begin();
100  }
101  iterator end() noexcept
102  {
103  return data_.end();
104  }
105  const_iterator begin() const noexcept
106  {
107  return data_.begin();
108  }
109  const_iterator end() const noexcept
110  {
111  return data_.end();
112  }
113  const_iterator cbegin() const noexcept
114  {
115  return data_.cbegin();
116  }
117  const_iterator cend() const noexcept
118  {
119  return data_.cend();
120  }
121  size_t size() const noexcept
122  {
123  return data_.size();
124  }
125  void resize(const size_t new_size)
126  {
127  data_.resize(new_size);
128  }
129  void reserve(const size_t new_size)
130  {
131  data_.reserve(new_size);
132  }
133  bool empty() const noexcept
134  {
135  return data_.empty();
136  }
137  VectorElement& operator[](size_t i) noexcept
138  {
139  return data_[i];
140  }
141  const VectorElement& operator[](size_t i) const noexcept
142  {
143  return data_[i];
144  }
145  VectorElement& at(size_t i)
146  {
147  return data_.at(i);
148  }
149  const VectorElement& at(size_t i) const
150  {
151  return data_.at(i);
152  }
153  VectorElement& back() noexcept
154  {
155  return data_.back();
156  }
157  const VectorElement& back() const noexcept
158  {
159  return data_.back();
160  }
161  void push_back(const VectorElement& f)
162  {
163  data_.push_back(f);
164  }
165  void push_back(VectorElement&& f)
166  {
167  data_.push_back(std::move(f));
168  }
169  template<typename... Args>
170  decltype(auto) emplace_back(Args&&... args)
171  {
172  return data_.emplace_back(std::forward<Args>(args)...);
173  }
174  void pop_back() noexcept
175  {
176  data_.pop_back();
177  }
178  iterator erase(const_iterator where) noexcept
179  {
180  return data_.erase(where);
181  }
183  {
184  return data_.erase(from, to);
185  }
186  template<typename T>
187  iterator insert(const_iterator where, T from, T to)
188  {
189  return data_.insert(where, from, to);
190  }
191 
193  const VecMember& getData() const
194  {
195  return data_;
196  }
199  {
200  return data_;
201  }
202  };
203 
204 } // namespace OpenMS
Definition: ExposedVector.h:55
iterator insert(const_iterator where, T from, T to)
Definition: ExposedVector.h:187
std::vector< VectorElement > VecMember
Definition: ExposedVector.h:57
typename VecMember::iterator iterator
Definition: ExposedVector.h:61
const_iterator begin() const noexcept
Definition: ExposedVector.h:105
typename VecMember::const_iterator const_iterator
Definition: ExposedVector.h:62
void reserve(const size_t new_size)
Definition: ExposedVector.h:129
typename VecMember::pointer pointer
Definition: ExposedVector.h:66
size_t size() const noexcept
Definition: ExposedVector.h:121
bool empty() const noexcept
Definition: ExposedVector.h:133
ExposedVector(const size_t n)
Definition: ExposedVector.h:76
decltype(auto) emplace_back(Args &&... args)
Definition: ExposedVector.h:170
typename VecMember::size_type size_type
Definition: ExposedVector.h:65
VectorElement & back() noexcept
Definition: ExposedVector.h:153
typename VecMember::value_type value_type
Definition: ExposedVector.h:60
const_iterator end() const noexcept
Definition: ExposedVector.h:109
typename VecMember::reverse_iterator reverse_iterator
Definition: ExposedVector.h:63
typename VecMember::const_reference const_reference
Definition: ExposedVector.h:68
ExposedVector(ExposedVector &&rhs) noexcept=default
Move C'tor.
const VectorElement & back() const noexcept
Definition: ExposedVector.h:157
typename VecMember::difference_type difference_type
Definition: ExposedVector.h:69
VecMember data_
the container which holds all the data
Definition: ExposedVector.h:72
ExposedVector & operator=(ExposedVector &&rhs) noexcept=default
Move Assignment.
const VectorElement & operator[](size_t i) const noexcept
Definition: ExposedVector.h:141
void pop_back() noexcept
Definition: ExposedVector.h:174
iterator begin() noexcept
Definition: ExposedVector.h:97
const_iterator cend() const noexcept
Definition: ExposedVector.h:117
void resize(const size_t new_size)
Definition: ExposedVector.h:125
void push_back(VectorElement &&f)
Definition: ExposedVector.h:165
ExposedVector & operator=(const ExposedVector &rhs)=default
Assignment.
VectorElement & at(size_t i)
Definition: ExposedVector.h:145
typename VecMember::reference reference
Definition: ExposedVector.h:67
VectorElement & operator[](size_t i) noexcept
Definition: ExposedVector.h:137
const VectorElement & at(size_t i) const
Definition: ExposedVector.h:149
ExposedVector(const size_t n, const VectorElement &val)
Definition: ExposedVector.h:80
const_iterator cbegin() const noexcept
Definition: ExposedVector.h:113
void push_back(const VectorElement &f)
Definition: ExposedVector.h:161
VecMember & getData()
read access to the underlying data
Definition: ExposedVector.h:198
ExposedVector(const ExposedVector &rhs)=default
Copy C'tor.
ExposedVector(Iter begin, Iter end)
Definition: ExposedVector.h:83
typename VecMember::const_reverse_iterator const_reverse_iterator
Definition: ExposedVector.h:64
const VecMember & getData() const
read-only access to the underlying data
Definition: ExposedVector.h:193
iterator erase(const_iterator where) noexcept
Definition: ExposedVector.h:178
iterator erase(const_iterator from, const_iterator to) noexcept
Definition: ExposedVector.h:182
iterator end() noexcept
Definition: ExposedVector.h:101
custom arguments to allow for looping calls
Definition: WizardHelper.h:47
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19