API Documentation
Loading...
Searching...
No Matches
TypeInfo.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: 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/ObjectInfo.h>
36namespace NDEVR
37{
38 /**--------------------------------------------------------------------------------------------------
39 \brief Stores information about a type, relevant for certain templated functions.
40 To get information about a type at runtime use ObjectInfo
41 **/
43 {
44 public:
45 constexpr TypeInfo()
46 : total_size(0)
47 , byte_size(0)
48 , vector_size(0)
49 , is_number(false)
50 , is_unsigned(false)
51 , is_float(false)
52 , is_string(false)
53 , is_buffer(false)
54 , is_color(false)
55 , is_boolean(false)
56 {}
60
68
69 template<class t_type>
70 bool isSame(const t_type& object)
71 {
72 return TypeInfo(object) == *this;
73 }
74 bool operator==(const TypeInfo& type) const
75 {
76 return total_size == type.total_size
77 && byte_size == type.byte_size
78 && vector_size == type.vector_size
79 && is_number == type.is_number
80 && is_unsigned == type.is_unsigned
81 && is_float == type.is_float
82 && is_string == type.is_string
83 && is_buffer == type.is_buffer
84 && is_color == type.is_color
85 && is_boolean == type.is_boolean;
86 }
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 };
101 static_assert(sizeof(TypeInfo) == 16, "Bad TypeInfo Size");//used in raw ndv file
102 template<class t_type, bool is_buffer = ObjectInfo<t_type>::Buffer>
103 constexpr typename std::enable_if<!ObjectInfo<t_type>::Buffer, TypeInfo>::type GetTypeInfo()
104 {
105 TypeInfo col_type;
106 col_type.byte_size = cast<uint02>(sizeof(t_type) / (ObjectInfo<t_type>::Dimensions + (ObjectInfo<t_type>::Dimensions == 0 ? 1 : 0)));
108 col_type.total_size = cast<uint04>(sizeof(t_type));
109
117 return col_type;
118 }
119 template<class t_type>
120 constexpr typename std::enable_if<ObjectInfo<t_type>::Buffer, TypeInfo>::type GetTypeInfo()
121 {
122 TypeInfo col_type;
123 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)));
124 col_type.vector_size = ObjectInfo<decltype(t_type::Type())>::Dimensions;
125 col_type.total_size = cast<uint04>(sizeof(decltype(t_type::Type())));
126
127 col_type.is_number = ObjectInfo<decltype(t_type::Type())>::Number;
128 col_type.is_unsigned = ObjectInfo<decltype(t_type::Type())>::Unsigned;
129 col_type.is_float = ObjectInfo<decltype(t_type::Type())>::Float;
131 col_type.is_buffer = true;
132 col_type.is_color = ObjectInfo<decltype(t_type::Type())>::Color;
133 col_type.is_boolean = ObjectInfo<decltype(t_type::Type())>::Boolean;
134 return col_type;
135 }
136
137}
Stores information about a type, relevant for certain templated functions. To get information about a...
Definition TypeInfo.h:43
bool operator==(const TypeInfo &type) const
Definition TypeInfo.h:74
bool is_number
Definition TypeInfo.h:61
constexpr TypeInfo()
Definition TypeInfo.h:45
bool operator!=(const TypeInfo &type) const
Definition TypeInfo.h:87
bool is_unsigned
Definition TypeInfo.h:62
bool is_color
Definition TypeInfo.h:66
bool is_buffer
Definition TypeInfo.h:65
uint02 byte_size
Definition TypeInfo.h:58
bool is_string
Definition TypeInfo.h:64
uint02 vector_size
Definition TypeInfo.h:59
bool is_float
Definition TypeInfo.h:63
bool isSame(const t_type &object)
Definition TypeInfo.h:70
uint04 total_size
Definition TypeInfo.h:57
bool is_boolean
Definition TypeInfo.h:67
Definition ACIColor.h:37
constexpr std::enable_if<!ObjectInfo< t_type >::Buffer, TypeInfo >::type GetTypeInfo()
Definition TypeInfo.h:103
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
Information about the object.
Definition ObjectInfo.h:54