| PST SDK 6.0.0.0-272350a

PstVector.h
Go to the documentation of this file.
1 // Copyright PS-Tech B.V. All Rights Reserved.
2
3 #pragma once
4
5 #include "PstBase.h"
6
7 #include <cstddef>
8
9 namespace PSTech
10 {
11 namespace Utils
12 {
28 template<typename T>
29 class PST_EXPORT PstVector
30 {
31 public:
32 typedef T value_type;
33 typedef size_t size_type;
34 typedef T* pointer;
35 typedef const T* const_pointer;
36 typedef T& reference;
37 typedef const T& const_reference;
38 typedef T* iterator;
39 typedef const T* const_iterator;
40
42 PstVector();
43
45 explicit PstVector(size_type size);
46
48 PstVector(size_type size, const_reference data);
49
51 PstVector(const PstVector& vector);
52
54 PstVector(PstVector&& vector) noexcept;
55
57 ~PstVector();
58
60 PstVector& operator=(const PstVector& vector);
61
63 PstVector& operator=(PstVector&& vector) noexcept;
64
66 void swap(PstVector& vector) noexcept;
67
73 size_type size() const;
74
80 size_type capacity() const;
81
83 bool empty() const;
84
91 void reserve(size_type size);
92
98 void resize(size_type size);
99
105 void resize(size_type size, const_reference data);
106
111 void clear();
112
117 void assign(size_type count, const_reference data);
118
123 void push_back(const_reference data);
124
129 void push_back(T&& data);
130
134 void pop_back();
135
141 const_reference at(size_type index) const;
142
148 reference at(size_type index);
149
151 const_reference front() const;
152
154 reference front();
155
157 const_reference back() const;
158
160 reference back();
161
163 const_iterator cbegin() const;
164
166 const_iterator begin() const;
167
169 iterator begin();
170
172 const_iterator cend() const;
173
175 const_iterator end() const;
176
178 iterator end();
179
181 const_reference operator [] (size_type index) const;
182
184 reference operator [] (size_type index);
185
186 private:
188 class Allocator
189 {
190 public:
192 typename PstVector<T>::pointer allocate(typename PstVector<T>::size_type num);
193
195 void construct(typename PstVector<T>::pointer p);
196
198 template<class... A>
199 void construct(typename PstVector<T>::pointer p, A&... arg);
200
202 void construct(typename PstVector<T>::pointer p, T&& data);
203
204 /* Destroy elements of initialized storage p */
205 void destroy(typename PstVector<T>::pointer p);
206
207 /* Deallocate storage p of deleted elements */
208 void deallocate(typename PstVector<T>::pointer p);
209 };
210
211 size_type m_size;
212 size_type m_allocated;
213 pointer m_array;
214 Allocator m_allocator;
215
216 void resize_internal(size_type size, const_pointer data);
217
218 void check_bounds(size_type index) const;
219 };
220 }
221 }
PSTech::Utils::PstVector
Basic vector class, cloning std::vector<T>.
Definition: PstVector.h:29
PSTech
Definition: ExportedTypeConversions.h:8
PSTech::Utils::PstVector::iterator
T * iterator
Definition: PstVector.h:38
PSTech::Utils::PstVector::const_pointer
const T * const_pointer
Definition: PstVector.h:35
PSTech::Utils::PstVector::reference
T & reference
Definition: PstVector.h:36
PST_EXPORT
#define PST_EXPORT
Definition: PstBase.h:12
PSTech::Utils::PstVector::value_type
T value_type
Definition: PstVector.h:32
PSTech::Utils::PstVector::Allocator
Definition: PstVector.h:188
PSTech::Utils::PstVector::m_array
pointer m_array
Definition: PstVector.h:213
PSTech::Utils::PstVector::m_size
size_type m_size
Definition: PstVector.h:211
PSTech::Utils::PstVector::m_allocated
size_type m_allocated
Definition: PstVector.h:212
PSTech::Utils::PstVector::m_allocator
Allocator m_allocator
Definition: PstVector.h:214
PSTech::Utils::PstVector::const_reference
const T & const_reference
Definition: PstVector.h:37
PSTech::Utils::PstVector::size_type
size_t size_type
Definition: PstVector.h:33
PSTech::Utils::PstVector::pointer
T * pointer
Definition: PstVector.h:34
PSTech::Utils::PstVector::const_iterator
const T * const_iterator
Definition: PstVector.h:39
PstBase.h