cgv
Loading...
Searching...
No Matches
type_id.cxx
1#include "type_id.h"
2#include <cgv/type/standard_types.h>
3#include <map>
4#include <typeinfo>
5
6namespace cgv {
7 namespace type {
8 namespace info {
9
10TypeId get_new_type_id()
11{
12 static int ti_counter = TI_LAST;
13 return TypeId(++ti_counter);
14}
15
16
18unsigned int get_type_size(TypeId tid)
19{
20 static unsigned int type_size_table[] = {
21 unsigned(-1),
22 unsigned(-1),
23 unsigned(-1),
24 sizeof(bool),
25 sizeof(int8_type),
26 sizeof(int16_type),
27 sizeof(int32_type),
28 sizeof(int64_type),
29 sizeof(uint8_type),
30 sizeof(uint16_type),
31 sizeof(uint32_type),
32 sizeof(uint64_type),
33 2, // flt16
34 sizeof(flt32_type),
35 sizeof(flt64_type),
36 sizeof(wchar_t),
37 sizeof(std::string),
38 sizeof(std::wstring),
39 sizeof(DummyEnum)
40 };
41 if (tid > TI_ENUM)
42 return unsigned(-1);
43 return type_size_table[tid];
44}
45
46
48{
49 const char* name;
50 TypeId tip;
51};
52
53TypeId get_type_id(const std::string& _type_name)
54{
55 static const name_type_id_pair nti_pairs[] = {
56 { "bit", TI_BIT },
57 { "void", TI_VOID },
58 { "bool", TI_BOOL },
59 { "int8", TI_INT8 }, { typeid(int8_type).name(), TI_INT8 },
60 { "int16", TI_INT16 }, { typeid(int16_type).name(), TI_INT16 },
61 { "int32", TI_INT32 }, { typeid(int32_type).name(), TI_INT32 },
62 { "int64", TI_INT64 }, { typeid(int64_type).name(), TI_INT64 },
63 { "uint8", TI_UINT8 }, { typeid(uint8_type).name(), TI_UINT8 },
64 { "uint16", TI_UINT16 }, { typeid(uint16_type).name(), TI_UINT16 },
65 { "uint32", TI_UINT32 }, { typeid(uint32_type).name(), TI_UINT32 },
66 { "uint64", TI_UINT64 }, { typeid(uint64_type).name(), TI_UINT64 },
67 { "flt16", TI_FLT16 },
68 { "flt32", TI_FLT32 }, { typeid(flt32_type).name(), TI_FLT32 },
69 { "flt64", TI_FLT64 }, { typeid(flt64_type).name(), TI_FLT64 },
70 { "wchar", TI_WCHAR },
71 { "string", TI_STRING },
72 { "wstring", TI_WSTRING },
73
74 { "enum", TI_ENUM },
75 { "reference", TI_REFERENCE },
76 { "pointer", TI_POINTER },
77 { "array", TI_ARRAY },
78 { "function_pointer", TI_FUNCTION_POINTER },
79 { "member_pointer", TI_MEMBER_POINTER },
80 { "method_pointer", TI_METHOD_POINTER },
81 { "struct", TI_STRUCT },
82 { "class", TI_CLASS },
83 { "union", TI_UNION },
84
85 { "const", TI_CONST },
86 { "expression", TI_EXPRESSION },
87 { "parameter", TI_PARAMETER },
88 { "signature", TI_SIGNATURE },
89 { "function", TI_FUNCTION },
90 { "base", TI_BASE },
91 { "member", TI_MEMBER },
92 { "method", TI_METHOD },
93 { "constructor", TI_CONSTRUCTOR },
94 { "instance", TI_INSTANCE },
95 { "typedef", TI_TYPEDEF },
96 { "typename", TI_TYPENAME },
97 { "classname", TI_CLASSNAME },
98 { "template", TI_TEMPLATE },
99 { 0, TI_UNDEF }
100 };
101 static std::map<const std::string,TypeId> type_name_id_map;
102 if (type_name_id_map.empty()) {
103 unsigned i = 0;
104 do {
105 type_name_id_map[nti_pairs[i].name] = nti_pairs[i].tip;
106 ++i;
107 } while (nti_pairs[i].name);
108 }
109 std::map<const std::string,TypeId>::iterator it = type_name_id_map.find(_type_name.c_str());
110 if (it == type_name_id_map.end())
111 return TI_UNDEF;
112 else
113 return it->second;
114}
115
117const char* get_type_name(TypeId tid)
118{
119 static const char* type_name_table[] = {
120 "undef",
121 "bit",
122
123 "void",
124
125 "bool",
126 "int8",
127 "int16",
128 "int32",
129 "int64",
130 "uint8",
131 "uint16",
132 "uint32",
133 "uint64",
134 "flt16",
135 "flt32",
136 "flt64",
137 "wchar",
138 "string",
139 "wstring",
140
141 "enum",
142 "reference",
143 "pointer",
144 "array",
145 "function_pointer",
146 "member_pointer",
147 "method_pointer",
148 "struct",
149 "class",
150 "union",
151
152 "const",
153 "expression",
154 "parameter",
155 "signature",
156 "function",
157 "base",
158 "member",
159 "method",
160 "constructor",
161 "instance",
162 "typedef",
163 "typename",
164 "classname",
165 "template",
166 "last"
167 };
168 return type_name_table[tid];
169}
170
171/*
173TypeId get_type_id(const std::string& _type_name)
174{
175 for (TypeId tid = TI_FIRST; tid < TI_LAST; tid = TypeId(tid+1)) {
176 if (_type_name == get_type_name(tid))
177 return tid;
178 }
179 return TI_UNDEF;
180}
181
182*/
183 }
184 }
185}
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
TypeId
ids for the different types and type constructs
Definition type_id.h:12
@ 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_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_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_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_PARAMETER
expression used for default parameters
Definition type_id.h:47
@ TI_LAST
a template construct
Definition type_id.h:60
double flt64_type
this type provides a 64 bit floating point type
DummyEnum
some enum to mark an integral parameter to be of enum type
signed char int8_type
this type provides an 8 bit signed integer type
int int32_type
this type provides an 32 bit signed integer type
short int16_type
this type provides an 16 bit signed integer type
unsigned short uint16_type
this type provides an 16 bit unsigned integer type
unsigned long long uint64_type
this type provides an 64 bit unsigned integer type
unsigned int uint32_type
this type provides an 32 bit unsigned integer type
long long int64_type
this type provides an 64 bit signed integer type
float flt32_type
this type provides a 32 bit floating point type
unsigned char uint8_type
this type provides an 8 bit unsigned integer type
the cgv namespace
Definition print.h:11