diff options
author | Brad King <brad.king@kitware.com> | 2001-02-26 17:07:53 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2001-02-26 17:07:53 (GMT) |
commit | 463e466be3efaada0c64beb120b98432e643e480 (patch) | |
tree | 46d1c660e37b4617bdab432c2abbea5fb699509f /Source/cmCommand.h | |
parent | d31ce244136205bc006967090ddd4d6fdde5b3cb (diff) | |
download | CMake-463e466be3efaada0c64beb120b98432e643e480.zip CMake-463e466be3efaada0c64beb120b98432e643e480.tar.gz CMake-463e466be3efaada0c64beb120b98432e643e480.tar.bz2 |
ENH: Added safe downcast support (without RTTI) to cmCommand and its subclasses.
Diffstat (limited to 'Source/cmCommand.h')
-rw-r--r-- | Source/cmCommand.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Source/cmCommand.h b/Source/cmCommand.h index aefd757..55841c4 100644 --- a/Source/cmCommand.h +++ b/Source/cmCommand.h @@ -122,6 +122,19 @@ public: const char* GetError() {return m_Error.c_str();} + /** + * Returns true if this class is the given class, or a subclass of it. + */ + static bool IsTypeOf(const char *type) + { return !strcmp("cmCommand", type); } + + /** + * Returns true if this object is an instance of the given class or + * a subclass of it. + */ + virtual bool IsA(const char *type) + { return cmCommand::IsTypeOf(type); } + protected: void SetError(const char* e) { @@ -136,4 +149,28 @@ private: std::string m_Error; }; +// All subclasses of cmCommand should invoke this macro. +#define cmTypeMacro(thisClass,superclass) \ +static bool IsTypeOf(const char *type) \ +{ \ + if ( !strcmp(#thisClass,type) ) \ + { \ + return true; \ + } \ + return superclass::IsTypeOf(type); \ +} \ +virtual bool IsA(const char *type) \ +{ \ + return thisClass::IsTypeOf(type); \ +} \ +static thisClass* SafeDownCast(cmCommand *c) \ +{ \ + if ( c && c->IsA(#thisClass) ) \ + { \ + return (thisClass *)c; \ + } \ + return 0;\ +} + + #endif |