Loading...
Searching...
No Matches
piercedVector.hpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25#ifndef __BITPIT_PIERCED_VECTOR_HPP__
26#define __BITPIT_PIERCED_VECTOR_HPP__
27
28#include <cassert>
29
30#include "piercedVectorKernel.hpp"
31#include "piercedVectorStorage.hpp"
32
33#define __PV_REFERENCE__ typename PiercedVector<value_t, id_t>::reference
34#define __PV_CONST_REFERENCE__ typename PiercedVector<value_t, id_t>::const_reference
35#define __PV_POINTER__ typename PiercedVector<value_t, id_t>::pointer
36#define __PV_CONST_POINTER__ typename PiercedVector<value_t, id_t>::const_pointer
37
38namespace bitpit {
39
41
42public:
43 virtual ~BasePiercedVector() = default;
44
45protected:
47
48};
49
62template<typename value_t, typename id_t = long>
64 public PiercedVectorKernel<id_t>,
65 public PiercedVectorStorage<value_t, id_t> {
66
67protected:
68 // According to Visual Studio 2022 documentation (see Compiler Error C2668), "if, in the
69 // same class, you have a regular member function and a templated member function with
70 // the same signature, the templated one must come first. This limitation remains in the
71 // current implementation of Visual C++."
75 using PiercedVectorKernel<id_t>::sort;
80 using PiercedVectorKernel<id_t>::swap;
81
82 using PiercedVectorStorage<value_t, id_t>::setStaticKernel;
83 using PiercedVectorStorage<value_t, id_t>::setDynamicKernel;
84 using PiercedVectorStorage<value_t, id_t>::unsetKernel;
85 using PiercedVectorStorage<value_t, id_t>::getKernel;
86 using PiercedVectorStorage<value_t, id_t>::getKernelType;
87 using PiercedVectorStorage<value_t, id_t>::getSyncMode;
88
89public:
90 // Typedefs
91
96
101
106
111
116
121
126
131
136
137 // Contructors
139 PiercedVector(std::size_t n);
142
145
146 // Methods that modify the contents of the container
147 iterator reclaim(id_t id);
148 iterator reclaimAfter(const id_t &referenceId, id_t id);
149 iterator reclaimBack(id_t id);
150 iterator reclaimBefore(const id_t &referenceId, id_t id);
151
152 iterator moveAfter(const id_t &referenceId, id_t id, bool delayed = false);
153 iterator moveBefore(const id_t &referenceId, id_t id, bool delayed = false);
154
155 iterator insert(id_t id, const value_t &value);
156 iterator insertAfter(const id_t &referenceId, id_t id, const value_t &value);
157 iterator insertBefore(const id_t &referenceId, id_t id, const value_t &value);
158
159 iterator replace(id_t id, value_t &&value);
160
161 iterator pushBack(id_t id, const value_t &value);
162
163 template<typename... Args, typename PiercedStorage<value_t,id_t>::template EnableIfHasInitialize<Args...> * = nullptr>
164 iterator emreclaim(id_t id, Args&&... args);
165 template<typename... Args, typename PiercedStorage<value_t,id_t>::template EnableIfHasInitialize<Args...> * = nullptr>
166 iterator emreclaimAfter(const id_t &referenceId, id_t id, Args&&... args);
167 template<typename... Args, typename PiercedStorage<value_t,id_t>::template EnableIfHasInitialize<Args...> * = nullptr>
168 void emreclaimBack(id_t id, Args&&... args);
169 template<typename... Args, typename PiercedStorage<value_t,id_t>::template EnableIfHasInitialize<Args...> * = nullptr>
170 iterator emreclaimBefore(const id_t &referenceId, id_t id, Args&&... args);
171
172 template<typename... Args>
173 iterator emplace(id_t id, Args&&... args);
174 template<typename... Args>
175 iterator emplaceAfter(const id_t &referenceId, id_t id, Args&&... args);
176 template<typename... Args>
177 void emplaceBack(id_t id, Args&&... args);
178 template<typename... Args>
179 iterator emplaceBefore(const id_t &referenceId, id_t id, Args&&... args);
180
181 template<typename... Args>
182 iterator emreplace(id_t id, Args&&... args);
183
184 iterator erase(id_t id, bool delayed = false);
185 void popBack();
186
187 void swap(id_t id_first, id_t id_second);
188
189 // Methods that modify the container as a whole
190 void clear(bool release = true);
191 void reserve(std::size_t n);
192 void resize(std::size_t n);
193 void sort();
194 void sortAfter(id_t referenceId, bool inclusive);
195 void sortBefore(id_t referenceId, bool inclusive);
196 void squeeze();
197 void shrinkToFit();
198 void swap(PiercedVector &other) noexcept;
199
200 // Methods that extract information about the container
201 const PiercedVectorKernel<id_t> & getKernel() const;
203
204 void dump() const;
205
206 // Methods that extract the contents of the container
207 using PiercedVectorStorage<value_t, id_t>::back;
208 using PiercedVectorStorage<value_t, id_t>::front;
209
210 using PiercedVectorStorage<value_t, id_t>::at;
211 using PiercedVectorStorage<value_t, id_t>::rawAt;
212
213 using PiercedVectorStorage<value_t, id_t>::operator[];
214
215 // Iterators
216 using PiercedVectorStorage<value_t, id_t>::begin;
217 using PiercedVectorStorage<value_t, id_t>::end;
218 using PiercedVectorStorage<value_t, id_t>::cbegin;
219 using PiercedVectorStorage<value_t, id_t>::cend;
220
221 using PiercedVectorStorage<value_t, id_t>::rawBegin;
222 using PiercedVectorStorage<value_t, id_t>::rawEnd;
223 using PiercedVectorStorage<value_t, id_t>::rawCbegin;
224 using PiercedVectorStorage<value_t, id_t>::rawCend;
225
226 using PiercedVectorStorage<value_t, id_t>::find;
227 using PiercedVectorStorage<value_t, id_t>::rawFind;
228
229 // Dump and restore
230 template<typename T = value_t, typename std::enable_if<std::is_pod<T>::value || PiercedVectorStorage<T, id_t>::has_restore()>::type * = nullptr>
231 void restore(std::istream &stream);
232
233 template<typename T = value_t, typename std::enable_if<std::is_pod<T>::value || PiercedVectorStorage<T, id_t>::has_dump()>::type * = nullptr>
234 void dump(std::ostream &stream) const;
235
236 void restoreKernel(std::istream &stream);
237
238 void dumpKernel(std::ostream &stream) const;
239
240private:
251
252 iterator reclaimValue(const FillAction &action);
253 iterator insertValue(const FillAction &action, const value_t &value);
254 template<typename... Args, typename PiercedStorage<value_t,id_t>::template EnableIfHasInitialize<Args...> * = nullptr>
255 iterator emreclaimValue(const FillAction &action, Args&&... args);
256 template<typename... Args>
257 iterator emplaceValue(const FillAction &action, Args&&... args);
258
259 iterator moveValue(const MoveAction &action);
260
261 void swapValues(const SwapAction &action);
262
263 iterator eraseValue(const EraseAction &action);
264
265};
266
267}
268
269// Include the implementation
270#include "piercedVector.tpp"
271
272#endif
Base class for pierced vectors.
const_iterator rawFind(std::size_t pos) const noexcept
const_iterator cend() const noexcept
const_iterator find(const id_t &id) const noexcept
const_iterator begin() const noexcept
const_iterator cbegin() const noexcept
const_iterator end() const noexcept
Iterator for the class PiercedStorage.
The PiercedStorageRange allow to iterate using range-based loops over a PiercedStorage.
PiercedSyncMaster::SyncMode getSyncMode() const
void unsetKernel(bool release=true)
Metafunction for generating a pierced storage.
raw_iterator rawBegin() noexcept
raw_iterator rawEnd() noexcept
std::vector< value_t >::const_iterator raw_const_iterator
std::vector< value_t >::iterator raw_iterator
typename std::enable_if< PiercedStorage< value_t, id_t >::template has_initialize< Args... >()>::type EnableIfHasInitialize
static constexpr bool has_dump()
static constexpr bool has_restore()
raw_const_iterator rawCbegin() const noexcept
raw_const_iterator rawCend() const noexcept
Kernel of the pierced vector.
Kernel of the pierced vector.
void setStaticKernel(const PiercedVectorKernel< id_t > *kernel)
__PVS_REFERENCE__ at(id_t id)
__PVS_REFERENCE__ rawAt(std::size_t pos)
void setDynamicKernel(const PiercedVectorKernel< id_t > *kernel, PiercedSyncMaster::SyncMode syncMode)
Metafunction for generating a pierced vector.
PiercedVectorStorage< value_t, id_t >::const_range const_range
iterator emplaceBefore(const id_t &referenceId, id_t id, Args &&... args)
void restore(std::istream &stream)
iterator insert(id_t id, const value_t &value)
iterator insertBefore(const id_t &referenceId, id_t id, const value_t &value)
iterator emreclaimAfter(const id_t &referenceId, id_t id, Args &&... args)
iterator replace(id_t id, value_t &&value)
iterator emplace(id_t id, Args &&... args)
const PiercedVectorKernel< id_t > & getKernel() const
iterator emreclaimBefore(const id_t &referenceId, id_t id, Args &&... args)
const PiercedVectorStorage< value_t, id_t > & getStorage() const
iterator reclaimBefore(const id_t &referenceId, id_t id)
void clear(bool release=true)
iterator reclaim(id_t id)
iterator emreclaim(id_t id, Args &&... args)
PiercedVectorStorage< value_t, id_t >::raw_const_iterator raw_const_iterator
void sortAfter(id_t referenceId, bool inclusive)
iterator pushBack(id_t id, const value_t &value)
PiercedVectorKernel< id_t >::id_type id_type
iterator erase(id_t id, bool delayed=false)
void swap(id_t id_first, id_t id_second)
PiercedVectorStorage< value_t, id_t >::const_iterator const_iterator
PiercedVector< value_t, id_t > & operator=(const PiercedVector< value_t, id_t > &other)
iterator emreplace(id_t id, Args &&... args)
void restoreKernel(std::istream &stream)
iterator reclaimBack(id_t id)
PiercedVectorStorage< value_t, id_t >::range range
iterator moveAfter(const id_t &referenceId, id_t id, bool delayed=false)
iterator insertAfter(const id_t &referenceId, id_t id, const value_t &value)
PiercedVectorStorage< value_t, id_t >::raw_iterator raw_iterator
void sortBefore(id_t referenceId, bool inclusive)
iterator reclaimAfter(const id_t &referenceId, id_t id)
PiercedVectorStorage< value_t, id_t >::iterator iterator
PiercedVectorStorage< value_t, id_t >::value_type value_type
void emreclaimBack(id_t id, Args &&... args)
void emplaceBack(id_t id, Args &&... args)
void dumpKernel(std::ostream &stream) const
void reserve(std::size_t n)
void resize(std::size_t n)
PiercedVectorKernel< id_t > kernel_type
iterator moveBefore(const id_t &referenceId, id_t id, bool delayed=false)
iterator emplaceAfter(const id_t &referenceId, id_t id, Args &&... args)
--- layout: doxygen_footer ---