API Documentation
Loading...
Searching...
No Matches
VariableReference.h
Go to the documentation of this file.
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/ObjectInfo.h>
36#include <NDEVR/TypeInfo.h>
37#include <NDEVR/Angle.h>
38namespace NDEVR
39{
40 template<class t_type_a, class t_type_b>
41 void assign(t_type_a& a, const t_type_b& b)
42 {
43 a = cast<t_type_a>(b);
44 }
45 template<class t_type_a>
46 void assign(t_type_a& a, const t_type_a& b)
47 {
48 a = b;
49 }
50 template<uint01 t_dim_a, class t_type_a, uint01 t_dim_b, class t_type_b>
52 {
53 a = b.template as<t_dim_a, t_type_a>();
54 }
55 template<class t_type_a, uint01 t_dim_b, class t_type_b>
56 void assign(t_type_a& a, const Vector<t_dim_b, t_type_b>& b)
57 {
58 a = b[0];
59 }
60 template<class t_type_a>
61 void assign(t_type_a& a, const char* b)
62 {
63 a = assign<t_type_a>(b);
64 }
65
66 template<uint01 t_dim_a, class t_type_a, uint01 t_dim_b, class t_type_b>
68 {
69 a[dim] = b[dim];
70 }
71
72 template<class t_type_a, uint01 t_dim_b, class t_type_b>
73 void assign(t_type_a& a, const Vector<t_dim_b, t_type_b>& b, uint01 dim)
74 {
75 a = b[dim];
76 }
77 /**--------------------------------------------------------------------------------------------------
78 \brief An optimized class for storing a reference to a variable of some type up to 8 bytes in size
79 without ownership or allocations on the stack.
80 **/
82 {
83 private:
84 union t_pointer
85 {
86 uint01* _uint01;
87 uint02* _uint02;
88 uint04* _uint04;
89 uint08* _uint08;
90
91 sint01* _sint01;
92 sint02* _sint02;
93 sint04* _sint04;
94 sint08* _sint08;
95
96 fltp04* _fltp04;
97 fltp08* _fltp08;
98
99 Angle<sint04>* _angles8;
100 Angle<fltp08>* _anglef8;
101 char* _char;
102 };
103 public:
104 template<class t_type>
105 constexpr VariableReference(t_type& value)
106 : m_pointer(reinterpret_cast<t_pointer*>(&value))
107 {
109 }
110 template<class t_object_type>
120 : m_pointer(reference.m_pointer)
121 {
122 memcpy(m_bits, reference.m_bits, sizeof(m_bits));
123 }
124
125 template<class t_type>
126 constexpr void set(const t_type& value)
127 {
128 m_flag(m_bits, value);
129 }
130 template<class t_type>
131 constexpr VariableReference& operator=(const t_type& b)
132 {
133 m_flag(m_bits, b);
134 return *this;
135 };
137 {
138 return *this;
139 };
140 template<class t_type>
141 constexpr bool operator==(const t_type& b) const
142 {
143 return get<t_type>() == b;
144 };
145 template<class t_type>
146 constexpr bool operator!=(const t_type& b) const
147 {
148 return get<t_type>() != b;
149 };
150 template<class t_type>
151 constexpr operator t_type() const
152 {
153 return get<t_type>();
154 }
155 template<class t_type>
156 t_type get() const
157 {
158 t_type value;
159 get<t_type>(value, 0, 0);
160 return value;
161 }
162 template<class t_type>
163 void get(t_type& value, uint04 level, uint04 index) const
164 {
165 lib_assert(m_bits->vector_size != 0, "Not yet ready");
166 getSingle(value, level, index);
167 }
168
169
170 template<class t_type>
171 void getSingle(t_type& value, uint04 level, uint04 index) const
172 {
173 if (m_bits[level].is_number)
174 {
175 if (m_bits[level].is_unsigned)
176 {
177 switch (m_bits[level].byte_size)
178 {
179 case 1: assign(value, *(m_pointer->_uint01 + index)); break;
180 case 2: assign(value, *(m_pointer->_uint02 + index)); break;
181 case 4: assign(value, *(m_pointer->_uint04 + index)); break;
182 case 8: assign(value, *(m_pointer->_uint08 + index)); break;
183 }
184 }
185 else
186 {
187 if (m_bits[level].is_float)
188 {
189 switch (m_bits[level].byte_size)
190 {
191 case 4: assign(value, *(m_pointer->_fltp04 + index)); break;
192 case 8: assign(value, *(m_pointer->_fltp08 + index)); break;
193 }
194 }
195 else
196 {
197 switch (m_bits[level].byte_size)
198 {
199 case 1: assign(value, *(m_pointer->_sint01 + index)); break;
200 case 2: assign(value, *(m_pointer->_sint02 + index)); break;
201 case 4: assign(value, *(m_pointer->_sint04 + index)); break;
202 case 8: assign(value, *(m_pointer->_sint08 + index)); break;
203 }
204 }
205 }
206 }
207 else if (m_bits[level].is_string)
208 {
209 assign(value, (m_pointer->_char + index));
210 }
211 }
212
213 private:
214 TypeInfo m_bits[8];
215 t_pointer* const m_pointer;
216 };
217};
#define lib_assert(expression, message)
Definition LibAssert.h:61
The primary angle storage class for this API. Stores an angle in an optimized format.
Definition StringStream.h:540
Stores information about a type, relevant for certain templated functions. To get information about a...
Definition TypeInfo.h:43
uint02 vector_size
Definition TypeInfo.h:59
An optimized class for storing a reference to a variable of some type up to 8 bytes in size without o...
Definition VariableReference.h:82
t_type get() const
Definition VariableReference.h:156
constexpr VariableReference & operator=(const t_type &b)
Definition VariableReference.h:131
constexpr bool operator==(const t_type &b) const
Definition VariableReference.h:141
void fillInfoTable(const ObjectInfo< t_object_type > &, uint01 level)
Definition VariableReference.h:111
constexpr VariableReference(t_type &value)
Definition VariableReference.h:105
constexpr bool operator!=(const t_type &b) const
Definition VariableReference.h:146
constexpr VariableReference & operator=(const VariableReference &)
Definition VariableReference.h:136
constexpr void set(const t_type &value)
Definition VariableReference.h:126
void get(t_type &value, uint04 level, uint04 index) const
Definition VariableReference.h:163
void getSingle(t_type &value, uint04 level, uint04 index) const
Definition VariableReference.h:171
VariableReference(const VariableReference &reference)
Definition VariableReference.h:119
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
Definition ACIColor.h:37
int32_t sint04
-Defines an alias representing a 4 byte, signed integer. -Can represent exact integer values -2147483...
Definition BaseValues.hpp:64
void assign(t_type_a &a, const t_type_b &b)
Definition VariableReference.h:41
constexpr std::enable_if<!ObjectInfo< t_type >::Buffer, TypeInfo >::type GetTypeInfo()
Definition TypeInfo.h:103
int64_t sint08
-Defines an alias representing an 8 byte, signed integer -Can represent exact integer values -9223372...
Definition BaseValues.hpp:71
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
Definition BaseValues.hpp:127
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
int8_t sint01
-Defines an alias representing a 1 byte, signed integer. -Can represent exact integer values -127 thr...
Definition BaseValues.hpp:50
int16_t sint02
-Defines an alias representing a 2 byte, signed integer. -Can represent exact integer values -32767 t...
Definition BaseValues.hpp:57
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
Definition BaseValues.hpp:106
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:375
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:88
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
Information about the object.
Definition ObjectInfo.h:54