Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

rtti.H

Go to the documentation of this file.
00001 #ifndef RTTI_H_IS_INCLUDED
00002 #define RTTI_H_IS_INCLUDED
00003 
00004 /*****************************************************************
00005  * rtti.H:
00006  *
00007  *      Macros for run-time type identification.
00008  *****************************************************************/
00009 
00010 #define IS(N)          (N == static_name())
00011 #define ISA(O)         ((O) && (O)->is_of_type(static_name()))
00012 #define ISOF(N,PAR)    (IS(N) || PAR::is_of_type(N))
00013 
00014 #define ISOF2(N,PAR1,PAR2) \
00015    (IS(N) || PAR1::is_of_type(N) || PAR2::is_of_type(N))
00016 
00017 #ifdef JOT_AVOID_STATIC_LOCAL_INLINE_VAR
00018 #define STAT_STR_RET str_ptr
00019 #else
00020 #define STAT_STR_RET Cstr_ptr &
00021 #endif
00022 
00023 //
00024 // For base class definitions:
00025 //
00026 #define DEFINE_RTTI_METHODS_BASE(CLASS_NAME, BASECLASS_PTR) \
00027    static  STAT_STR_RET static_name()         { RET_STAT_STR(CLASS_NAME); } \
00028    virtual STAT_STR_RET class_name () const   { return static_name(); } \
00029    virtual int  is_of_type(Cstr_ptr &n)const  { return n == static_name(); } \
00030    static  int  isa       (BASECLASS_PTR o)   { return ISA (o); }
00031 
00032 //
00033 // For derived class definitions:
00034 //
00035 #define DEFINE_RTTI_METHODS2(CLASS_NAME, CLASS_PAR, BASECLASS_PTR) \
00036    static  STAT_STR_RET static_name()         { RET_STAT_STR(CLASS_NAME);} \
00037    virtual STAT_STR_RET class_name () const   { return static_name(); } \
00038    virtual int  is_of_type(Cstr_ptr &n)const  { return ISOF(n,CLASS_PAR);} \
00039    static  int  isa       (BASECLASS_PTR o)   { return ISA (o); }
00040 
00041 #define DEFINE_RTTI_METHODS(CLASS_NAME, CLASS_PAR, BASECLASS_PTR) \
00042         DEFINE_RTTI_METHODS2(CLASS_NAME, CLASS_PAR, BASECLASS_PTR &)
00043 
00044 //
00045 // Handy macro for doing upcasts:
00046 //
00047 #define DEFINE_UPCAST(CLASS_PTR, BASECLASS_PTR) \
00048    static CLASS_PTR upcast(BASECLASS_PTR p) { \
00049       return isa(p) ? (CLASS_PTR)p : 0; \
00050    }
00051 
00052 //
00053 // Same as DEFINE_RTTI_METHODS2, but also defines upcast:
00054 //
00055 #define DEFINE_RTTI_METHODS3(CLASS_NAME, CLASS_PTR, CLASS_PAR, BASECLASS_PTR)\
00056    DEFINE_RTTI_METHODS2(CLASS_NAME, CLASS_PAR, BASECLASS_PTR) \
00057    DEFINE_UPCAST(CLASS_PTR, BASECLASS_PTR)
00058 
00059 #endif // RTTI_H_IS_INCLUDED
00060 
00061 /* end of file rtti.H */

Generated on Mon Sep 18 11:39:33 2006 for jot by  doxygen 1.4.4