API Documentation
Loading...
Searching...
No Matches
BaseValues.hpp
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: BaseValues
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/LibAssert.h>
35#include <limits>
36#include <cinttypes>
37namespace NDEVR
38{
39 /**--------------------------------------------------------------------------------------------------
40 \brief Dummy class to ensure creation of an include file around core root values
41
42 **/
44 {};
45 /**--------------------------------------------------------------------------------------------------
46 \brief -Defines an alias representing a 1 byte, signed integer.
47 -Can represent exact integer values -127 through 127.
48 -Byte value 0XFF (integer value: -128) is considered invalid and reserved.
49 **/
50 typedef int8_t sint01;
51
52 /**--------------------------------------------------------------------------------------------------
53 \brief -Defines an alias representing a 2 byte, signed integer.
54 -Can represent exact integer values -32767 through 32767.
55 -Byte value 0XFFFF (integer value: -32768) is considered invalid and reserved.
56 **/
57 typedef int16_t sint02;
58
59 /**--------------------------------------------------------------------------------------------------
60 \brief -Defines an alias representing a 4 byte, signed integer.
61 -Can represent exact integer values -2147483647 through 2147483647.
62 -Byte value 0XFFFFFFFF (integer value: -2147483648) is considered invalid and reserved.
63 **/
64 typedef int32_t sint04;
65
66 /**--------------------------------------------------------------------------------------------------
67 \brief -Defines an alias representing an 8 byte, signed integer
68 -Can represent exact integer values -9223372036854775807 through 9223372036854775807.
69 -Byte value 0XFFFFFFFFFFFFFFFF (integer value: -9223372036854775808) is considered invalid and reserved.
70 **/
71 typedef int64_t sint08;
72
73 /**--------------------------------------------------------------------------------------------------
74 \brief -Defines an alias representing a 1 byte, unsigned integer
75 -Can represent exact integer values 0 through 254.
76 -Byte value 0XFF (integer value: 255) is considered invalid and should normally be reserved. Note that
77 it can be used with caution.
78 -Note that subtracting 1 from 0 will result in 0xFF, the reserved invalid value.
79 **/
80 typedef uint8_t uint01;
81
82 /**--------------------------------------------------------------------------------------------------
83 \brief -Defines an alias representing a 2 byte, unsigned integer
84 -Can represent exact integer values 0 through 65534.
85 -Byte value 0xFFFF (integer value: 65535) is considered invalid and reserved.
86 -Note that subtracting 1 from 0 will result in 0xFFFF, the reserved invalid value.
87 **/
88 typedef uint16_t uint02;
89
90 /**--------------------------------------------------------------------------------------------------
91 \brief -Defines an alias representing a 4 byte, unsigned integer
92 -Can represent exact integer values 0 through 4294967294.
93 -Byte value 0xFFFFFFFF (integer value: 4294967295) is considered invalid and reserved.
94 -Note that subtracting 1 from 0 will result in 0xFFFFFFFF, the reserved invalid value.
95 **/
96 typedef uint32_t uint04;
97
98 /**--------------------------------------------------------------------------------------------------
99 \brief -Defines an alias representing an 8 byte, unsigned integer
100
101 -Can represent exact integer values 0 through 18446744073709551614.
102 -Byte value 0XFFFFFFFFFFFFFFFF (integer value: 18446744073709551615) is considered invalid and
103 reserved.
104 -Note that subtracting 1 from 0 will result in 0XFFFFFFFFFFFFFFFF, the reserved invalid value.
105 **/
106 typedef uint64_t uint08;
107
108 /**--------------------------------------------------------------------------------------------------
109 \brief Defines an alias representing a 4 byte floating-point number
110 Bit layout is as follows:
111 -Sign: 1 bit at position 31 determines whether or not the value is positive or negative.
112 0 denotes a positive number, and 1 denotes a negative number
113 -Exponent: 8 bits stored in position 30–23 The exponent field needs to represent both positive
114 and negative exponents. To do this, a bias is added to the actual exponent in order to get
115 the stored exponent. This value is 127.
116 Thus, an exponent of zero means that 127 is stored in the exponent field.
117 A stored value of 200 indicates an exponent of (200–127), or 73. For reasons
118 exponents of −127 (all 0s) and +128 (all 1s) are reserved for special numbers.
119 -Fraction: 23 bits stored in positions 22–00. The mantissa, also known as the significand,
120 represents the precision bits of the number. It is composed of an implicit leading bit
121 (left of the radix point) and the fraction bits (to the right of the radix point).
122 Note that positive and negative infinity are reserved as max and min. However precision changes
123 for large and small numbers. Precision is greatest around 0.
124 \warning Note that Invalid is reserved as invalid values. Using == will not work for these values.
125
126 **/
127 typedef float fltp04;
128
129 /**--------------------------------------------------------------------------------------------------
130 \brief Defines an alias representing an 8 byte floating-point number.
131
132 Bit layout is as follows:
133 -Sign: 1 bit at position 63 determines whether or not the value is positive or negative.
134 0 denotes a positive number, and 1 denotes a negative number
135 -Exponent: 11 bits stored in position 62–52. The exponent field needs to represent both positive
136 and negative exponents. To do this, a bias is added to the actual exponent in order to get
137 the stored exponent. This value is 1023.
138 Thus, an exponent of zero means that 1023 is stored in the exponent field.
139 A stored value of 200 indicates an exponent of (200–1023), or -823. For reasons
140 exponents of all 0s and all 1s are reserved for special numbers.
141 -Fraction: 52 bits stored in positions 51–00. The mantissa, also known as the significand,
142 represents the precision bits of the number. It is composed of an implicit leading bit
143 (left of the radix point) and the fraction bits (to the right of the radix point).
144 Note that positive and negative infinity are reserved as max and min. However precision changes
145 for large and small numbers. Precision is greatest around 0.
146 \warning Note that Invalid is reserved as invalid values. Using == will not work for these values.
147
148 **/
149 typedef double fltp08;
150
151 /**--------------------------------------------------------------------------------------------------
152 \brief Allias for wchar_t, a value that represents a character of two bytes in size.
153
154 **/
155 typedef wchar_t wchar;
156
157 /**--------------------------------------------------------------------------------------------------
158 \brief Values that represent dimension values.
159
160 Note these are used throughout the code to make things more readable. For example, for a vertex
161 we can access it via vertex[Z] instead of vertex[2] which overall contributes to total readability.
162 Typically for shapes (Triangles, LineSegments, etc) we access the nodes via A, B, C. triangle.vertex(A)
163 for example. For points we typically use X, Y, Z triangle.vertex(A)[X] = triangle.vertex(B)[X]
164 **/
166 {
167 X = 0
168 , A = 0
169 , Y = 1
170 , B = 1
171 , Z = 2
172 , C = 2
173 , W = 3
174 , D = 3
175 };
176 /**--------------------------------------------------------------------------------------------------
177 \brief Values that represent dimension values for geodic dimensions.
178 Represents latitude, longitude, and altitude.
179 **/
181 {
182 LAT = 0,
183 LON = 1,
184 ALT = 2
185 };
186 /**--------------------------------------------------------------------------------------------------
187
188 \brief Values that represent location values.
189
190 Note these are used throughout the code to make things more readable as above. For example, for example
191 in point pairs with a max and a min, or in a bounds object.
192 **/
193
195 {
196 MIN = 0
197 , MAX = 1
198 };
199
200 /**--------------------------------------------------------------------------------------------------
201 \brief Used for classifying shape intersections.
202
203 Values include:
204 - Outside means completely outside the other shape, not touching the boundary.
205 - Inside means entirely inside (but may touch the boundary) of the shape.
206 - Mixed means the shape is neither completely inside or outside the shape.
207 These values are used heavily in the intersection class.
208 **/
210 {
211 outside = 0//Outside means completely outside the other shape, not touching the boundary.
212 , inside//Entirely inside (but may touch the boundary) of the shape.
213 , mixed//The shape is neither completely inside or outside the shape.
214 };
215
216 /**--------------------------------------------------------------------------------------------------
217 \brief Values that represent interpolation functions. Useful in large or complicated geological or time
218 based data sets.
219 **/
226
227 /**--------------------------------------------------------------------------------------------------
228 \brief Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved
229 'invalid' value.
230 **/
231 template<class t_type>
232 struct Constant
233 {
234 static const t_type Invalid; //The reserved Invalid value of the object, typically 0xFF...
235 static const t_type Min; //The minimum value the object type can take on.
236 static const t_type Max; //The maximum value the object type can take on.
237 };
238
239 template<> constexpr const bool Constant<bool>::Invalid = false;
240 template<> constexpr const bool Constant<bool>::Max = true;
241 template<> constexpr const bool Constant<bool>::Min = false;
242
243 template<> constexpr const sint01 Constant<sint01>::Invalid = -128;
244 template<> constexpr const sint01 Constant<sint01>::Max = 127;
245 template<> constexpr const sint01 Constant<sint01>::Min = -127;
246
247 template<> constexpr const uint01 Constant<uint01>::Invalid = 255;
248 template<> constexpr const uint01 Constant<uint01>::Max = 254;
249 template<> constexpr const uint01 Constant<uint01>::Min = 0;
250
251 template<> constexpr const sint02 Constant<sint02>::Invalid = -32768;
252 template<> constexpr const sint02 Constant<sint02>::Max = 32767;
253 template<> constexpr const sint02 Constant<sint02>::Min = -32767;
254
255 template<> constexpr const uint02 Constant<uint02>::Invalid = 65535;
256 template<> constexpr const uint02 Constant<uint02>::Max = 65534;
257 template<> constexpr const uint02 Constant<uint02>::Min = 0;
258
259 template<> constexpr const sint04 Constant<sint04>::Invalid = 0x80000000;
260 template<> constexpr const sint04 Constant<sint04>::Max = 2147483647;
261 template<> constexpr const sint04 Constant<sint04>::Min = -2147483647;
262
263 template<> constexpr const uint04 Constant<uint04>::Invalid = 4294967295UL;
264 template<> constexpr const uint04 Constant<uint04>::Max = 4294967294UL;
265 template<> constexpr const uint04 Constant<uint04>::Min = 0;
266
267 template<> constexpr const sint08 Constant<sint08>::Invalid = 0x8000000000000000;
268 template<> constexpr const sint08 Constant<sint08>::Max = 9223372036854775807LL;
269 template<> constexpr const sint08 Constant<sint08>::Min = -9223372036854775807LL;
270
271 template<> constexpr const uint08 Constant<uint08>::Invalid = 18446744073709551615ULL;
272 template<> constexpr const uint08 Constant<uint08>::Max = 18446744073709551614ULL;
273 template<> constexpr const uint08 Constant<uint08>::Min = 0;
274
275 template<> constexpr const fltp04 Constant<fltp04>::Invalid = std::numeric_limits<fltp04>::quiet_NaN();
276 template<> constexpr const fltp04 Constant<fltp04>::Max = std::numeric_limits<fltp04>::infinity();
277 template<> constexpr const fltp04 Constant<fltp04>::Min = -std::numeric_limits<fltp04>::infinity();
278
279 template<> constexpr const fltp08 Constant<fltp08>::Invalid = std::numeric_limits<fltp08>::quiet_NaN();
280 template<> constexpr const fltp08 Constant<fltp08>::Max = std::numeric_limits<fltp08>::infinity();
281 template<> constexpr const fltp08 Constant<fltp08>::Min = -std::numeric_limits<fltp08>::infinity();
282
283 /**
284 \brief Casts the given value. Is equivalent to static_cast except allows for the option of special cases by
285 specializing the template
286
287 static_cast is used for cases where you want to reverse an implicit conversion, with a few restrictions
288 and additions.
289
290 cast performs no runtime checks.
291
292 This should be used if you know that you refer to an object of a specific type,
293 and thus a check would be unnecessary.
294
295 \param[in] value - The value to cast.
296 \return The value cast to the specified type.
297 **/
298 template<class t_to, class t_from>
299 constexpr t_to cast(t_from value)
300 {
301 return static_cast<t_to>(value);
302 }
303
304 /**
305 \brief Casts the given value. Is equivalent to static_cast except allows for the option of special cases by
306 specializing the template
307
308 static_cast is used for cases where you want to reverse an implicit conversion, with a few restrictions
309 and additions.
310
311 In debug mode, cast performs runtime check to ensure value is positve prior to casting
312
313 This should be used if you know that you refer to an object of a specific type,
314 and thus a check would be unnecessary.
315
316 \param[in] value - The value to cast.
317 \return The value cast to the usigned.
318 **/
319 template<>
320 constexpr uint04 cast(fltp04 value)
321 {
322 lib_assert(value >= 0, "Bad value");
323 return static_cast<uint04>(value);
324 }
325 /**
326 \brief Casts the given value. Is equivalent to static_cast except allows for the option of special cases by
327 specializing the template
328
329 static_cast is used for cases where you want to reverse an implicit conversion, with a few restrictions
330 and additions.
331
332 In debug mode, cast performs runtime check to ensure value is positve prior to casting
333
334 This should be used if you know that you refer to an object of a specific type,
335 and thus a check would be unnecessary.
336
337 \param[in] value - The value to cast.
338 \return The value cast to the usigned.
339 **/
340 template<>
341 constexpr uint04 cast(fltp08 value)
342 {
343 lib_assert(value >= 0, "Bad value");
344 return static_cast<uint04>(value);
345 }
346 /**
347 \brief Casts the given value. Is equivalent to static_cast except allows for the option of special cases by
348 specializing the template
349
350 static_cast is used for cases where you want to reverse an implicit conversion, with a few restrictions
351 and additions.
352
353 In debug mode, cast performs runtime check to ensure value is positve prior to casting
354
355 This should be used if you know that you refer to an object of a specific type,
356 and thus a check would be unnecessary.
357
358 \param[in] value - The value to cast.
359 \return The value cast to the usigned.
360 **/
361 template<>
362 constexpr uint04 cast(sint04 value)
363 {
364 lib_assert(value >= 0, "Bad value");
365 return static_cast<uint04>(value);
366 }
367 /**
368 \brief Casts the given value. Is equivalent to static_cast except allows for the option of special cases by
369 specializing the template
370
371 static_cast is used for cases where you want to reverse an implicit conversion, with a few restrictions
372 and additions.
373
374 In debug mode, cast performs runtime check to ensure value is positve prior to casting
375
376 This should be used if you know that you refer to an object of a specific type,
377 and thus a check would be unnecessary.
378
379 \param[in] value - The value to cast.
380 \return The value cast to the usigned.
381 **/
382 template<>
383 constexpr uint04 cast(sint08 value)
384 {
385 lib_assert(value >= 0, "Bad value");
386 return static_cast<uint04>(value);
387 }
388 /**
389 \brief Casts the given value. Is equivalent to reinterpret_cast except allows for the option of special cases by
390 specializing the template
391
392 Allows any pointer to be converted into any other pointer type. Also allows any integral type to be
393 converted into any pointer type and vice versa.
394
395 Author: Tyler Parke
396
397 Date: 2017-09-04
398
399 \param[in] value - The value to cast.
400 \return The value cast to the specified type.
401 **/
402 template<class t_to, class t_from>
403 constexpr t_to rcast(t_from value)
404 {
405 static_assert(sizeof(t_to) <= sizeof(t_from), "Bad rcast conversion");
406 return *((t_to*)(&value));
407 }
408
409 #define UNUSED(expr) do { (void)(expr); } while (0)
410
411
412 static_assert(sizeof(bool) == 1, "Bad bool size");
413 static_assert(sizeof(char) == 1, "Bad char size");
414 //static_assert(sizeof(wchar) == 4, "Bad bool size");
415 static_assert(sizeof(float) == 4, "Bad float size");
416 static_assert(sizeof(double) == 8, "Bad double size");
417
418 static_assert(sizeof(fltp04) == 4, "Bad fltp04 size");
419 static_assert(sizeof(fltp08) == 8, "Bad fltp08 size");
420
421 static_assert(sizeof(uint01) == 1, "Bad int size");
422 static_assert(sizeof(uint02) == 2, "Bad int size");
423 static_assert(sizeof(uint04) == 4, "Bad int size");
424 static_assert(sizeof(uint08) == 8, "Bad int size");
425
426 static_assert(sizeof(sint01) == 1, "Bad int size");
427 static_assert(sizeof(sint02) == 2, "Bad int size");
428 static_assert(sizeof(sint04) == 4, "Bad int size");
429 static_assert(sizeof(sint08) == 8, "Bad int size");
430};
431
432#include "BaseFunctions.hpp"
#define lib_assert(expression, message)
Definition LibAssert.h:61
Dummy class to ensure creation of an include file around core root values.
Definition BaseValues.hpp:44
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
GeodeticValues
Values that represent dimension values for geodic dimensions. Represents latitude,...
Definition BaseValues.hpp:181
@ LAT
Definition BaseValues.hpp:182
@ LON
Definition BaseValues.hpp:183
@ ALT
Definition BaseValues.hpp:184
int64_t sint08
-Defines an alias representing an 8 byte, signed integer -Can represent exact integer values -9223372...
Definition BaseValues.hpp:71
LocationValues
Values that represent location values.
Definition BaseValues.hpp:195
@ MIN
Definition BaseValues.hpp:196
@ MAX
Definition BaseValues.hpp:197
wchar_t wchar
Allias for wchar_t, a value that represents a character of two bytes in size.
Definition BaseValues.hpp:155
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
InterpolationValues
Values that represent interpolation functions. Useful in large or complicated geological or time base...
Definition BaseValues.hpp:221
@ nearest_neighbor
Definition BaseValues.hpp:222
@ bicubic
Definition BaseValues.hpp:224
@ e_linear
Definition BaseValues.hpp:223
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
constexpr t_to rcast(t_from value)
Casts the given value. Is equivalent to reinterpret_cast except allows for the option of special case...
Definition BaseValues.hpp:403
IntersectionTypes
Used for classifying shape intersections.
Definition BaseValues.hpp:210
@ inside
Definition BaseValues.hpp:212
@ mixed
Definition BaseValues.hpp:213
@ outside
Definition BaseValues.hpp:211
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
DimensionValues
Values that represent dimension values.
Definition BaseValues.hpp:166
@ B
Definition BaseValues.hpp:170
@ A
Definition BaseValues.hpp:168
@ Y
Definition BaseValues.hpp:169
@ X
Definition BaseValues.hpp:167
@ C
Definition BaseValues.hpp:172
@ D
Definition BaseValues.hpp:174
@ Z
Definition BaseValues.hpp:171
@ W
Definition BaseValues.hpp:173
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233
static const t_type Invalid
Definition BaseValues.hpp:234
static const t_type Min
Definition BaseValues.hpp:235
static const t_type Max
Definition BaseValues.hpp:236