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
99 {
100 public:
101 template<class t_type>
102 constexpr VariableReference(t_type& value)
103 : m_pointer(reinterpret_cast<t_pointer*>(&value))
104 {
106 }
107 template<class t_object_type>
117 : m_pointer(reference.m_pointer)
118 {
119 memcpy(m_bits, reference.m_bits, sizeof(m_bits));
120 }
121
122 template<class t_type>
123 constexpr void set(const t_type& value)
124 {
125 m_flag(m_bits, value);
126 }
127 template<class t_type>
128 constexpr VariableReference& operator=(const t_type& b)
129 {
130 m_flag(m_bits, b);
131 return *this;
132 };
134 {
135 return *this;
136 };
137 template<class t_type>
138 constexpr bool operator==(const t_type& b) const
139 {
140 return get<t_type>() == b;
141 };
142 template<class t_type>
143 constexpr bool operator!=(const t_type& b) const
144 {
145 return get<t_type>() != b;
146 };
147 template<class t_type>
148 constexpr operator t_type() const
149 {
150 return get<t_type>();
151 }
152 template<class t_type>
153 t_type get() const
154 {
155 t_type value;
156 get<t_type>(value, 0, 0);
157 return value;
158 }
159 template<class t_type>
160 void get(t_type& value, uint04 level, uint04 index) const
161 {
162 lib_assert(m_bits->vector_size != 0, "Not yet ready");
163 getSingle(value, level, index);
164 }
165
166
167 template<class t_type>
168 void getSingle(t_type& value, uint04 level, uint04 index) const
169 {
170 if (m_bits[level].is_number)
171 {
172 if (m_bits[level].is_unsigned)
173 {
174 switch (m_bits[level].byte_size)
175 {
176 case 1: assign(value, *(m_pointer->_uint01 + index)); break;
177 case 2: assign(value, *(m_pointer->_uint02 + index)); break;
178 case 4: assign(value, *(m_pointer->_uint04 + index)); break;
179 case 8: assign(value, *(m_pointer->_uint08 + index)); break;
180 }
181 }
182 else
183 {
184 if (m_bits[level].is_float)
185 {
186 switch (m_bits[level].byte_size)
187 {
188 case 4: assign(value, *(m_pointer->_fltp04 + index)); break;
189 case 8: assign(value, *(m_pointer->_fltp08 + index)); break;
190 }
191 }
192 else
193 {
194 switch (m_bits[level].byte_size)
195 {
196 case 1: assign(value, *(m_pointer->_sint01 + index)); break;
197 case 2: assign(value, *(m_pointer->_sint02 + index)); break;
198 case 4: assign(value, *(m_pointer->_sint04 + index)); break;
199 case 8: assign(value, *(m_pointer->_sint08 + index)); break;
200 }
201 }
202 }
203 }
204 else if (m_bits[level].is_string)
205 {
206 assign(value, (m_pointer->_char + index));
207 }
208 }
209
210 private:
211 TypeInfo m_bits[8];
212 t_pointer* const m_pointer;
213 };
214};
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
Stores an angle in an optimized format.
Definition StringStream.h:352
Definition TypeInfo.h:39
uint02 vector_size
Definition TypeInfo.h:55
Definition VariableReference.h:99
t_type get() const
Definition VariableReference.h:153
constexpr VariableReference & operator=(const t_type &b)
Definition VariableReference.h:128
constexpr bool operator==(const t_type &b) const
Definition VariableReference.h:138
void fillInfoTable(const ObjectInfo< t_object_type > &, uint01 level)
Definition VariableReference.h:108
constexpr VariableReference(t_type &value)
Definition VariableReference.h:102
constexpr bool operator!=(const t_type &b) const
Definition VariableReference.h:143
constexpr VariableReference & operator=(const VariableReference &)
Definition VariableReference.h:133
constexpr void set(const t_type &value)
Definition VariableReference.h:123
void get(t_type &value, uint04 level, uint04 index) const
Definition VariableReference.h:160
void getSingle(t_type &value, uint04 level, uint04 index) const
Definition VariableReference.h:168
VariableReference(const VariableReference &reference)
Definition VariableReference.h:116
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
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:76
constexpr std::enable_if<!ObjectInfo< t_type >::Buffer, TypeInfo >::type GetTypeInfo()
Definition TypeInfo.h:99
int64_t sint08
-Defines an alias representing an 8 byte, signed integer -Can represent exact integer values -9223372...
Definition BaseValues.hpp:86
float fltp04
Defines an alias representing a 4 byte floating-point number.
Definition BaseValues.hpp:157
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
int8_t sint01
-Defines an alias representing a 1 byte, signed integer. -Can represent exact integer values -127 thr...
Definition BaseValues.hpp:56
int16_t sint02
-Defines an alias representing a 2 byte, signed integer. -Can represent exact integer values -32767 t...
Definition BaseValues.hpp:66
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer -Can represent exact integer values 0 thro...
Definition BaseValues.hpp:132
void assign(String &a, const t_type_b &b)
Definition String.h:480
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:109
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181
Information about the object.
Definition ObjectInfo.h:56
Definition VariableReference.h:80
sint04 * _sint04
Definition VariableReference.h:88
uint04 * _uint04
Definition VariableReference.h:83
uint02 * _uint02
Definition VariableReference.h:82
sint01 * _sint01
Definition VariableReference.h:86
fltp08 * _fltp08
Definition VariableReference.h:92
Angle< sint04 > * _angles8
Definition VariableReference.h:94
Angle< fltp08 > * _anglef8
Definition VariableReference.h:95
uint01 * _uint01
Definition VariableReference.h:81
uint08 * _uint08
Definition VariableReference.h:84
sint08 * _sint08
Definition VariableReference.h:89
char * _char
Definition VariableReference.h:96
fltp04 * _fltp04
Definition VariableReference.h:91
sint02 * _sint02
Definition VariableReference.h:87