Panda3D
register_type.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file register_type.h
10  * @author drose
11  * @date 2001-08-06
12  */
13 
14 #ifndef REGISTER_TYPE_H
15 #define REGISTER_TYPE_H
16 
17 #include "dtoolbase.h"
18 
19 #include "typeHandle.h"
20 #include "typeRegistry.h"
21 
22 /**
23  * This inline function is just a convenient way to call
24  * TypeRegistry::register_type(), along with zero to four
25  * record_derivation()s. If for some reason you have a class that has more
26  * than four base classes (you're insane!), then you will need to call
27  * Register() and record_derivation() yourself.
28  */
29 INLINE void
30 register_type(TypeHandle &type_handle, const std::string &name);
31 
32 INLINE void
33 register_type(TypeHandle &type_handle, const std::string &name,
34  TypeHandle parent1);
35 
36 INLINE void
37 register_type(TypeHandle &type_handle, const std::string &name,
38  TypeHandle parent1, TypeHandle parent2);
39 
40 INLINE void
41 register_type(TypeHandle &type_handle, const std::string &name,
42  TypeHandle parent1, TypeHandle parent2,
43  TypeHandle parent3);
44 
45 INLINE void
46 register_type(TypeHandle &type_handle, const std::string &name,
47  TypeHandle parent1, TypeHandle parent2,
48  TypeHandle parent3, TypeHandle parent4);
49 
50 
51 /**
52  * This is essentially similar to register_type(), except that it doesn't
53  * store a reference to any TypeHandle passed in and it therefore doesn't
54  * complain if the type is registered more than once to different TypeHandle
55  * reference.
56  */
57 INLINE TypeHandle
58 register_dynamic_type(const std::string &name);
59 
60 INLINE TypeHandle
61 register_dynamic_type(const std::string &name, TypeHandle parent1);
62 
63 INLINE TypeHandle
64 register_dynamic_type(const std::string &name,
65  TypeHandle parent1, TypeHandle parent2);
66 
67 INLINE TypeHandle
68 register_dynamic_type(const std::string &name,
69  TypeHandle parent1, TypeHandle parent2,
70  TypeHandle parent3);
71 
72 INLINE TypeHandle
73 register_dynamic_type(const std::string &name,
74  TypeHandle parent1, TypeHandle parent2,
75  TypeHandle parent3, TypeHandle parent4);
76 
77 
78 // A few system-wide TypeHandles are defined for some basic types.
79 extern TypeHandle EXPCL_DTOOL_DTOOLBASE long_type_handle;
80 extern TypeHandle EXPCL_DTOOL_DTOOLBASE int_type_handle;
81 extern TypeHandle EXPCL_DTOOL_DTOOLBASE uint_type_handle;
82 extern TypeHandle EXPCL_DTOOL_DTOOLBASE short_type_handle;
83 extern TypeHandle EXPCL_DTOOL_DTOOLBASE ushort_type_handle;
84 extern TypeHandle EXPCL_DTOOL_DTOOLBASE char_type_handle;
85 extern TypeHandle EXPCL_DTOOL_DTOOLBASE uchar_type_handle;
86 extern TypeHandle EXPCL_DTOOL_DTOOLBASE bool_type_handle;
87 extern TypeHandle EXPCL_DTOOL_DTOOLBASE double_type_handle;
88 extern TypeHandle EXPCL_DTOOL_DTOOLBASE float_type_handle;
89 extern TypeHandle EXPCL_DTOOL_DTOOLBASE string_type_handle;
90 extern TypeHandle EXPCL_DTOOL_DTOOLBASE wstring_type_handle;
91 
92 extern TypeHandle long_p_type_handle;
93 extern TypeHandle int_p_type_handle;
94 extern TypeHandle short_p_type_handle;
95 extern TypeHandle char_p_type_handle;
96 extern TypeHandle bool_p_type_handle;
97 extern TypeHandle double_p_type_handle;
98 extern TypeHandle float_p_type_handle;
99 extern TypeHandle void_p_type_handle;
100 
101 extern TypeHandle EXPCL_DTOOL_DTOOLBASE pvector_type_handle;
102 extern TypeHandle EXPCL_DTOOL_DTOOLBASE ov_set_type_handle;
103 extern TypeHandle EXPCL_DTOOL_DTOOLBASE pdeque_type_handle;
104 extern TypeHandle EXPCL_DTOOL_DTOOLBASE plist_type_handle;
105 extern TypeHandle EXPCL_DTOOL_DTOOLBASE pmap_type_handle;
106 extern TypeHandle EXPCL_DTOOL_DTOOLBASE pset_type_handle;
107 
108 void EXPCL_DTOOL_DTOOLBASE init_system_type_handles();
109 
110 // The following template function and its specializations will return a
111 // TypeHandle for any type in the world, from a pointer to that type.
112 
113 template<class T>
114 INLINE TypeHandle _get_type_handle(const T *) {
115  return T::get_class_type();
116 }
117 
118 template<>
119 INLINE TypeHandle _get_type_handle(const long *) {
120  return long_type_handle;
121 }
122 
123 template<>
124 INLINE TypeHandle _get_type_handle(const int *) {
125  return int_type_handle;
126 }
127 
128 template<>
129 INLINE TypeHandle _get_type_handle(const unsigned int *) {
130  return uint_type_handle;
131 }
132 
133 template<>
134 INLINE TypeHandle _get_type_handle(const short *) {
135  return short_type_handle;
136 }
137 
138 template<>
139 INLINE TypeHandle _get_type_handle(const unsigned short *) {
140  return ushort_type_handle;
141 }
142 
143 template<>
144 INLINE TypeHandle _get_type_handle(const char *) {
145  return char_type_handle;
146 }
147 
148 template<>
149 INLINE TypeHandle _get_type_handle(const unsigned char *) {
150  return uchar_type_handle;
151 }
152 
153 template<>
154 INLINE TypeHandle _get_type_handle(const bool *) {
155  return bool_type_handle;
156 }
157 
158 template<>
159 INLINE TypeHandle _get_type_handle(const double *) {
160  return double_type_handle;
161 }
162 
163 template<>
164 INLINE TypeHandle _get_type_handle(const float *) {
165  return float_type_handle;
166 }
167 
168 template<>
169 INLINE TypeHandle _get_type_handle(const std::string *) {
170  return string_type_handle;
171 }
172 
173 template<>
174 INLINE TypeHandle _get_type_handle(const std::wstring *) {
175  return wstring_type_handle;
176 }
177 
178 template<>
179 INLINE TypeHandle _get_type_handle(const long * const *) {
180  return long_p_type_handle;
181 }
182 
183 template<>
184 INLINE TypeHandle _get_type_handle(const int * const *) {
185  return int_p_type_handle;
186 }
187 
188 template<>
189 INLINE TypeHandle _get_type_handle(const short * const *) {
190  return short_p_type_handle;
191 }
192 
193 template<>
194 INLINE TypeHandle _get_type_handle(const char * const *) {
195  return char_p_type_handle;
196 }
197 
198 template<>
199 INLINE TypeHandle _get_type_handle(const bool * const *) {
200  return bool_p_type_handle;
201 }
202 
203 template<>
204 INLINE TypeHandle _get_type_handle(const double * const *) {
205  return double_p_type_handle;
206 }
207 
208 template<>
209 INLINE TypeHandle _get_type_handle(const float * const *) {
210  return float_p_type_handle;
211 }
212 
213 template<>
214 INLINE TypeHandle _get_type_handle(const void * const *) {
215  return void_p_type_handle;
216 }
217 
218 
219 // The macro get_type_handle(type) is defined to make getting the type handle
220 // associated with a particular type a bit cleaner.
221 #define get_type_handle(type) _get_type_handle((const type *)0)
222 
223 
224 // The following template function and its specializations can be used to call
225 // init() on any unknown type. Handy for use within a template class.
226 
227 template<class T>
228 INLINE void _do_init_type(const T *) {
229  T::init_type();
230 }
231 
232 template<>
233 INLINE void _do_init_type(const long *) {
234  init_system_type_handles();
235 }
236 
237 template<>
238 INLINE void _do_init_type(const int *) {
239  init_system_type_handles();
240 }
241 
242 template<>
243 INLINE void _do_init_type(const short *) {
244  init_system_type_handles();
245 }
246 
247 template<>
248 INLINE void _do_init_type(const char *) {
249  init_system_type_handles();
250 }
251 
252 template<>
253 INLINE void _do_init_type(const bool *) {
254  init_system_type_handles();
255 }
256 
257 template<>
258 INLINE void _do_init_type(const double *) {
259  init_system_type_handles();
260 }
261 
262 template<>
263 INLINE void _do_init_type(const float *) {
264  init_system_type_handles();
265 }
266 
267 template<>
268 INLINE void _do_init_type(const long * const *) {
269  init_system_type_handles();
270 }
271 
272 template<>
273 INLINE void _do_init_type(const int * const *) {
274  init_system_type_handles();
275 }
276 
277 template<>
278 INLINE void _do_init_type(const short * const *) {
279  init_system_type_handles();
280 }
281 
282 template<>
283 INLINE void _do_init_type(const char * const *) {
284  init_system_type_handles();
285 }
286 
287 template<>
288 INLINE void _do_init_type(const bool * const *) {
289  init_system_type_handles();
290 }
291 
292 template<>
293 INLINE void _do_init_type(const double * const *) {
294  init_system_type_handles();
295 }
296 
297 template<>
298 INLINE void _do_init_type(const float * const *) {
299  init_system_type_handles();
300 }
301 
302 template<>
303 INLINE void _do_init_type(const void * const *) {
304  init_system_type_handles();
305 }
306 
307 #define do_init_type(type) _do_init_type((const type *)0)
308 
309 #include "register_type.I"
310 
311 #endif
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
TypeHandle register_dynamic_type(const std::string &name)
This is essentially similar to register_type(), except that it doesn't store a reference to any TypeH...
Definition: register_type.I:69