NDEVR
API Documentation
BoolVector.hpp
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: BoolVector
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/BaseValues.h>
34#include <NDEVR/LibAssert.h>
35#include <NDEVR/Vector.h>
36#include <NDEVR/BitReference.h>
37namespace NDEVR
38{
43 template<uint01 t_dims>
44 class Vector<t_dims, bool>
45 {
46 public:
47 constexpr Vector() = default;
48 constexpr Vector(const Vector<t_dims, bool>& vector)
49 {
50 for (uint01 dim = 0; dim < sizeof(Vector<t_dims, bool>); ++dim)
51 m_values[dim] = vector.m_values[dim];
52 }
63 template<class t_vec_type>
64 constexpr Vector(const Vector<t_dims, t_vec_type>& vector)
65 {
66 for (uint01 dim = 0; dim < t_dims; ++dim)
67 m_values[dim] = cast<bool>(vector[dim]);
68 }
69
80
81 constexpr explicit Vector(const bool& value)
82 {
83 for (uint01 dim = 0; dim < ByteCount(); ++dim)
84 m_values[dim] = BitFlag(value);
85 }
86
87
88 Vector(std::initializer_list<bool> active_list)
89 {
90 uint04 i = 0;
91 for (auto val : active_list)
92 (*this)(i++, val);
93 }
94
95 template<class t_type>
96 Vector(std::initializer_list<t_type> active_list)
97 {
98 for (auto i : active_list)
99 (*this)(cast<uint01>(i), true);
100 }
101
102 constexpr void operator()(const uint01 dim, bool value)
103 {
104 m_values[dim / 8](dim % 8, value);
105 }
106
119 constexpr Vector(const bool& x, const bool& y)
120 {
121 static_assert(t_dims == 2, "Unexpected Number of Dimensions. Vector Size Required: 2");
122 m_values[0](X, x);
123 m_values[0](Y, y);
124 }
125
133 constexpr Vector(const bool& x, const bool& y, const bool& z)
134 {
135 static_assert(t_dims == 3, "Unexpected Number of Dimensions. Vector Size Required: 3");
136 m_values[0](X, x);
137 m_values[0](Y, y);
138 m_values[0](Z, z);
139 }
140
149 constexpr Vector(const bool& x, const bool& y, const bool& z, const bool& w)
150 {
151 static_assert(t_dims == 4, "Unexpected Number of Dimensions. Vector Size Required: 4");
152 m_values[0](X, x);
153 m_values[0](Y, y);
154 m_values[0](Z, z);
155 m_values[0](W, w);
156 }
157
162 constexpr explicit Vector(const bool(&vector)[t_dims])
163 {
164 for (uint01 dim = 0; dim < t_dims; dim++)
165 m_values[dim / 8](dim % 8, vector[dim]);
166 }
167
173 constexpr Vector(const Vector<t_dims - 1, bool>& vector, const bool& suffix)
174 {
175 static_assert(t_dims >= 2, "Unexpected Number of Dimensions. Vector Size Required: >= 2");
176 for (uint01 dim = 0; dim < t_dims - 1; ++dim)
177 m_values[dim / 8](dim % 8, vector[dim]);
178 m_values[(t_dims - 1) / 8]((t_dims - 1) % 8, suffix);
179 }
180
187 constexpr Vector(const Vector<getMax(t_dims - 2, 0), bool>& vector, const bool& suffix_a, const bool& suffix_b)
188 {
189 static_assert(t_dims >= 3, "Unexpected Number of Dimensions. Vector Size Required: >= 3");
190 for (uint01 dim = 0; dim < t_dims - 2; ++dim)
191 m_values[dim / 8](dim % 8, vector[dim]);
192 m_values[(t_dims - 2) / 8]((t_dims - 2) % 8, suffix_a);
193 m_values[(t_dims - 1) / 8]((t_dims - 1) % 8, suffix_b);
194 }
195
201 constexpr Vector(const bool& prefix, const Vector<t_dims - 1, bool>& vector)
202 {
203 static_assert(t_dims >= 2, "Unexpected Number of Dimensions. Vector Size Required: >= 2");
204 m_values[0](0, prefix);
205 for (uint01 dim = 1; dim < t_dims; ++dim)
206 m_values[dim / 8](dim % 8, vector[dim - 1]);
207 }
208
214 constexpr Vector(const bool& prefix_a, const bool& prefix_b, const Vector<t_dims - 1, bool>& vector)
215 {
216 static_assert(t_dims >= 2, "Unexpected Number of Dimensions. Vector Size Required: of at least 1");
217 m_values[X] = prefix_a;
218 m_values[Y] = prefix_b;
219 for (uint01 dim = Z; dim < t_dims; ++dim)
220 m_values[dim] = vector[dim - 1];
221 }
222
229 template<uint01 t_new_dim, class t_new_type>
230 constexpr Vector<t_new_dim, t_new_type> as(t_new_type extra_fill_value = 0) const
231 {
232 Vector<t_new_dim, t_new_type> vec;
233 uint01 dim = 0;
234 const uint01 min = getMin(t_new_dim, t_dims);
235 for (; dim < min; dim++)
236 vec[dim] = cast<t_new_type>(m_values[dim / 8][dim % 8]);
237 for (; dim < t_new_dim; dim++)
238 vec[dim] = extra_fill_value;
239 return vec;
240 }
241
242
243
249 constexpr operator bool() const
250 {
251 static_assert(t_dims == 1, "Cannot auto-convert from vector to scaler unless dimension of vector is 1.");
252 return m_values[0][0];
253 }
254
255
256
262
263 constexpr BitReference operator[](uint01 dimension_index)
264 {
265 lib_assert(dimension_index < t_dims, "Dimension requested Exceeded maximum vector dimension");
266 return BitReference(m_values[dimension_index / 8], dimension_index % 8);
267 }
268
269
270
271 constexpr bool operator[](const uint01 dimension_index) const
272 {
273 lib_assert(dimension_index < t_dims, "Dimension requested Exceeded maximum vector dimension");
274 return m_values[dimension_index / 8][dimension_index % 8];
275 }
276
277
283
284 constexpr Vector<t_dims, bool>& operator=(const Vector<t_dims, bool>& vector)
285 {
286 for (uint01 dim = 0; dim < ByteCount(); ++dim)
287 m_values[dim] = vector.m_values[dim];
288 return *this;
289 }
290
296 constexpr Vector<t_dims, bool>& operator=(const bool& scaler)
297 {
298
299 for (uint01 dim = 0; dim < ByteCount(); ++dim)
300 m_values[dim] = BitFlag(scaler);
301 return *this;
302 }
303
304 constexpr Vector<t_dims, bool>& operator&=(const Vector<t_dims, bool>& vector)
305 {
306 for (uint01 dim = 0; dim < ByteCount(); ++dim)
307 m_values[dim] &= vector.m_values[dim];
308 return *this;
309 }
310
311 constexpr Vector<t_dims, bool>& operator|=(const Vector<t_dims, bool>& vector)
312 {
313 for (uint01 dim = 0; dim < ByteCount(); ++dim)
314 m_values[dim] |= vector.m_values[dim];
315 return *this;
316 }
317
318 constexpr Vector<t_dims, bool> operator&(const Vector<t_dims, bool>& vector) const
319 {
320 Vector<t_dims, bool> output(0);
321 for (uint01 dim = 0; dim < ByteCount(); ++dim)
322 output[dim] = m_values[dim] & vector.m_values[dim];
323 return output;
324 }
325
326 constexpr Vector<t_dims, bool> operator|(const Vector<t_dims, bool>& vector) const
327 {
328 Vector<t_dims, bool> output(0);
329 for (uint01 dim = 0; dim < ByteCount(); ++dim)
330 output[dim] = m_values[dim] | vector.m_values[dim];
331 return output;
332 }
333
338
339 static constexpr uint01 NumberOfDimensions() { return t_dims; }
340
346 constexpr static bool Type() { return bool(); }
347
348 static constexpr uint04 ByteCount()
349 {
350 return (t_dims / 8) + (t_dims % 8 == 0 ? 0 : 1);
351 }
352 protected:
354 BitFlag m_values[(t_dims / 8) + (t_dims % 8 == 0 ? 0 : 1)];
355 };
356};
357
358
A bitset that stores 8 bits (elements with only two possible values: 0 or 1, true or false,...
Definition BitFlag.hpp:55
A convenience class used with Buffers or Vectors of bools for referencing or acting on a single bit.
constexpr Vector(const Vector< t_dims - 1, bool > &vector, const bool &suffix)
Vectors.
constexpr Vector(const bool &x, const bool &y)
Sets values in each dimension to the respective value in the passed in scaler.
constexpr Vector(const bool(&vector)[t_dims])
Given a container of statically determined array, transforms it to a vector.
constexpr Vector(const bool &prefix, const Vector< t_dims - 1, bool > &vector)
Creates a vector where the prefix scaler is combined with the suffix vector.
static constexpr uint01 NumberOfDimensions()
Number of dimensions in this vector class.
constexpr Vector(const bool &value)
Sets values in each dimension to the value in the passed in scaler.
constexpr Vector(const Vector< getMax(t_dims - 2, 0), bool > &vector, const bool &suffix_a, const bool &suffix_b)
Creates a vector where the prefix vector is combined with the suffix scalers.
constexpr Vector(const bool &x, const bool &y, const bool &z, const bool &w)
Sets values in each dimension to the respective value in the passed in scaler.
constexpr Vector(const Vector< t_dims, t_vec_type > &vector)
Copy constructor.
constexpr Vector(const bool &x, const bool &y, const bool &z)
Sets values in each dimension to the respective value in the passed in scaler.
static constexpr bool Type()
Returns the type of this class.
constexpr Vector< t_dims, bool > & operator=(const Vector< t_dims, bool > &vector)
Assignment operator.
constexpr Vector(const bool &prefix_a, const bool &prefix_b, const Vector< t_dims - 1, bool > &vector)
Vectors.
constexpr BitReference operator[](uint01 dimension_index)
Accesses the value of a certain dimension.
constexpr Vector< t_new_dim, t_new_type > as(t_new_type extra_fill_value=0) const
As the given extra fill value.
BitFlag m_values[(t_dims/8)+(t_dims % 8==0 ? 0 :1)]
The values[t dims].
constexpr Vector< t_dims, bool > & operator=(const bool &scaler)
Assignment operator.
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
t_type m_values[t_dims]
The values[t dims].
Definition Vector.hpp:630
constexpr t_type & operator[](uint01 dimension_index)
Accesses the value of a certain dimension.
Definition Vector.hpp:548
The primary namespace for the NDEVR SDK.
@ BitFlag
Per-vertex bit flags (selected, hidden, etc.).
constexpr t_type getMin(const t_type &left, const t_type &right)
Finds the minimum of the given arguments based on the < operator Author: Tyler Parke Date: 2017-11-05...
constexpr t_type getMax(const t_type &left, const t_type &right)
Finds the max of the given arguments using the > operator The only requirement is that t_type have > ...
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
uint01 operator|(const TextAlignment &a, const TextAlignment &b)
Bitwise OR operator for combining TextAlignment flags.
Definition Font.h:336
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Definition Angle.h:408