contrib/rpl/rgrl/rgrl_macros.h
Go to the documentation of this file.
00001 #ifndef rgrl_macros_h
00002 #define rgrl_macros_h
00003 //:
00004 // \file
00005 
00006 #include <vcl_typeinfo.h>
00007 #include <vcl_iostream.h>
00008 
00009 #if defined(VCL_VC_DOTNET) || defined(VCL_GCC)
00010 # define RGRL_HERE __FUNCTION__
00011 #else
00012 # define RGRL_HERE __FILE__
00013 #endif
00014 
00015 //: Macro to print the debug message in a class member functions
00016 #define DebugMacro(level, x) do \
00017 { if (level == 0 || this->debug_flag() >= level) { \
00018     vcl_cout<< "Debug: "<< RGRL_HERE << " ( line " \
00019             << __LINE__ <<" )\n" << "       "<<x; } \
00020 } while (false)
00021 
00022 //: Macro to print the debug message without preprocessor info
00023 #define DebugMacro_abv(level, x) do \
00024 { if (level == 0 || this->debug_flag() >= level) { vcl_cout<<"       "<<x; } \
00025 } while (false)
00026 
00027 //: Macro to print the warning message in a class member functions
00028 #define WarningMacro(x) do \
00029 {  if ( this->warning() ) { \
00030      vcl_cout<< "WARNING: "<< RGRL_HERE <<" ( line " \
00031              << __LINE__ <<" )\n" \
00032              << "       "<<x; }  \
00033 } while (false)
00034 
00035 //: Macro to print the warning message without class info
00036 #define WarningMacro_abv(x) do \
00037 { if ( this->warning() ) { \
00038     vcl_cout<<<"WARNING: "<<x; } \
00039 } while (false)
00040 
00041 //: Macro to print the debug message in a stand-alone function
00042 #define DebugFuncMacro(flag, level, x) do \
00043 { if (flag >= level) { \
00044     vcl_cout<< "Debug: " << RGRL_HERE << " ( line " \
00045             << __LINE__ <<" )\n" << "       "<<x; } \
00046 } while (false)
00047 
00048 //: Macro to print the debug message in a stand-alone function without preprocessor info
00049 #define DebugFuncMacro_abv(flag, level, x) do \
00050 { if (flag >= level) { vcl_cout<<"       "<<x; } \
00051 } while (false)
00052 
00053 //: Macro to define type-related functions of the class
00054 //
00055 //  Please note, type_id() is static, and therefore
00056 //  non-virtual. Always do class::type_id(), not
00057 //  class_instance.type_id(). If the type_id of a class instance is
00058 //  needed, use RTTI (run-time-type-identification), i.e.
00059 //  typeid(class_instance).
00060 //
00061 //  is_type(.) checks if the instance is a type of \a classname or \a
00062 //  superclass.
00063 #define rgrl_type_macro( classname, superclassname) \
00064      typedef classname       self; \
00065      typedef superclassname  superclass; \
00066      static const vcl_type_info& type_id() \
00067          { return typeid(self); } \
00068      virtual bool is_type( const vcl_type_info& type ) const\
00069          { return (typeid(self) == type)!=0 || this->superclass::is_type(type); }
00070 
00071 #if 0
00072 //: Macro to define the type_id() function of the class
00073 //
00074 //  Please note, type_id() is static, and therefore non-virtual.
00075 //  Always do class::type_id(), not class_instance.type_id().
00076 //  If the type name of a class instance is needed, use RTTI
00077 //  (run-time-type-identification), typeid(class_instance).name().
00078 #define rgrl_type_macro( classname ) \
00079    static const vcl_type_info& type_id() \
00080    {  return typeid(classname); }
00081 
00082 //: Macro to define the is_type(.) function of the class
00083 #define IsTypeMacro( classname ) \
00084    virtual bool is_type( const vcl_type_info& type ) \
00085    {  return typeid(classname) == type || this->superclass::is_type(type); }
00086 #endif // 0
00087 
00088 #endif // end of rgrl_macros.h