ML Reference
MeVis/Foundation/Sources/MLUtilities/mlRuntimeSubClass.h
Go to the documentation of this file.
00001 // **InsertLicense** code
00002 //-------------------------------------------------------------------------
00008 
00013 // This file defines a set of macros which are inserted in
00014 // the header- and source files of the image processing modules
00015 // (e.g., class Module) or in in the library
00016 // initialization.
00017 //-------------------------------------------------------------------------
00018 #ifndef __mlRuntimeSubClass_H
00019 #define __mlRuntimeSubClass_H
00020 
00021 // Include normal ML runtime system and error handling stuff.
00022 #ifndef __mlRuntime_H
00023 #include "mlRuntime.h"
00024 #endif
00025 #ifndef __mlErrorOutput_H
00026 #include "mlErrorOutput.h"
00027 #endif
00028 #ifndef __mlErrorOutputInfos_H
00029 #include "mlErrorOutputInfos.h"
00030 #endif
00031 
00032 
00033 //--------------------------------------------------------------
00041 //--------------------------------------------------------------
00042 #define ML_BASE_IS_A(base,type) ((base && base->getTypeId()) ? base->getTypeId()->isDerivedFrom(type::getClassTypeId()) : false)
00043 
00044 
00045 #ifdef ML_DEPRECATED
00046 
00047 
00048 
00049 
00050 
00051   #define BASE_IS_A(base, type)   ML_BASE_IS_A(base, type)
00052 
00053 #endif // ML_DEPRECATED
00054 
00055 //--------------------------------------------------------------
00057 //--------------------------------------------------------------
00058 #ifndef ML_EMPTY_PARAM
00059 #define ML_EMPTY_PARAM
00060 #endif
00061 
00062 
00063 //--------------------------------------------------------------
00070 //--------------------------------------------------------------
00071 #define ML_CLASS_HEADER_EXPORTED(className, EXP_SYM)              \
00072 public:                                                           \
00073   /* Creates a new runtime type from class name and insert      */\
00074   /* it into the runtime type system.                           */\
00075   /* A \p classPrefix (a null terminated string) can be passed  */\
00076   /* which then will be prefixed to the class name before       */\
00077   /* creating the runtime type name from it.                    */\
00078   /* \p nameReplacement is also a null terminated string which  */\
00079   /* will be used as replacement of the class name if passed as */\
00080   /* non NULL. It will still be prefixed if a prefix is passed. */\
00081   EXP_SYM static void initClass(const char* classPrefix=NULL,     \
00082                                 const char* nameReplacement=NULL);\
00083                                                                   \
00084   /* Removes the class type from the runtime type system. */      \
00085   EXP_SYM static void destroyClass();                             \
00086                                                                   \
00087   /* Returns the runtime type of this class. */                   \
00088   EXP_SYM static  const RuntimeType* getClassTypeId();            \
00089                                                                   \
00090   /* Returns the (evt. overloaded) runtime type of this object.*/ \
00091   EXP_SYM virtual const RuntimeType* getTypeId() const;           \
00092                                                                   \
00093   /* Returns the null terminated type name of this runtime type*/ \
00094   /* or the string "<Name of Uninitialized Type>" if the type  */ \
00095   /* is still uninitialized. That case will also cause an ML   */ \
00096   /* error message with code ML_TYPE_NOT_REGISTERED.           */ \
00097   EXP_SYM virtual const char* getTypeIdName() const;              \
00098                                                                   \
00099   /* Creates an instance of this class type. */                   \
00100   EXP_SYM static void* createCB() ML_RETURN_VALUE_SHOULD_BE_USED; \
00101                                                                   \
00102 private:                                                          \
00103   /* Pointer to the runtime type of this class which is stored */ \
00104   /* in the runtime type system.                               */ \
00105   static const RuntimeType* _classType;
00106 
00107 
00108 //--------------------------------------------------------------
00111 //--------------------------------------------------------------
00112 #define ML_CLASS_HEADER(className)                                \
00113   ML_CLASS_HEADER_EXPORTED(className, ML_EMPTY_PARAM)
00114 
00115 
00116 //--------------------------------------------------------------
00122 //--------------------------------------------------------------
00123 #define ML_CLASS_SOURCE(className,parentName)                     \
00124                                                                   \
00125 /* Pointer to the runtime type of this class which is stored */   \
00126 /* in the runtime type system. Types should be initialized   */   \
00127 /* to NULL since Runtime::badType() could be initialized     */   \
00128 /* to NULL later than the type itself.                       */   \
00129 const RuntimeType* className::_classType = NULL;                  \
00130                                                                   \
00131 /* Creates a new runtime type from class name and insert      */  \
00132 /* it into the runtime type system.                           */  \
00133 /* A \p classPrefix (a null terminated string) can be passed  */  \
00134 /* which then will be prefixed to the class name before       */  \
00135 /* creating the runtime type name from it.                    */  \
00136 /* \p nameReplacement is also a null terminated string which  */  \
00137 /* will be used as replacement of the class name if passed as */  \
00138 /* non NULL. It will still be prefixed if a prefix is passed. */  \
00139 void className::initClass(const char* classPrefix,                \
00140                           const char* nameReplacement)            \
00141 {                                                                 \
00142     ML_TRACE_IN( #className "::initClass( )" );                   \
00143                                                                   \
00144     _classType = Runtime::initType(_classType,                    \
00145                                  #parentName,                     \
00146                                  classPrefix,                     \
00147                                  nameReplacement ?                \
00148                                    nameReplacement :              \
00149                                    #className,                    \
00150                                  ML_UTILS_NAMESPACE::className::createCB);\
00151 }                                                                 \
00152 /* Removes the class type from the runtime type system. */        \
00153 void className::destroyClass()                                    \
00154 {                                                                 \
00155   Runtime::destroyType(#className);                               \
00156 }                                                                 \
00157                                                                   \
00158 /* Returns the runtime type of this class. */                     \
00159 const RuntimeType* className::getClassTypeId()                    \
00160 {                                                                 \
00161   return _classType;                                              \
00162 }                                                                 \
00163                                                                   \
00164 /* Returns the (evt. overloaded) runtime type of this object.*/   \
00165 const RuntimeType* className::getTypeId() const                   \
00166 {                                                                 \
00167   return _classType;                                              \
00168 }                                                                 \
00169                                                                   \
00170 /* Returns the null terminated type name of this runtime type */  \
00171 /* or the string "<Name of Uninitialized Type>" if the type   */  \
00172 /* is still uninitialized. That case will also cause an ML    */  \
00173 /* error message with code ML_TYPE_NOT_REGISTERED.            */  \
00174 const char* className::getTypeIdName() const                      \
00175 {                                                                 \
00176   ML_TRACE_IN( #className "::getTypeIdName( )" );                 \
00177                                                                   \
00178   /* OR with MLAlwaysFalse to avoid unreachable code warnings.*/  \
00179   if (_classType || MLAlwaysFalse){                               \
00180     return _classType->getName();                                 \
00181   }                                                               \
00182   else{                                                           \
00183     ML_PRINT_ERROR(#className,                                    \
00184                    ML_TYPE_NOT_REGISTERED,                        \
00185                    "Returning '<Name of Uninitialized Type>'"     \
00186                    "instead of real type name since type is "     \
00187                    "not initialized. Did you forget to call '"    \
00188                    #className                                     \
00189                    "::initClass' during library initialization?");\
00190     return "<Name of Uninitialized Type>";                        \
00191   }                                                               \
00192 }                                                                 \
00193                                                                   \
00194 /* Creates an instance of this class type. */                     \
00195 void* className::createCB()                                       \
00196 {                                                                 \
00197   return new className();                                         \
00198 }                                                                 \
00199 
00200 
00201 //--------------------------------------------------------------
00206 //--------------------------------------------------------------
00207 #define ML_ROOT_CLASS_SOURCE(className)                           \
00208   ML_CLASS_SOURCE(className,)
00209 
00210 
00211 //--------------------------------------------------------------
00216 //--------------------------------------------------------------
00217 #define ML_ABSTRACT_CLASS_HEADER_EXPORTED(className, EXP_SYM)     \
00218 public:                                                           \
00219   /* Creates a new runtime type from class name and insert      */\
00220   /* it into the runtime type system.                           */\
00221   /* A \p classPrefix (a null terminated string) can be passed  */\
00222   /* which then will be prefixed to the class name before       */\
00223   /* creating the runtime type name from it.                    */\
00224   /* \p nameReplacement is also a null terminated string which  */\
00225   /* will be used as replacement of the class name if passed as */\
00226   /* non NULL. It will still be prefixed if a prefix is passed. */\
00227   EXP_SYM static void initClass(const char* classPrefix=NULL,     \
00228                                 const char* nameReplacement=NULL);\
00229                                                                   \
00230   /* Removes the class type from the runtime type system. */      \
00231   EXP_SYM static void destroyClass();                             \
00232                                                                   \
00233   /* Returns the runtime type of this class. */                   \
00234   EXP_SYM static  const RuntimeType* getClassTypeId();            \
00235                                                                   \
00236   /* Returns the (evt. overloaded) runtime type of this object.*/ \
00237   EXP_SYM virtual const RuntimeType* getTypeId() const;           \
00238                                                                   \
00239   /* Returns the null terminated type name of this runtime type*/ \
00240   /* or the string "<Name of Uninitialized Type>" if the type  */ \
00241   /* is still uninitialized. That case will also cause an ML   */ \
00242   /* error message with code ML_TYPE_NOT_REGISTERED.           */ \
00243   EXP_SYM virtual const char* getTypeIdName() const;              \
00244                                                                   \
00245 private:                                                          \
00246   static const RuntimeType* _classType;                           \
00247 
00248 
00249 //--------------------------------------------------------------
00253 //--------------------------------------------------------------
00254 #define ML_ABSTRACT_CLASS_HEADER(className)                       \
00255   ML_ABSTRACT_CLASS_HEADER_EXPORTED(className, ML_EMPTY_PARAM)
00256 
00257 
00258 //--------------------------------------------------------------
00264 //--------------------------------------------------------------
00265 #define ML_ABSTRACT_CLASS_SOURCE(className,parentName)            \
00266                                                                   \
00267 /* Pointer to the runtime type of this class which is stored */   \
00268 /* in the runtime type system. For uninitialized typed both  */   \
00269 /* is ok Runtime::badType() or NULL.                         */   \
00270 const RuntimeType* className::_classType = NULL;                  \
00271                                                                   \
00272 /* Creates a new runtime type from class name and insert      */  \
00273 /* it into the runtime type system.                           */  \
00274 /* A \p classPrefix (a null terminated string) can be passed  */  \
00275 /* which then will be prefixed to the class name before       */  \
00276 /* creating the runtime type name from it.                    */  \
00277 /* \p nameReplacement is also a null terminated string which  */  \
00278 /* will be used as replacement of the class name if passed as */  \
00279 /* non NULL. It will still be prefixed if a prefix is passed. */  \
00280 void className::initClass(const char* classPrefix,                \
00281                           const char* nameReplacement)            \
00282 {                                                                 \
00283     ML_TRACE_IN( #className "::initClass( )" );                   \
00284                                                                   \
00285     _classType = Runtime::initType(_classType,                    \
00286                                  #parentName,                     \
00287                                  classPrefix,                     \
00288                                  nameReplacement ?                \
00289                                    nameReplacement :              \
00290                                    #className,                    \
00291                                  NULL);                           \
00292 }                                                                 \
00293 /* Removes the class type from the runtime type system. */        \
00294 void className::destroyClass()                                    \
00295 {                                                                 \
00296   Runtime::destroyType(#className);                               \
00297 }                                                                 \
00298                                                                   \
00299 /* Returns the runtime type of this class. */                     \
00300 const RuntimeType* className::getClassTypeId()                    \
00301 {                                                                 \
00302   return _classType;                                              \
00303 }                                                                 \
00304                                                                   \
00305 /* Returns the null terminated type name of this runtime type */  \
00306 /* or the string "<Name of Uninitialized Type>" if the type   */  \
00307 /* is still uninitialized. That case will also cause an ML    */  \
00308 /* error message with code ML_TYPE_NOT_REGISTERED.            */  \
00309 const char* className::getTypeIdName() const                      \
00310 {                                                                 \
00311   ML_TRACE_IN( #className "::getTypeIdName( )" );                 \
00312                                                                   \
00313   /* OR with MLAlwaysFalse to avoid unreachable code warnings.*/  \
00314   if (_classType || MLAlwaysFalse){                               \
00315     return _classType->getName();                                 \
00316   }                                                               \
00317   else{                                                           \
00318     ML_PRINT_ERROR(#className,                                    \
00319                    ML_TYPE_NOT_REGISTERED,                        \
00320                    "Returning '<Name of Uninitialized Type>'"     \
00321                    "instead of real type name since type is "     \
00322                    "not initialized. Did you forget to call '"    \
00323                    #className                                     \
00324                    "::initClass' during library initialization?");\
00325     return "<Name of Uninitialized Type>";                        \
00326   }                                                               \
00327 }                                                                 \
00328                                                                   \
00329 /* Returns the (evt. overloaded) runtime type of this object. */  \
00330 const RuntimeType* className::getTypeId() const                   \
00331 {                                                                 \
00332   return _classType;                                              \
00333 }                                                                 \
00334 
00335 
00336 //--------------------------------------------------------------
00341 //--------------------------------------------------------------
00342 #define ML_ABSTRACT_ROOT_CLASS_SOURCE(className)                  \
00343   ML_ABSTRACT_CLASS_SOURCE(className,)
00344 
00345 
00346 //--------------------------------------------------------------
00352 //--------------------------------------------------------------
00353 #define ML_MODULE_CLASS_HEADER(className)                         \
00354   /* Implement normal class header stuff. */                      \
00355   ML_CLASS_HEADER(className)                                      \
00356                                                                   \
00357   /* Implement private copy constructor. */                       \
00358   private: className(const className&);                           \
00359                                                                   \
00360   /* Implement private assignment operator. */                    \
00361   private: className& operator=(const className&);                \
00362 
00363 
00364 //--------------------------------------------------------------
00371 //--------------------------------------------------------------
00372 #define ML_MODULE_CLASS_SOURCE(className, parentName)             \
00373   /* Implement normal class source stuff. */                      \
00374   ML_CLASS_SOURCE(className, parentName)
00375   
00376 //--------------------------------------------------------------
00382 //--------------------------------------------------------------
00383 #define ML_ABSTRACT_MODULE_CLASS_HEADER(className)                \
00384   /* Implement normal class header stuff. */                      \
00385   ML_ABSTRACT_CLASS_HEADER(className)                             \
00386                                                                   \
00387   /* Implement private copy constructor. */                       \
00388   private: className(const className&);                           \
00389                                                                   \
00390   /* Implement private assignment operator. */                    \
00391   private: className& operator=(const className&);                \
00392 
00393 
00394 //--------------------------------------------------------------
00401 //--------------------------------------------------------------
00402 #define ML_ABSTRACT_MODULE_CLASS_SOURCE(className, parentName)    \
00403   /* Implement normal class source stuff. */                      \
00404   ML_ABSTRACT_CLASS_SOURCE(className, parentName)
00405 
00406 
00407 //--------------------------------------------------------------
00411 //--------------------------------------------------------------
00412 #define ML_MODULE_CLASS_SOURCE_EXT(className, parentName, superClassConstructs) \
00413   /* Implement normal class source stuff. */                      \
00414   ML_CLASS_SOURCE(className, parentName)
00415 
00416 
00417 //--------------------------------------------------------------
00421 //--------------------------------------------------------------
00422 #define ML_ABSTRACT_MODULE_CLASS_SOURCE_EXT(className, parentName, superClassConstructs) \
00423   /* Implement normal class source stuff. */                      \
00424   ML_ABSTRACT_CLASS_SOURCE(className, parentName)
00425 
00426 
00427 #ifdef ML_DEPRECATED
00428 
00430 
00431 
00434 #define ML_BASEOP_CLASS_HEADER(className) \
00435         ML_MODULE_CLASS_HEADER(className)
00436 
00437 
00438 #define ML_BASEOP_CLASS_SOURCE(className, parentName) \
00439         ML_MODULE_CLASS_SOURCE(className, parentName)
00440 
00443 #define ML_ABSTRACT_BASEOP_CLASS_HEADER(className) \
00444         ML_ABSTRACT_MODULE_CLASS_HEADER(className)
00445 
00448 #define ML_ABSTRACT_BASEOP_CLASS_SOURCE(className, parentName) \
00449         ML_ABSTRACT_MODULE_CLASS_SOURCE(className, parentName)
00450 
00453 #define ML_BASEOP_CLASS_SOURCE_EXT(className, parentName, superClassConstructs) \
00454         ML_CLASS_SOURCE(className, parentName)
00455 
00458 #define ML_ABSTRACT_BASEOP_CLASS_SOURCE_EXT(className, parentName, superClassConstructs) \
00459         ML_ABSTRACT_CLASS_SOURCE(className, parentName)
00460 
00462 
00463 #endif // ML_DEPRECATED
00464 
00465 
00466 #endif  // __mlRuntimeSubClass_H
00467