Panda3D
 All Classes Functions Variables Enumerations
register_type.I
1 // Filename: register_type.I
2 // Created by: drose (06Aug01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: register_type
18 // Description: This inline function is just a convenient way to call
19 // TypeRegistry::register_type(), along with zero to four
20 // record_derivation()s. If for some reason you have a
21 // class that has more than four base classes (you're
22 // insane!), then you will need to call Register() and
23 // record_derivation() yourself.
24 ////////////////////////////////////////////////////////////////////
25 INLINE void
26 register_type(TypeHandle &type_handle, const string &name) {
27  TypeRegistry::ptr()->register_type(type_handle, name);
28 }
29 INLINE void
30 register_type(TypeHandle &type_handle, const string &name,
31  TypeHandle parent1) {
32  if (TypeRegistry::ptr()->register_type(type_handle, name)) {
33  TypeRegistry::ptr()->record_derivation(type_handle, parent1);
34  }
35 }
36 INLINE void
37 register_type(TypeHandle &type_handle, const string &name,
38  TypeHandle parent1, TypeHandle parent2) {
39  if (TypeRegistry::ptr()->register_type(type_handle, name)) {
40  TypeRegistry::ptr()->record_derivation(type_handle, parent1);
41  TypeRegistry::ptr()->record_derivation(type_handle, parent2);
42  }
43 }
44 INLINE void
45 register_type(TypeHandle &type_handle, const string &name,
46  TypeHandle parent1, TypeHandle parent2,
47  TypeHandle parent3) {
48  if (TypeRegistry::ptr()->register_type(type_handle, name)) {
49  TypeRegistry::ptr()->record_derivation(type_handle, parent1);
50  TypeRegistry::ptr()->record_derivation(type_handle, parent2);
51  TypeRegistry::ptr()->record_derivation(type_handle, parent3);
52  }
53 }
54 INLINE void
55 register_type(TypeHandle &type_handle, const string &name,
56  TypeHandle parent1, TypeHandle parent2,
57  TypeHandle parent3, TypeHandle parent4) {
58  if (TypeRegistry::ptr()->register_type(type_handle, name)) {
59  TypeRegistry::ptr()->record_derivation(type_handle, parent1);
60  TypeRegistry::ptr()->record_derivation(type_handle, parent2);
61  TypeRegistry::ptr()->record_derivation(type_handle, parent3);
62  TypeRegistry::ptr()->record_derivation(type_handle, parent4);
63  }
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: register_dynamic_type
68 // Description: This is essentially similar to register_type(),
69 // except that it doesn't store a reference to any
70 // TypeHandle passed in and it therefore doesn't
71 // complain if the type is registered more than once to
72 // different TypeHandle reference.
73 ////////////////////////////////////////////////////////////////////
74 INLINE TypeHandle
75 register_dynamic_type(const string &name) {
77 }
78 INLINE TypeHandle
79 register_dynamic_type(const string &name, TypeHandle parent1) {
80  TypeHandle type_handle =
82  TypeRegistry::ptr()->record_derivation(type_handle, parent1);
83  return type_handle;
84 }
85 INLINE TypeHandle
86 register_dynamic_type(const string &name,
87  TypeHandle parent1, TypeHandle parent2) {
88  TypeHandle type_handle =
90  TypeRegistry::ptr()->record_derivation(type_handle, parent1);
91  TypeRegistry::ptr()->record_derivation(type_handle, parent2);
92  return type_handle;
93 }
94 INLINE TypeHandle
95 register_dynamic_type(const string &name,
96  TypeHandle parent1, TypeHandle parent2,
97  TypeHandle parent3) {
98  TypeHandle type_handle =
100  TypeRegistry::ptr()->record_derivation(type_handle, parent1);
101  TypeRegistry::ptr()->record_derivation(type_handle, parent2);
102  TypeRegistry::ptr()->record_derivation(type_handle, parent3);
103  return type_handle;
104 }
105 INLINE TypeHandle
106 register_dynamic_type(const string &name,
107  TypeHandle parent1, TypeHandle parent2,
108  TypeHandle parent3, TypeHandle parent4) {
109  TypeHandle type_handle =
111  TypeRegistry::ptr()->record_derivation(type_handle, parent1);
112  TypeRegistry::ptr()->record_derivation(type_handle, parent2);
113  TypeRegistry::ptr()->record_derivation(type_handle, parent3);
114  TypeRegistry::ptr()->record_derivation(type_handle, parent4);
115  return type_handle;
116 }
TypeHandle register_dynamic_type(const string &name)
Registers a new type on-the-fly, presumably at runtime.
static TypeRegistry * ptr()
Returns the pointer to the global TypeRegistry object.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
bool register_type(TypeHandle &type_handle, const string &name)
Creates a new Type of the given name and assigns a unique value to the type_handle.
void record_derivation(TypeHandle child, TypeHandle parent)
Records that the type referenced by child inherits directly from the type referenced by parent...