00001 // Filename: typeHandle.I 00002 // Created by: drose (22Feb00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 00020 // In general, we use the express_cat->info() syntax in this file 00021 // (instead of express_cat.info()), because much of this work is done at 00022 // static init time, and we must use the arrow syntax to force 00023 // initialization of the express_cat category. 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Function: TypeHandle::Constructor 00027 // Access: Published 00028 // Description: The default constructor must do nothing, because we 00029 // can't guarantee ordering of static initializers. If 00030 // the constructor tried to initialize its value, it 00031 // might happen after the value had already been set 00032 // previously by another static initializer! 00033 //////////////////////////////////////////////////////////////////// 00034 INLINE TypeHandle:: 00035 TypeHandle() { 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function: TypeHandle::Copy Constructor 00040 // Access: Published 00041 // Description: 00042 //////////////////////////////////////////////////////////////////// 00043 INLINE TypeHandle:: 00044 TypeHandle(const TypeHandle ©) : _index(copy._index) { 00045 } 00046 00047 //////////////////////////////////////////////////////////////////// 00048 // Function: TypeHandle::Equality Operator 00049 // Access: Published 00050 // Description: 00051 //////////////////////////////////////////////////////////////////// 00052 INLINE bool TypeHandle:: 00053 operator == (const TypeHandle &other) const { 00054 return (_index == other._index); 00055 } 00056 00057 //////////////////////////////////////////////////////////////////// 00058 // Function: TypeHandle::Inequality Operator 00059 // Access: Published 00060 // Description: 00061 //////////////////////////////////////////////////////////////////// 00062 INLINE bool TypeHandle:: 00063 operator != (const TypeHandle &other) const { 00064 return (_index != other._index); 00065 } 00066 00067 //////////////////////////////////////////////////////////////////// 00068 // Function: TypeHandle::Ordering Operator 00069 // Access: Published 00070 // Description: 00071 //////////////////////////////////////////////////////////////////// 00072 INLINE bool TypeHandle:: 00073 operator < (const TypeHandle &other) const { 00074 return (_index < other._index); 00075 } 00076 00077 //////////////////////////////////////////////////////////////////// 00078 // Function: TypeHandle::Ordering Operator 00079 // Access: Published 00080 // Description: 00081 //////////////////////////////////////////////////////////////////// 00082 INLINE bool TypeHandle:: 00083 operator <= (const TypeHandle &other) const { 00084 return (_index <= other._index); 00085 } 00086 00087 //////////////////////////////////////////////////////////////////// 00088 // Function: TypeHandle::Ordering Operator 00089 // Access: Published 00090 // Description: 00091 //////////////////////////////////////////////////////////////////// 00092 INLINE bool TypeHandle:: 00093 operator > (const TypeHandle &other) const { 00094 return (_index > other._index); 00095 } 00096 00097 //////////////////////////////////////////////////////////////////// 00098 // Function: TypeHandle::Ordering Operator 00099 // Access: Published 00100 // Description: 00101 //////////////////////////////////////////////////////////////////// 00102 INLINE bool TypeHandle:: 00103 operator >= (const TypeHandle &other) const { 00104 return (_index >= other._index); 00105 } 00106 00107 //////////////////////////////////////////////////////////////////// 00108 // Function: TypeHandle::compare_to 00109 // Access: Published 00110 // Description: Sorts TypeHandles arbitrarily (according to <, >, 00111 // etc.). Returns a number less than 0 if this type 00112 // sorts before the other one, greater than zero if it 00113 // sorts after, 0 if they are equivalent. 00114 //////////////////////////////////////////////////////////////////// 00115 INLINE int TypeHandle:: 00116 compare_to(const TypeHandle &other) const { 00117 return _index - other._index; 00118 } 00119 00120 //////////////////////////////////////////////////////////////////// 00121 // Function: TypeHandle::get_name 00122 // Access: Published 00123 // Description: Returns the name of the type. 00124 // 00125 // The "object" pointer is an optional pointer to the 00126 // TypedObject class that owns this TypeHandle. It is 00127 // only used in case the TypeHandle is inadvertantly 00128 // undefined. 00129 //////////////////////////////////////////////////////////////////// 00130 INLINE string TypeHandle:: 00131 get_name(TypedObject *object) const { 00132 if ((*this) == TypeHandle::none()) { 00133 return "none"; 00134 } else { 00135 return TypeRegistry::ptr()->get_name(*this, object); 00136 } 00137 } 00138 00139 //////////////////////////////////////////////////////////////////// 00140 // Function: TypeHandle::is_derived_from 00141 // Access: Published 00142 // Description: Returns true if this type is derived from the 00143 // indicated type, false otherwise. 00144 // 00145 // The "object" pointer is an optional pointer to the 00146 // TypedObject class that owns this TypeHandle. It is 00147 // only used in case the TypeHandle is inadvertantly 00148 // undefined. 00149 //////////////////////////////////////////////////////////////////// 00150 INLINE bool TypeHandle:: 00151 is_derived_from(TypeHandle parent, TypedObject *object) const { 00152 return TypeRegistry::ptr()->is_derived_from(*this, parent, object); 00153 } 00154 00155 //////////////////////////////////////////////////////////////////// 00156 // Function: TypeHandle::get_num_parent_classes 00157 // Access: Published 00158 // Description: Returns the number of parent classes that this 00159 // type is known to have. This may then be used to 00160 // index into get_parent_class(). The result will be 0 00161 // if this class does not inherit from any other 00162 // classes, 1 if normal, single inheritance is in 00163 // effect, or greater than one if multiple inheritance 00164 // is in effect. 00165 // 00166 // The "object" pointer is an optional pointer to the 00167 // TypedObject class that owns this TypeHandle. It is 00168 // only used in case the TypeHandle is inadvertantly 00169 // undefined. 00170 //////////////////////////////////////////////////////////////////// 00171 INLINE int TypeHandle:: 00172 get_num_parent_classes(TypedObject *object) const { 00173 return TypeRegistry::ptr()->get_num_parent_classes(*this, object); 00174 } 00175 00176 //////////////////////////////////////////////////////////////////// 00177 // Function: TypeHandle::get_num_parent_classes 00178 // Access: Published 00179 // Description: Returns the nth parent class of this type. The index 00180 // should be in the range 0 <= index < 00181 // get_num_parent_classes(). 00182 //////////////////////////////////////////////////////////////////// 00183 INLINE TypeHandle TypeHandle:: 00184 get_parent_class(int index) const { 00185 return TypeRegistry::ptr()->get_parent_class(*this, index); 00186 } 00187 00188 //////////////////////////////////////////////////////////////////// 00189 // Function: TypeHandle::get_num_child_classes 00190 // Access: Published 00191 // Description: Returns the number of child classes that this 00192 // type is known to have. This may then be used to 00193 // index into get_child_class(). 00194 // 00195 // The "object" pointer is an optional pointer to the 00196 // TypedObject class that owns this TypeHandle. It is 00197 // only used in case the TypeHandle is inadvertantly 00198 // undefined. 00199 //////////////////////////////////////////////////////////////////// 00200 INLINE int TypeHandle:: 00201 get_num_child_classes(TypedObject *object) const { 00202 return TypeRegistry::ptr()->get_num_child_classes(*this, object); 00203 } 00204 00205 //////////////////////////////////////////////////////////////////// 00206 // Function: TypeHandle::get_num_child_classes 00207 // Access: Published 00208 // Description: Returns the nth child class of this type. The index 00209 // should be in the range 0 <= index < 00210 // get_num_child_classes(). 00211 //////////////////////////////////////////////////////////////////// 00212 INLINE TypeHandle TypeHandle:: 00213 get_child_class(int index) const { 00214 return TypeRegistry::ptr()->get_child_class(*this, index); 00215 } 00216 00217 //////////////////////////////////////////////////////////////////// 00218 // Function: TypeHandle::get_parent_towards 00219 // Access: Published 00220 // Description: Returns the parent class that is in a direct line of 00221 // inheritance to the indicated ancestor class. This is 00222 // useful in the presence of multiple inheritance to try 00223 // to determine what properties an unknown type may 00224 // have. 00225 // 00226 // The return value is TypeHandle::none() if the type 00227 // does not inherit from the ancestor. If ancestor is 00228 // the same as this type, the return value is this type. 00229 // 00230 // The "object" pointer is an optional pointer to the 00231 // TypedObject class that owns this TypeHandle. It is 00232 // only used in case the TypeHandle is inadvertantly 00233 // undefined. 00234 //////////////////////////////////////////////////////////////////// 00235 INLINE TypeHandle TypeHandle:: 00236 get_parent_towards(TypeHandle ancestor, TypedObject *object) const { 00237 return TypeRegistry::ptr()->get_parent_towards(*this, ancestor, object); 00238 } 00239 00240 //////////////////////////////////////////////////////////////////// 00241 // Function: TypeHandle::get_index 00242 // Access: Published 00243 // Description: Returns the integer index associated with this 00244 // TypeHandle. Each different TypeHandle will have a 00245 // different index. However, you probably shouldn't be 00246 // using this method; you should just treat the 00247 // TypeHandles as opaque classes. This is provided for 00248 // the convenience of non-C++ scripting languages to 00249 // build a hashtable of TypeHandles. 00250 //////////////////////////////////////////////////////////////////// 00251 INLINE int TypeHandle:: 00252 get_index() const { 00253 return _index; 00254 } 00255 00256 //////////////////////////////////////////////////////////////////// 00257 // Function: TypeHandle::output 00258 // Access: Published 00259 // Description: 00260 //////////////////////////////////////////////////////////////////// 00261 INLINE void TypeHandle:: 00262 output(ostream &out) const { 00263 out << get_name(); 00264 } 00265 00266 //////////////////////////////////////////////////////////////////// 00267 // Function: TypeHandle::none 00268 // Access: Published, Static 00269 // Description: Returns a special zero-valued TypeHandle that is used 00270 // to indicate no type. 00271 //////////////////////////////////////////////////////////////////// 00272 INLINE TypeHandle TypeHandle:: 00273 none() { 00274 return _none; 00275 } 00276