Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
VectorLike.h
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2016 The SKA organisation
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #ifndef SKA_CHEETAH_DATA_VECTORLIKE_H
25 #define SKA_CHEETAH_DATA_VECTORLIKE_H
26 
27 #include <cstddef>
28 #include <type_traits>
29 
30 namespace ska {
31 namespace cheetah {
32 namespace data {
33 
43 template <typename VectorType>
45 {
47 
48  public:
49  typedef typename VectorType::iterator Iterator;
50  typedef typename VectorType::const_iterator ConstIterator;
51  typedef typename VectorType::reverse_iterator ReverseIterator;
52  typedef typename VectorType::pointer Pointer;
53  typedef typename VectorType::const_pointer ConstPointer;
54  typedef typename VectorType::reference Reference;
55  typedef typename VectorType::const_reference ConstReference;
56  typedef typename VectorType::value_type ValueType;
57  typedef typename VectorType::allocator_type AllocatorType;
58 
59  public:
63  VectorLike();
64 
68  explicit VectorLike(AllocatorType const& allocator);
69 
75  template<typename... Args>
76  explicit VectorLike(std::size_t n, Args&&... args);
77 
84  explicit VectorLike(std::size_t n, const ValueType& value, AllocatorType const& allocator=AllocatorType());
85  ~VectorLike();
86 
90  std::size_t size() const;
91 
95  ValueType const& front() const;
96  ValueType& front();
97 
101  ValueType const& back() const;
102  ValueType& back();
103 
109  void resize(std::size_t size, const ValueType &x = ValueType());
110 
118  Reference operator[](std::size_t n);
119 
127  ConstReference operator[](std::size_t n) const;
128 
134  Iterator begin();
135 
141  ConstIterator begin() const;
142  ConstIterator cbegin() const;
143 
149  ReverseIterator rbegin();
150 
156  Iterator end();
157 
163  ConstIterator end() const;
164 
170  ConstIterator cend() const;
171 
176  ReverseIterator rend();
177 
183  Pointer data();
184 
190  ConstPointer data() const;
191 
197  void push_back(ValueType const& value);
198 
204  template<typename ...Args>
205  void emplace_back(Args&&... value);
206 
212  void reserve(std::size_t size);
213 
219  std::size_t capacity() const;
220 
226  void swap(VectorLike &v);
227 
231  Iterator erase(Iterator pos);
232 
233  Iterator erase(Iterator first, Iterator last);
234 
238  Iterator insert(Iterator pos, const ValueType& value);
239 
240  ConstIterator insert(ConstIterator pos, ValueType&& value);
241 
242  ConstIterator insert(ConstIterator pos, const ValueType& value);
243 
244  Iterator insert(Iterator pos, ValueType&& value);
245 
246  template<typename...Args>
247  Iterator emplace(Iterator pos, Args&&...);
248 
249  template<typename...Args>
250  ConstIterator emplace(ConstIterator pos, Args&&...);
251 
255  SelfType& operator+=(SelfType const&);
256 
260  bool empty() const;
261 
265  void clear();
266 
270  AllocatorType allocator() const;
271 
272  private:
273  VectorType _data;
274 };
275 
276 } // namespace data
277 } // namespace cheetah
278 } // namespace ska
279 
280 #include "cheetah/data/detail/VectorLike.cpp"
281 
282 #endif // SKA_CHEETAH_DATA_VECTORLIKE_H
ValueType const & front() const
the first emelment
Definition: VectorLike.cpp:232
ValueType const & back() const
the last emelment
Definition: VectorLike.cpp:244
void resize(std::size_t size, const ValueType &x=ValueType())
Resize the vector.
Definition: VectorLike.cpp:67
Pointer data()
Return a pointer pointing to the start of the vector.
Definition: VectorLike.cpp:133
Reference operator[](std::size_t n)
Subscript access to the data contained in the underlying vector.
Definition: VectorLike.cpp:73
ConstIterator cend() const
A constant iterator pointing to the end of the vector.
Definition: VectorLike.cpp:121
std::size_t size() const
Retrieve the size of the underlying vector.
Definition: VectorLike.cpp:61
void emplace_back(Args &&... value)
Appends element to end of vector using the move operator.
Definition: VectorLike.cpp:152
Class that wraps objects that export the std::vector interface.
Definition: VectorLike.h:44
AllocatorType allocator() const
return the allocator
Definition: VectorLike.cpp:271
Some limits and constants for FLDO.
Definition: Brdz.h:35
void clear()
clear the data
Definition: VectorLike.cpp:256
void push_back(ValueType const &value)
Appends element to end of vector.
Definition: VectorLike.cpp:145
void reserve(std::size_t size)
Reserve space for this many elements.
Definition: VectorLike.cpp:158
void swap(VectorLike &v)
swaps the contents of this vector_base with another vector
Definition: VectorLike.cpp:170
ReverseIterator rbegin()
A reverse iterator pointing to the end of the vector (i.e the last element).
Definition: VectorLike.cpp:103
VectorLike()
Construct a VectorLike instance.
Definition: VectorLike.cpp:32
Iterator end()
An iterator pointing to the end of the vector.
Definition: VectorLike.cpp:109
bool empty() const
return true if the vector is empty
Definition: VectorLike.cpp:250
std::size_t capacity() const
The reseved size of the vector.
Definition: VectorLike.cpp:164
Iterator insert(Iterator pos, const ValueType &value)
insert a value in the vector_base
Definition: VectorLike.cpp:188
SelfType & operator+=(SelfType const &)
add the contents of the argument to the current vector
Definition: VectorLike.cpp:262
Iterator erase(Iterator pos)
erase the element from a given position or a range of positions
Definition: VectorLike.cpp:176
Iterator begin()
An iterator pointing to the start of the vector.
Definition: VectorLike.cpp:85