cgv
Loading...
Searching...
No Matches
type_id.h
1#pragma once
2
3#include <string>
4#include <cgv/type/standard_types.h>
5#include <cgv/type/lib_begin.h>
6
7namespace cgv {
8 namespace type {
9 namespace info {
10
69
71inline bool is_unsigned_integral(TypeId tid) { return tid>=TI_UINT8 && tid<=TI_UINT64; }
72inline bool is_signed_integral(TypeId tid) { return tid>=TI_INT8 && tid<=TI_INT64; }
73inline bool is_integral(TypeId tid) { return tid>=TI_INT8 && tid<=TI_UINT64; }
74inline bool is_floating(TypeId tid) { return tid>=TI_FLT16 && tid<=TI_FLT64; }
75inline bool is_number(TypeId tid) { return tid>=TI_INT8 && tid<=TI_FLT64; }
76inline bool is_fundamental(TypeId tid) { return tid>=TI_FIRST_STD_TYPE && tid<=TI_LAST_STD_TYPE; }
77inline bool is_compound(TypeId tid) { return tid>=TI_STRUCT && tid<=TI_UNION; }
78inline bool is_type(TypeId tid) { return tid>=TI_FIRST_TYPE && tid<=TI_LAST_TYPE || tid > TI_LAST; }
79
80extern CGV_API TypeId get_new_type_id();
81
83
85template <typename T>
86struct type_id {
87 static TypeId get_id() { static TypeId ti = get_new_type_id(); return ti; }
88};
89
90template <> struct type_id<void> { static TypeId get_id() { return TI_VOID; } };
91template <> struct type_id<bool> { static TypeId get_id() { return TI_BOOL; } };
92template <> struct type_id<int8_type> { static TypeId get_id() { return TI_INT8; } };
93template <> struct type_id<int16_type> { static TypeId get_id() { return TI_INT16; } };
94template <> struct type_id<int32_type> { static TypeId get_id() { return TI_INT32; } };
95template <> struct type_id<int64_type> { static TypeId get_id() { return TI_INT64; } };
96template <> struct type_id<uint8_type> { static TypeId get_id() { return TI_UINT8; } };
97template <> struct type_id<uint16_type> { static TypeId get_id() { return TI_UINT16; } };
98template <> struct type_id<uint32_type> { static TypeId get_id() { return TI_UINT32; } };
99template <> struct type_id<uint64_type> { static TypeId get_id() { return TI_UINT64; } };
100template <> struct type_id<flt32_type> { static TypeId get_id() { return TI_FLT32; } };
101template <> struct type_id<flt64_type> { static TypeId get_id() { return TI_FLT64; } };
102template <> struct type_id<wchar_type> { static TypeId get_id() { return TI_WCHAR; } };
103template <> struct type_id<std::string> { static TypeId get_id() { return TI_STRING; } };
104template <> struct type_id<std::wstring> { static TypeId get_id() { return TI_WSTRING; } };
105
107extern CGV_API unsigned int get_type_size(TypeId tid);
108
110extern CGV_API const char* get_type_name(TypeId tid);
111
113extern CGV_API TypeId get_type_id(const std::string& _type_name);
114
115 }
116 }
117}
118
119#include <cgv/config/lib_end.h>
complete implementation of method actions that only call one method when entering a node
Definition action.h:113
TypeId get_type_id(const std::string &_type_name)
function that returns the type id of a type name
Definition type_id.cxx:53
unsigned int get_type_size(TypeId tid)
function that returns the size of a type specified through TypeId
Definition type_id.cxx:18
const char * get_type_name(TypeId tid)
function that returns the name of a type specified through TypeId
Definition type_id.cxx:117
bool is_unsigned_integral(TypeId tid)
query if a kind is an unsigned integral type
Definition type_id.h:71
TypeId
ids for the different types and type constructs
Definition type_id.h:12
@ TI_FIRST
alias for character type
Definition type_id.h:63
@ TI_INT16
signed integer stored in 8 bits
Definition type_id.h:20
@ TI_INT8
boolean
Definition type_id.h:19
@ TI_INT32
signed integer stored in 16 bits
Definition type_id.h:21
@ TI_VOID
bit based types
Definition type_id.h:16
@ TI_STRING
wide character type
Definition type_id.h:31
@ TI_TYPENAME
a type definition
Definition type_id.h:56
@ TI_FUNCTION
function or method signature
Definition type_id.h:49
@ TI_WCHAR
floating point type stored in 64 bits
Definition type_id.h:30
@ TI_ARRAY
pointer type construct
Definition type_id.h:37
@ TI_CLASSNAME
an undefined typename used as template parameter
Definition type_id.h:57
@ TI_INSTANCE
constructor of a compound
Definition type_id.h:54
@ TI_FIRST_TYPE
always the last standard type
Definition type_id.h:66
@ TI_CHAR
always the index after the last type construct
Definition type_id.h:62
@ TI_FLT32
floating point type stored in 16 bits
Definition type_id.h:28
@ TI_WSTRING
string type
Definition type_id.h:32
@ TI_TEMPLATE
an undefined class name used as template parameter
Definition type_id.h:58
@ TI_MEMBER
base type of a compound type
Definition type_id.h:51
@ TI_POINTER
reference type construct
Definition type_id.h:36
@ TI_LAST_TYPE
always the first standard type
Definition type_id.h:67
@ TI_CONST
union type compound
Definition type_id.h:45
@ TI_BIT
used for undefined type
Definition type_id.h:14
@ TI_UINT32
unsigned integer stored in 16 bits
Definition type_id.h:25
@ TI_UINT8
signed integer stored in 64 bits
Definition type_id.h:23
@ TI_METHOD
member of a compound
Definition type_id.h:52
@ TI_SIGNATURE
function or method parameter
Definition type_id.h:48
@ TI_INT64
signed integer stored in 32 bits
Definition type_id.h:22
@ TI_ENUM
string type
Definition type_id.h:34
@ TI_CLASS
struct type compound
Definition type_id.h:42
@ TI_TYPEDEF
an instance not a type
Definition type_id.h:55
@ TI_FUNCTION_POINTER
array type construct
Definition type_id.h:38
@ TI_METHOD_POINTER
member pointer type construct
Definition type_id.h:40
@ TI_STRUCT
method pointer type construct
Definition type_id.h:41
@ TI_FLT16
unsigned integer stored in 64 bits
Definition type_id.h:27
@ TI_BASE
function not a function pointer
Definition type_id.h:50
@ TI_MEMBER_POINTER
function pointer type construct
Definition type_id.h:39
@ TI_BOOL
void
Definition type_id.h:18
@ TI_CONSTRUCTOR
method of a compound, not a method pointer
Definition type_id.h:53
@ TI_FIRST_STD_TYPE
always the first type construct
Definition type_id.h:64
@ TI_EXPRESSION
const modifier
Definition type_id.h:46
@ TI_UNION
class type compound
Definition type_id.h:43
@ TI_UINT16
unsigned integer stored in 8 bits
Definition type_id.h:24
@ TI_FLT64
floating point type stored in 32 bits
Definition type_id.h:29
@ TI_UINT64
unsigned integer stored in 32 bits
Definition type_id.h:26
@ TI_REFERENCE
all enum types
Definition type_id.h:35
@ TI_LAST_STD_TYPE
always the first standard type
Definition type_id.h:65
@ TI_PARAMETER
expression used for default parameters
Definition type_id.h:47
@ TI_LAST
a template construct
Definition type_id.h:60
wchar_t wchar_type
wide character type
the cgv namespace
Definition print.h:11
template with a static member function get_id() of type TypeId returning the TypeId of the template a...
Definition type_id.h:86