NDEVR
API Documentation
TypeInfo.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: TypeInfo
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <type_traits>
34#include <NDEVR/BaseValues.h>
35#include <NDEVR/BufferBase.h>
36namespace NDEVR
37{
43 {
44 public:
48 constexpr TypeInfo()
49 : total_size(0)
50 , byte_size(0)
51 , vector_size(0)
52 , is_number(false)
53 , is_unsigned(false)
54 , is_float(false)
55 , is_string(false)
56 , is_buffer(false)
57 , is_color(false)
58 , is_boolean(false)
59 {}
63
64 bool is_number;
66 bool is_float;
67 bool is_string;
68 bool is_buffer;
69 bool is_color;
71
77 template<class t_type>
78 bool isSame(const t_type& object)
79 {
80 return TypeInfo(object) == *this;
81 }
82
87 bool operator==(const TypeInfo& type) const
88 {
89 return total_size == type.total_size
90 && byte_size == type.byte_size
91 && vector_size == type.vector_size
92 && is_number == type.is_number
93 && is_unsigned == type.is_unsigned
94 && is_float == type.is_float
95 && is_string == type.is_string
96 && is_buffer == type.is_buffer
97 && is_color == type.is_color
98 && is_boolean == type.is_boolean;
99 }
100
105 bool operator!=(const TypeInfo& type) const
106 {
107 return total_size != type.total_size
108 || byte_size != type.byte_size
109 || vector_size != type.vector_size
110 || is_number != type.is_number
111 || is_unsigned != type.is_unsigned
112 || is_float != type.is_float
113 || is_string != type.is_string
114 || is_buffer != type.is_buffer
115 || is_color != type.is_color
116 || is_boolean != type.is_boolean;
117 }
118 };
119 static_assert(sizeof(TypeInfo) == 16, "Bad TypeInfo Size");//used in raw ndv file
124 template<class t_type, bool is_buffer = ObjectInfo<t_type>::Buffer>
125 constexpr typename std::enable_if<!ObjectInfo<t_type>::Buffer, TypeInfo>::type GetTypeInfo()
126 {
127 TypeInfo col_type;
128 col_type.byte_size = cast<uint02>(sizeof(t_type) / (ObjectInfo<t_type>::Dimensions + (ObjectInfo<t_type>::Dimensions == 0 ? 1 : 0)));
130 col_type.total_size = cast<uint04>(sizeof(t_type));
131
139 return col_type;
140 }
141
145 template<class t_type>
146 constexpr typename std::enable_if<ObjectInfo<t_type>::Buffer, TypeInfo>::type GetTypeInfo()
147 {
148 TypeInfo col_type;
149 col_type.byte_size = cast<uint02>(sizeof(decltype(t_type::Type())) / (ObjectInfo<decltype(t_type::Type())>::Dimensions + (ObjectInfo<decltype(t_type::Type())>::Dimensions == 0 ? 1 : 0)));
150 col_type.vector_size = ObjectInfo<decltype(t_type::Type())>::Dimensions;
151 col_type.total_size = cast<uint04>(sizeof(decltype(t_type::Type())));
152
153 col_type.is_number = ObjectInfo<decltype(t_type::Type())>::Number;
154 col_type.is_unsigned = ObjectInfo<decltype(t_type::Type())>::Unsigned;
155 col_type.is_float = ObjectInfo<decltype(t_type::Type())>::Float;
157 col_type.is_buffer = true;
158 col_type.is_color = ObjectInfo<decltype(t_type::Type())>::Color;
159 col_type.is_boolean = ObjectInfo<decltype(t_type::Type())>::Boolean;
160 return col_type;
161 }
162
163}
The core Color class in the NDEVR API.
Definition Color.h:42
Stores information about a type, relevant for certain templated functions.
Definition TypeInfo.h:43
bool is_unsigned
Whether the type represents an unsigned numeric value.
Definition TypeInfo.h:65
uint02 vector_size
The number of dimensions or components in the type (e.g. 3 for a 3D vector).
Definition TypeInfo.h:62
bool operator==(const TypeInfo &type) const
Checks whether two TypeInfo instances are equal by comparing all fields.
Definition TypeInfo.h:87
bool operator!=(const TypeInfo &type) const
Checks whether two TypeInfo instances are not equal.
Definition TypeInfo.h:105
bool isSame(const t_type &object)
Checks whether the given object has the same TypeInfo as this instance.
Definition TypeInfo.h:78
bool is_string
Whether the type represents a string.
Definition TypeInfo.h:67
bool is_buffer
Whether the type represents a buffer or container.
Definition TypeInfo.h:68
uint02 byte_size
The size in bytes of a single element within the type.
Definition TypeInfo.h:61
uint04 total_size
The total size of the type in bytes.
Definition TypeInfo.h:60
bool is_color
Whether the type represents a color.
Definition TypeInfo.h:69
bool is_number
Whether the type represents a numeric value.
Definition TypeInfo.h:64
constexpr TypeInfo()
Constructs a default TypeInfo with all sizes set to zero and all type flags set to false.
Definition TypeInfo.h:48
bool is_boolean
Whether the type represents a boolean.
Definition TypeInfo.h:70
bool is_float
Whether the type represents a floating-point numeric value.
Definition TypeInfo.h:66
The primary namespace for the NDEVR SDK.
@ type
The type identifier string for this model node.
Definition Model.h:58
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
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
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