Panda3D

register_type.h

00001 // Filename: register_type.h
00002 // Created by:  drose (06Aug01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef REGISTER_TYPE_H
00016 #define REGISTER_TYPE_H
00017 
00018 #include "dtoolbase.h"
00019 
00020 #include "typeHandle.h"
00021 #include "typeRegistry.h"
00022 
00023 ////////////////////////////////////////////////////////////////////
00024 //     Function: register_type
00025 //  Description: This inline function is just a convenient way to call
00026 //               TypeRegistry::register_type(), along with zero to four
00027 //               record_derivation()s.  If for some reason you have a
00028 //               class that has more than four base classes (you're
00029 //               insane!), then you will need to call Register() and
00030 //               record_derivation() yourself.
00031 ////////////////////////////////////////////////////////////////////
00032 INLINE void
00033 register_type(TypeHandle &type_handle, const string &name);
00034 
00035 INLINE void
00036 register_type(TypeHandle &type_handle, const string &name,
00037               TypeHandle parent1);
00038 
00039 INLINE void
00040 register_type(TypeHandle &type_handle, const string &name,
00041               TypeHandle parent1, TypeHandle parent2);
00042 
00043 INLINE void
00044 register_type(TypeHandle &type_handle, const string &name,
00045               TypeHandle parent1, TypeHandle parent2,
00046               TypeHandle parent3);
00047 
00048 INLINE void
00049 register_type(TypeHandle &type_handle, const string &name,
00050               TypeHandle parent1, TypeHandle parent2,
00051               TypeHandle parent3, TypeHandle parent4);
00052 
00053 
00054 ////////////////////////////////////////////////////////////////////
00055 //     Function: register_dynamic_type
00056 //  Description: This is essentially similar to register_type(),
00057 //               except that it doesn't store a reference to any
00058 //               TypeHandle passed in and it therefore doesn't
00059 //               complain if the type is registered more than once to
00060 //               different TypeHandle reference.
00061 ////////////////////////////////////////////////////////////////////
00062 INLINE TypeHandle
00063 register_dynamic_type(const string &name);
00064 
00065 INLINE TypeHandle
00066 register_dynamic_type(const string &name, TypeHandle parent1);
00067 
00068 INLINE TypeHandle
00069 register_dynamic_type(const string &name,
00070                       TypeHandle parent1, TypeHandle parent2);
00071 
00072 INLINE TypeHandle
00073 register_dynamic_type(const string &name,
00074                       TypeHandle parent1, TypeHandle parent2,
00075                       TypeHandle parent3);
00076 
00077 INLINE TypeHandle
00078 register_dynamic_type(const string &name,
00079                       TypeHandle parent1, TypeHandle parent2,
00080                       TypeHandle parent3, TypeHandle parent4);
00081 
00082 
00083 // A few system-wide TypeHandles are defined for some basic types.
00084 extern TypeHandle EXPCL_DTOOL long_type_handle;
00085 extern TypeHandle EXPCL_DTOOL int_type_handle;
00086 extern TypeHandle EXPCL_DTOOL uint_type_handle;
00087 extern TypeHandle EXPCL_DTOOL short_type_handle;
00088 extern TypeHandle EXPCL_DTOOL ushort_type_handle;
00089 extern TypeHandle EXPCL_DTOOL char_type_handle;
00090 extern TypeHandle EXPCL_DTOOL uchar_type_handle;
00091 extern TypeHandle EXPCL_DTOOL bool_type_handle;
00092 extern TypeHandle EXPCL_DTOOL double_type_handle;
00093 extern TypeHandle EXPCL_DTOOL float_type_handle;
00094 extern TypeHandle EXPCL_DTOOL string_type_handle;
00095 
00096 extern TypeHandle long_p_type_handle;
00097 extern TypeHandle int_p_type_handle;
00098 extern TypeHandle short_p_type_handle;
00099 extern TypeHandle char_p_type_handle;
00100 extern TypeHandle bool_p_type_handle;
00101 extern TypeHandle double_p_type_handle;
00102 extern TypeHandle float_p_type_handle;
00103 extern TypeHandle void_p_type_handle;
00104 
00105 extern TypeHandle EXPCL_DTOOL pvector_type_handle;
00106 extern TypeHandle EXPCL_DTOOL ov_set_type_handle;
00107 extern TypeHandle EXPCL_DTOOL pdeque_type_handle;
00108 extern TypeHandle EXPCL_DTOOL plist_type_handle;
00109 extern TypeHandle EXPCL_DTOOL pmap_type_handle;
00110 extern TypeHandle EXPCL_DTOOL pset_type_handle;
00111 
00112 void EXPCL_DTOOL init_system_type_handles();
00113 
00114 // The following template function and its specializations will return
00115 // a TypeHandle for any type in the world, from a pointer to that
00116 // type.
00117 
00118 template<class T>
00119 INLINE TypeHandle _get_type_handle(const T *) {
00120   return T::get_class_type();
00121 }
00122 
00123 template<>
00124 INLINE TypeHandle _get_type_handle(const long *) {
00125   return long_type_handle;
00126 }
00127 
00128 template<>
00129 INLINE TypeHandle _get_type_handle(const int *) {
00130   return int_type_handle;
00131 }
00132 
00133 template<>
00134 INLINE TypeHandle _get_type_handle(const unsigned int *) {
00135   return uint_type_handle;
00136 }
00137 
00138 template<>
00139 INLINE TypeHandle _get_type_handle(const short *) {
00140   return short_type_handle;
00141 }
00142 
00143 template<>
00144 INLINE TypeHandle _get_type_handle(const unsigned short *) {
00145   return ushort_type_handle;
00146 }
00147 
00148 template<>
00149 INLINE TypeHandle _get_type_handle(const char *) {
00150   return char_type_handle;
00151 }
00152 
00153 template<>
00154 INLINE TypeHandle _get_type_handle(const unsigned char *) {
00155   return uchar_type_handle;
00156 }
00157 
00158 template<>
00159 INLINE TypeHandle _get_type_handle(const bool *) {
00160   return bool_type_handle;
00161 }
00162 
00163 template<>
00164 INLINE TypeHandle _get_type_handle(const double *) {
00165   return double_type_handle;
00166 }
00167 
00168 template<>
00169 INLINE TypeHandle _get_type_handle(const float *) {
00170   return float_type_handle;
00171 }
00172 
00173 template<>
00174 INLINE TypeHandle _get_type_handle(const string *) {
00175   return string_type_handle;
00176 }
00177 
00178 template<>
00179 INLINE TypeHandle _get_type_handle(const long * const *) {
00180   return long_p_type_handle;
00181 }
00182 
00183 template<>
00184 INLINE TypeHandle _get_type_handle(const int * const *) {
00185   return int_p_type_handle;
00186 }
00187 
00188 template<>
00189 INLINE TypeHandle _get_type_handle(const short * const *) {
00190   return short_p_type_handle;
00191 }
00192 
00193 template<>
00194 INLINE TypeHandle _get_type_handle(const char * const *) {
00195   return char_p_type_handle;
00196 }
00197 
00198 template<>
00199 INLINE TypeHandle _get_type_handle(const bool * const *) {
00200   return bool_p_type_handle;
00201 }
00202 
00203 template<>
00204 INLINE TypeHandle _get_type_handle(const double * const *) {
00205   return double_p_type_handle;
00206 }
00207 
00208 template<>
00209 INLINE TypeHandle _get_type_handle(const float * const *) {
00210   return float_p_type_handle;
00211 }
00212 
00213 template<>
00214 INLINE TypeHandle _get_type_handle(const void * const *) {
00215   return void_p_type_handle;
00216 }
00217 
00218 
00219 // The macro get_type_handle(type) is defined to make getting the type
00220 // handle associated with a particular type a bit cleaner.
00221 #define get_type_handle(type) _get_type_handle((const type *)0)
00222 
00223 
00224 // The following template function and its specializations can be used
00225 // to call init() on any unknown type.  Handy for use within a
00226 // template class.
00227 
00228 template<class T>
00229 INLINE void _do_init_type(const T *) {
00230   T::init_type();
00231 }
00232 
00233 template<>
00234 INLINE void _do_init_type(const long *) {
00235   init_system_type_handles();
00236 }
00237 
00238 template<>
00239 INLINE void _do_init_type(const int *) {
00240   init_system_type_handles();
00241 }
00242 
00243 template<>
00244 INLINE void _do_init_type(const short *) {
00245   init_system_type_handles();
00246 }
00247 
00248 template<>
00249 INLINE void _do_init_type(const char *) {
00250   init_system_type_handles();
00251 }
00252 
00253 template<>
00254 INLINE void _do_init_type(const bool *) {
00255   init_system_type_handles();
00256 }
00257 
00258 template<>
00259 INLINE void _do_init_type(const double *) {
00260   init_system_type_handles();
00261 }
00262 
00263 template<>
00264 INLINE void _do_init_type(const float *) {
00265   init_system_type_handles();
00266 }
00267 
00268 template<>
00269 INLINE void _do_init_type(const long * const *) {
00270   init_system_type_handles();
00271 }
00272 
00273 template<>
00274 INLINE void _do_init_type(const int * const *) {
00275   init_system_type_handles();
00276 }
00277 
00278 template<>
00279 INLINE void _do_init_type(const short * const *) {
00280   init_system_type_handles();
00281 }
00282 
00283 template<>
00284 INLINE void _do_init_type(const char * const *) {
00285   init_system_type_handles();
00286 }
00287 
00288 template<>
00289 INLINE void _do_init_type(const bool * const *) {
00290   init_system_type_handles();
00291 }
00292 
00293 template<>
00294 INLINE void _do_init_type(const double * const *) {
00295   init_system_type_handles();
00296 }
00297 
00298 template<>
00299 INLINE void _do_init_type(const float * const *) {
00300   init_system_type_handles();
00301 }
00302 
00303 template<>
00304 INLINE void _do_init_type(const void * const *) {
00305   init_system_type_handles();
00306 }
00307 
00308 #define do_init_type(type) _do_init_type((const type *)0)
00309 
00310 #include "register_type.I"
00311 
00312 #endif
 All Classes Functions Variables Enumerations