forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypeHandle.I
More file actions
208 lines (189 loc) · 5.47 KB
/
typeHandle.I
File metadata and controls
208 lines (189 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file typeHandle.I
* @author drose
* @date 2000-02-22
*/
/**
*
*/
INLINE bool TypeHandle::
operator == (const TypeHandle &other) const {
return (_index == other._index);
}
/**
*
*/
INLINE bool TypeHandle::
operator != (const TypeHandle &other) const {
return (_index != other._index);
}
/**
*
*/
INLINE bool TypeHandle::
operator < (const TypeHandle &other) const {
return (_index < other._index);
}
/**
*
*/
INLINE bool TypeHandle::
operator <= (const TypeHandle &other) const {
return (_index <= other._index);
}
/**
*
*/
INLINE bool TypeHandle::
operator > (const TypeHandle &other) const {
return (_index > other._index);
}
/**
*
*/
INLINE bool TypeHandle::
operator >= (const TypeHandle &other) const {
return (_index >= other._index);
}
/**
* Sorts TypeHandles arbitrarily (according to <, >, etc.). Returns a number
* less than 0 if this type sorts before the other one, greater than zero if
* it sorts after, 0 if they are equivalent.
*/
INLINE int TypeHandle::
compare_to(const TypeHandle &other) const {
return _index - other._index;
}
/**
* Returns a hash code suitable for phash_map.
*/
INLINE size_t TypeHandle::
get_hash() const {
return (size_t)_index;
}
/**
* Returns the name of the type.
*
* The "object" pointer is an optional pointer to the TypedObject class that
* owns this TypeHandle. It is only used in case the TypeHandle is
* inadvertantly undefined.
*/
INLINE std::string TypeHandle::
get_name(TypedObject *object) const {
if ((*this) == TypeHandle::none()) {
return "none";
} else {
return TypeRegistry::ptr()->get_name(*this, object);
}
}
/**
* Returns true if this type is derived from the indicated type, false
* otherwise.
*
* The "object" pointer is an optional pointer to the TypedObject class that
* owns this TypeHandle. It is only used in case the TypeHandle is
* inadvertantly undefined.
*/
INLINE bool TypeHandle::
is_derived_from(TypeHandle parent, TypedObject *object) const {
return TypeRegistry::ptr()->is_derived_from(*this, parent, object);
}
/**
* Returns the number of parent classes that this type is known to have. This
* may then be used to index into get_parent_class(). The result will be 0 if
* this class does not inherit from any other classes, 1 if normal, single
* inheritance is in effect, or greater than one if multiple inheritance is in
* effect.
*
* The "object" pointer is an optional pointer to the TypedObject class that
* owns this TypeHandle. It is only used in case the TypeHandle is
* inadvertantly undefined.
*/
INLINE int TypeHandle::
get_num_parent_classes(TypedObject *object) const {
return TypeRegistry::ptr()->get_num_parent_classes(*this, object);
}
/**
* Returns the nth parent class of this type. The index should be in the
* range 0 <= index < get_num_parent_classes().
*/
INLINE TypeHandle TypeHandle::
get_parent_class(int index) const {
return TypeRegistry::ptr()->get_parent_class(*this, index);
}
/**
* Returns the number of child classes that this type is known to have. This
* may then be used to index into get_child_class().
*
* The "object" pointer is an optional pointer to the TypedObject class that
* owns this TypeHandle. It is only used in case the TypeHandle is
* inadvertantly undefined.
*/
INLINE int TypeHandle::
get_num_child_classes(TypedObject *object) const {
return TypeRegistry::ptr()->get_num_child_classes(*this, object);
}
/**
* Returns the nth child class of this type. The index should be in the range
* 0 <= index < get_num_child_classes().
*/
INLINE TypeHandle TypeHandle::
get_child_class(int index) const {
return TypeRegistry::ptr()->get_child_class(*this, index);
}
/**
* Returns the parent class that is in a direct line of inheritance to the
* indicated ancestor class. This is useful in the presence of multiple
* inheritance to try to determine what properties an unknown type may have.
*
* The return value is TypeHandle::none() if the type does not inherit from
* the ancestor. If ancestor is the same as this type, the return value is
* this type.
*
* The "object" pointer is an optional pointer to the TypedObject class that
* owns this TypeHandle. It is only used in case the TypeHandle is
* inadvertantly undefined.
*/
INLINE TypeHandle TypeHandle::
get_parent_towards(TypeHandle ancestor, TypedObject *object) const {
return TypeRegistry::ptr()->get_parent_towards(*this, ancestor, object);
}
/**
* Returns the integer index associated with this TypeHandle. Each different
* TypeHandle will have a different index. However, you probably shouldn't be
* using this method; you should just treat the TypeHandles as opaque classes.
* This is provided for the convenience of non-C++ scripting languages to
* build a hashtable of TypeHandles.
*/
INLINE int TypeHandle::
get_index() const {
return _index;
}
/**
*
*/
INLINE void TypeHandle::
output(std::ostream &out) const {
out << get_name();
}
/**
* TypeHandle::none() evaluates to false, everything else evaluates to true.
*/
INLINE TypeHandle::
operator bool () const {
return (_index != 0);
}
/**
* Private constructor for initializing a TypeHandle from an index, used by
* none() and by from_index().
*/
constexpr TypeHandle::
TypeHandle(int index) : _index(index) {
}