Loading...
Searching...
No Matches
flatVector2D.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_FLAT_VECTOR_2D_HPP__
26#define __BITPIT_FLAT_VECTOR_2D_HPP__
27
28#include <vector>
29#include <cassert>
30#include <iostream>
31#include <memory>
32
33#include "binary_stream.hpp"
34
35namespace bitpit{
36
37template<class T>
38class FlatVector2D;
39
40template<class T>
41OBinaryStream& operator<<(OBinaryStream &buffer, const FlatVector2D<T> &vector);
42
43template<class T>
44IBinaryStream& operator>>(IBinaryStream &buffer, FlatVector2D<T> &vector);
45
58template <class T>
60{
61
62template<class U>
63friend OBinaryStream& (operator<<) (OBinaryStream &buffer, const FlatVector2D<U> &vector);
64template<class U>
66
67public:
68 FlatVector2D(bool initialize = true);
69 FlatVector2D(const std::vector<std::size_t> &sizes, const T &value = T());
70 FlatVector2D(std::size_t nVectors, std::size_t size, const T &value = T());
71 FlatVector2D(std::size_t nVectors, const std::size_t *sizes, const T &value);
72 FlatVector2D(std::size_t nVectors, const std::size_t *sizes, const T *values);
73 FlatVector2D(const std::vector<std::vector<T> > &vector2D);
74 FlatVector2D(const FlatVector2D &other) = default;
75 FlatVector2D(FlatVector2D &&other) = default;
76
84
92
93 bool isInitialized() const;
94
95 void initialize(const std::vector<std::size_t> &sizes, const T &value = T());
96 void initialize(std::size_t nVectors, std::size_t size, const T &value = T());
97 void initialize(std::size_t nVectors, const std::size_t *sizes, const T &value);
98 void initialize(std::size_t nVectors, const std::size_t *sizes, const T *values);
99 void initialize(const std::vector<std::vector<T> > &vector2D);
100 void initialize(const FlatVector2D<T> &other);
101
102 void destroy();
103 void reserve(std::size_t nVectors, std::size_t nItems = 0);
104 void swap(FlatVector2D &other) noexcept;
105 bool operator==(const FlatVector2D& rhs) const;
106 void fill(T &value);
107 bool empty() const;
108
109 void clear(bool release = true);
110 void clearItems(bool release = true);
111 void shrinkToFit();
112
113 const std::size_t * indices() const noexcept;
114 const std::size_t * indices(std::size_t i) const noexcept;
115
116 T * data() noexcept;
118 const std::vector<T> & vector() const;
119
120 void pushBack();
121 void pushBack(std::size_t subArraySize, const T &value = T());
122 void pushBack(const std::vector<T> &subArray);
123 void pushBack(std::size_t subArraySize, const T *subArray);
124 void pushBackItem(const T& value);
125 void pushBackItem(T &&value);
126 void pushBackItem(std::size_t i, const T& value);
127 void pushBackItem(std::size_t i, T &&value);
128
129 void popBack();
130 void popBackItem();
131 void popBackItem(std::size_t i);
132
133 void erase(std::size_t i);
134 void eraseItem(std::size_t i, std::size_t j);
135
136 void setItem(std::size_t i, std::size_t j, const T &value);
137 void setItem(std::size_t i, std::size_t j, T &&value);
138 T & getItem(std::size_t i, std::size_t j);
139 const T & getItem(std::size_t i, std::size_t j) const;
140 const T * get(std::size_t i) const;
141 T * get(std::size_t i);
142
143 void rawSetItem(std::size_t k, const T &value);
144 void rawSetItem(std::size_t k, T &&value);
145 T & rawGetItem(std::size_t k);
146 const T & rawGetItem(std::size_t k) const;
147
148 T * back();
149 T * first();
150
151 std::size_t size() const;
152 std::size_t capacity() const;
153
154 void merge();
155
156 std::size_t getItemCount() const;
157 std::size_t getItemCount(std::size_t i) const;
158 std::size_t getItemCapacity() const;
159
160 std::size_t getBinarySize() const;
161
162private:
163 std::vector<T> m_v;
164 std::vector<std::size_t> m_index;
165
166 const T* operator[](std::size_t i) const;
167 T* operator[](std::size_t i);
168 bool isIndexValid(std::size_t i) const;
169 bool isIndexValid(std::size_t i, std::size_t j) const;
170
171 void initialize(std::size_t nVectors, const std::size_t *sizes, std::size_t sizesStride, const T *values, std::size_t valuesStride);
172
173 void destroy(bool destroyIndex, bool destroyValues);
174
175};
176
177}
178
179// Include the implementation
180#include "flatVector2D.tpp"
181
182#endif
Metafunction for generation of a flattened vector of vectors.
const std::size_t * indices() const noexcept
bool isInitialized() const
void clearItems(bool release=true)
T & getItem(std::size_t i, std::size_t j)
bool operator==(const FlatVector2D &rhs) const
FlatVector2D & operator=(FlatVector2D &&other)=default
void swap(FlatVector2D &other) noexcept
T & rawGetItem(std::size_t k)
const std::vector< T > & vector() const
std::size_t getItemCapacity() const
FlatVector2D(bool initialize=true)
void rawSetItem(std::size_t k, const T &value)
std::size_t size() const
void clear(bool release=true)
void reserve(std::size_t nVectors, std::size_t nItems=0)
std::size_t getItemCount() const
void initialize(const std::vector< std::size_t > &sizes, const T &value=T())
void eraseItem(std::size_t i, std::size_t j)
void erase(std::size_t i)
const T * get(std::size_t i) const
std::size_t capacity() const
std::size_t getBinarySize() const
void setItem(std::size_t i, std::size_t j, const T &value)
void pushBackItem(const T &value)
FlatVector2D & operator=(const FlatVector2D &other)=default
Output binary stream.
Output binary stream.
std::ostream & operator<<(std::ostream &, const std::vector< T > &)
--- layout: doxygen_footer ---