NDEVR
API Documentation
VariableReference.h
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: VariableReference
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/BaseValues.h>
34#include <NDEVR/Vector.h>
35#include <NDEVR/BufferBase.h>
36#include <NDEVR/TypeInfo.h>
37#include <NDEVR/Angle.h>
38namespace NDEVR
39{
45 template<class t_type_a, class t_type_b>
46 void assign(t_type_a& a, const t_type_b& b)
47 {
48 a = cast<t_type_a>(b);
49 }
50
55 template<class t_type_a>
56 void assign(t_type_a& a, const t_type_a& b)
57 {
58 a = b;
59 }
60
65 template<uint01 t_dim_a, class t_type_a, uint01 t_dim_b, class t_type_b>
67 {
68 a = b.template as<t_dim_a, t_type_a>();
69 }
70
75 template<class t_type_a, uint01 t_dim_b, class t_type_b>
76 void assign(t_type_a& a, const Vector<t_dim_b, t_type_b>& b)
77 {
78 a = b[0];
79 }
80
85 template<class t_type_a>
86 void assign(t_type_a& a, const char* b)
87 {
88 a = assign<t_type_a>(b);
89 }
90
97 template<uint01 t_dim_a, class t_type_a, uint01 t_dim_b, class t_type_b>
99 {
100 a[dim] = b[dim];
101 }
102
109 template<class t_type_a, uint01 t_dim_b, class t_type_b>
110 void assign(t_type_a& a, const Vector<t_dim_b, t_type_b>& b, uint01 dim)
111 {
112 a = b[dim];
113 }
114
119 {
120 private:
124 union t_pointer
125 {
126 uint01* _uint01;
127 uint02* _uint02;
128 uint04* _uint04;
129 uint08* _uint08;
130
131 sint01* _sint01;
132 sint02* _sint02;
133 sint04* _sint04;
134 sint08* _sint08;
135
136 fltp04* _fltp04;
137 fltp08* _fltp08;
138
139 Angle<sint04>* _angles8;
140 Angle<fltp08>* _anglef8;
141 char* _char;
142 };
143 public:
149 template<class t_type>
150 constexpr VariableReference(t_type& value)
151 : m_pointer(reinterpret_cast<t_pointer*>(&value))
152 {
154 }
155
160 template<class t_object_type>
169
175 : m_pointer(reference.m_pointer)
176 {
177 memcpy(m_bits, reference.m_bits, sizeof(m_bits));
178 }
179
184 template<class t_type>
185 constexpr void set(const t_type& value)
186 {
187 m_flag(m_bits, value);
188 }
189
194 template<class t_type>
195 constexpr VariableReference& operator=(const t_type& b)
196 {
197 m_flag(m_bits, b);
198 return *this;
199 };
200
205 {
206 return *this;
207 };
208
213 template<class t_type>
214 constexpr bool operator==(const t_type& b) const
215 {
216 return get<t_type>() == b;
217 };
218
223 template<class t_type>
224 constexpr bool operator!=(const t_type& b) const
225 {
226 return get<t_type>() != b;
227 };
228
232 template<class t_type>
233 constexpr operator t_type() const
234 {
235 return get<t_type>();
236 }
237
241 template<class t_type>
242 t_type get() const
243 {
244 t_type value;
245 get<t_type>(value, 0, 0);
246 return value;
247 }
248
254 template<class t_type>
255 void get(t_type& value, uint04 level, uint04 index) const
256 {
257 lib_assert(m_bits->vector_size != 0, "Not yet ready");
258 getSingle(value, level, index);
259 }
260
261
269 template<class t_type>
270 void getSingle(t_type& value, uint04 level, uint04 index) const
271 {
272 if (m_bits[level].is_number)
273 {
274 if (m_bits[level].is_unsigned)
275 {
276 switch (m_bits[level].byte_size)
277 {
278 case 1: assign(value, *(m_pointer->_uint01 + index)); break;
279 case 2: assign(value, *(m_pointer->_uint02 + index)); break;
280 case 4: assign(value, *(m_pointer->_uint04 + index)); break;
281 case 8: assign(value, *(m_pointer->_uint08 + index)); break;
282 }
283 }
284 else
285 {
286 if (m_bits[level].is_float)
287 {
288 switch (m_bits[level].byte_size)
289 {
290 case 4: assign(value, *(m_pointer->_fltp04 + index)); break;
291 case 8: assign(value, *(m_pointer->_fltp08 + index)); break;
292 }
293 }
294 else
295 {
296 switch (m_bits[level].byte_size)
297 {
298 case 1: assign(value, *(m_pointer->_sint01 + index)); break;
299 case 2: assign(value, *(m_pointer->_sint02 + index)); break;
300 case 4: assign(value, *(m_pointer->_sint04 + index)); break;
301 case 8: assign(value, *(m_pointer->_sint08 + index)); break;
302 }
303 }
304 }
305 }
306 else if (m_bits[level].is_string)
307 {
308 assign(value, (m_pointer->_char + index));
309 }
310 }
311
312 private:
313 TypeInfo m_bits[8];
314 t_pointer* const m_pointer;
315 };
316};
Stores an angle in an optimized internal format with support for efficient trigonometric operations.
Definition Angle.h:83
Stores information about a type, relevant for certain templated functions.
Definition TypeInfo.h:43
constexpr VariableReference & operator=(const VariableReference &)
Copy assignment operator.
t_type get() const
Retrieves the referenced value converted to the requested type.
void fillInfoTable(const ObjectInfo< t_object_type > &, uint01 level)
Recursively populates the type info table for the referenced variable, descending into Vector sub-typ...
constexpr bool operator!=(const t_type &b) const
Inequality operator.
void get(t_type &value, uint04 level, uint04 index) const
Retrieves the referenced value into an output variable, using the type hierarchy level and element in...
constexpr VariableReference(t_type &value)
Constructs a VariableReference from a typed variable, storing a pointer to the variable and populatin...
constexpr bool operator==(const t_type &b) const
Equality operator.
constexpr void set(const t_type &value)
Sets the referenced variable to the given value.
void getSingle(t_type &value, uint04 level, uint04 index) const
Reads a single scalar value from the referenced memory by interpreting the raw pointer according to t...
VariableReference(const VariableReference &reference)
Copy constructor.
constexpr VariableReference & operator=(const t_type &b)
Assignment operator.
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
The primary namespace for the NDEVR SDK.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
constexpr std::enable_if<!ObjectInfo< t_type >::Buffer, TypeInfo >::type GetTypeInfo()
Constructs a TypeInfo for a non-buffer type at compile time using ObjectInfo traits.
Definition TypeInfo.h:125
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
int16_t sint02
-Defines an alias representing a 2 byte, signed integer.
int32_t sint04
-Defines an alias representing a 4 byte, signed integer.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
void assign(t_type_a &a, const t_type_b &b)
Assigns a value of one type to a variable of another type using a cast.
int8_t sint01
-Defines an alias representing a 1 byte, signed integer.
int64_t sint08
-Defines an alias representing an 8 byte, signed integer -Can represent exact integer values -9223372...
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Definition Angle.h:408
Information about the object.
Definition ObjectInfo.h:55