Panda3D
Loading...
Searching...
No Matches
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 */
29INLINE void
30register_type(TypeHandle &type_handle, const std::string &name);
31
32INLINE void
33register_type(TypeHandle &type_handle, const std::string &name,
34 TypeHandle parent1);
35
36INLINE void
37register_type(TypeHandle &type_handle, const std::string &name,
38 TypeHandle parent1, TypeHandle parent2);
39
40INLINE void
41register_type(TypeHandle &type_handle, const std::string &name,
42 TypeHandle parent1, TypeHandle parent2,
43 TypeHandle parent3);
44
45INLINE void
46register_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 */
57INLINE TypeHandle
58register_dynamic_type(const std::string &name);
59
60INLINE TypeHandle
61register_dynamic_type(const std::string &name, TypeHandle parent1);
62
63INLINE TypeHandle
64register_dynamic_type(const std::string &name,
65 TypeHandle parent1, TypeHandle parent2);
66
67INLINE TypeHandle
68register_dynamic_type(const std::string &name,
69 TypeHandle parent1, TypeHandle parent2,
70 TypeHandle parent3);
71
72INLINE TypeHandle
73register_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.
79extern TypeHandle EXPCL_DTOOL_DTOOLBASE long_type_handle;
80extern TypeHandle EXPCL_DTOOL_DTOOLBASE int_type_handle;
81extern TypeHandle EXPCL_DTOOL_DTOOLBASE uint_type_handle;
82extern TypeHandle EXPCL_DTOOL_DTOOLBASE short_type_handle;
83extern TypeHandle EXPCL_DTOOL_DTOOLBASE ushort_type_handle;
84extern TypeHandle EXPCL_DTOOL_DTOOLBASE char_type_handle;
85extern TypeHandle EXPCL_DTOOL_DTOOLBASE uchar_type_handle;
86extern TypeHandle EXPCL_DTOOL_DTOOLBASE bool_type_handle;
87extern TypeHandle EXPCL_DTOOL_DTOOLBASE double_type_handle;
88extern TypeHandle EXPCL_DTOOL_DTOOLBASE float_type_handle;
89extern TypeHandle EXPCL_DTOOL_DTOOLBASE string_type_handle;
90extern TypeHandle EXPCL_DTOOL_DTOOLBASE wstring_type_handle;
91
92extern TypeHandle long_p_type_handle;
93extern TypeHandle int_p_type_handle;
94extern TypeHandle short_p_type_handle;
95extern TypeHandle char_p_type_handle;
96extern TypeHandle bool_p_type_handle;
97extern TypeHandle double_p_type_handle;
98extern TypeHandle float_p_type_handle;
99extern TypeHandle void_p_type_handle;
100
101extern TypeHandle EXPCL_DTOOL_DTOOLBASE pvector_type_handle;
102extern TypeHandle EXPCL_DTOOL_DTOOLBASE ov_set_type_handle;
103extern TypeHandle EXPCL_DTOOL_DTOOLBASE pdeque_type_handle;
104extern TypeHandle EXPCL_DTOOL_DTOOLBASE plist_type_handle;
105extern TypeHandle EXPCL_DTOOL_DTOOLBASE pmap_type_handle;
106extern TypeHandle EXPCL_DTOOL_DTOOLBASE pset_type_handle;
107
108void 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
113template<class T>
114INLINE TypeHandle _get_type_handle(const T *) {
115 return T::get_class_type();
116}
117
118template<>
119INLINE TypeHandle _get_type_handle(const long *) {
120 return long_type_handle;
121}
122
123template<>
124INLINE TypeHandle _get_type_handle(const int *) {
125 return int_type_handle;
126}
127
128template<>
129INLINE TypeHandle _get_type_handle(const unsigned int *) {
130 return uint_type_handle;
131}
132
133template<>
134INLINE TypeHandle _get_type_handle(const short *) {
135 return short_type_handle;
136}
137
138template<>
139INLINE TypeHandle _get_type_handle(const unsigned short *) {
140 return ushort_type_handle;
141}
142
143template<>
144INLINE TypeHandle _get_type_handle(const char *) {
145 return char_type_handle;
146}
147
148template<>
149INLINE TypeHandle _get_type_handle(const unsigned char *) {
150 return uchar_type_handle;
151}
152
153template<>
154INLINE TypeHandle _get_type_handle(const bool *) {
155 return bool_type_handle;
156}
157
158template<>
159INLINE TypeHandle _get_type_handle(const double *) {
160 return double_type_handle;
161}
162
163template<>
164INLINE TypeHandle _get_type_handle(const float *) {
165 return float_type_handle;
166}
167
168template<>
169INLINE TypeHandle _get_type_handle(const std::string *) {
170 return string_type_handle;
171}
172
173template<>
174INLINE TypeHandle _get_type_handle(const std::wstring *) {
175 return wstring_type_handle;
176}
177
178template<>
179INLINE TypeHandle _get_type_handle(const long * const *) {
180 return long_p_type_handle;
181}
182
183template<>
184INLINE TypeHandle _get_type_handle(const int * const *) {
185 return int_p_type_handle;
186}
187
188template<>
189INLINE TypeHandle _get_type_handle(const short * const *) {
190 return short_p_type_handle;
191}
192
193template<>
194INLINE TypeHandle _get_type_handle(const char * const *) {
195 return char_p_type_handle;
196}
197
198template<>
199INLINE TypeHandle _get_type_handle(const bool * const *) {
200 return bool_p_type_handle;
201}
202
203template<>
204INLINE TypeHandle _get_type_handle(const double * const *) {
205 return double_p_type_handle;
206}
207
208template<>
209INLINE TypeHandle _get_type_handle(const float * const *) {
210 return float_p_type_handle;
211}
212
213template<>
214INLINE 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
227template<class T>
228INLINE void _do_init_type(const T *) {
229 T::init_type();
230}
231
232template<>
233INLINE void _do_init_type(const long *) {
234 init_system_type_handles();
235}
236
237template<>
238INLINE void _do_init_type(const int *) {
239 init_system_type_handles();
240}
241
242template<>
243INLINE void _do_init_type(const short *) {
244 init_system_type_handles();
245}
246
247template<>
248INLINE void _do_init_type(const char *) {
249 init_system_type_handles();
250}
251
252template<>
253INLINE void _do_init_type(const bool *) {
254 init_system_type_handles();
255}
256
257template<>
258INLINE void _do_init_type(const double *) {
259 init_system_type_handles();
260}
261
262template<>
263INLINE void _do_init_type(const float *) {
264 init_system_type_handles();
265}
266
267template<>
268INLINE void _do_init_type(const long * const *) {
269 init_system_type_handles();
270}
271
272template<>
273INLINE void _do_init_type(const int * const *) {
274 init_system_type_handles();
275}
276
277template<>
278INLINE void _do_init_type(const short * const *) {
279 init_system_type_handles();
280}
281
282template<>
283INLINE void _do_init_type(const char * const *) {
284 init_system_type_handles();
285}
286
287template<>
288INLINE void _do_init_type(const bool * const *) {
289 init_system_type_handles();
290}
291
292template<>
293INLINE void _do_init_type(const double * const *) {
294 init_system_type_handles();
295}
296
297template<>
298INLINE void _do_init_type(const float * const *) {
299 init_system_type_handles();
300}
301
302template<>
303INLINE 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
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.