|
|
@@ -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
|