Commit 463e466b authored by Brad King's avatar Brad King

ENH: Added safe downcast support (without RTTI) to cmCommand and its subclasses.

parent d31ce244
......@@ -54,6 +54,8 @@ public:
return
"ABSTRACT_FILES(file1 file2 ..)";
}
cmTypeMacro(cmAbstractFilesCommand, cmCommand);
};
......
......@@ -65,6 +65,8 @@ public:
return
"ADD_TARGET(Name \"command to run\")";
}
cmTypeMacro(cmAddTargetCommand, cmCommand);
};
#endif
......@@ -67,6 +67,8 @@ public:
return
"AUX_SOURCE_DIRECTORY(dir)";
}
cmTypeMacro(cmAuxSourceDirectoryCommand, cmCommand);
};
......
......@@ -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
......@@ -63,6 +63,8 @@ public:
return
"EXECUTABLES(file1 file2 ...)";
}
cmTypeMacro(cmExecutablesCommand, cmCommand);
};
......
......@@ -70,6 +70,8 @@ public:
return
"FIND_INCLUDE(DEFINE try1 try2 ...)";
}
cmTypeMacro(cmFindIncludeCommand, cmCommand);
};
......
......@@ -71,6 +71,8 @@ public:
return
"FIND_LIBRARY(DEFINE libraryName path1 path2 path3...)";
}
cmTypeMacro(cmFindLibraryCommand, cmCommand);
};
......
......@@ -71,6 +71,8 @@ public:
return
"FIND_PROGRAM(NAME executable1 executable2 ...)";
}
cmTypeMacro(cmFindProgramCommand, cmCommand);
};
......
......@@ -69,6 +69,8 @@ public:
return
"INCLUDE_DIRECTORIES(dir1 dir2 ...)";
}
cmTypeMacro(cmIncludeDirectoryCommand, cmCommand);
};
......
......@@ -64,6 +64,8 @@ public:
return
"LIBRARY(libraryname)";
}
cmTypeMacro(cmLibraryCommand, cmCommand);
};
......
......@@ -74,6 +74,8 @@ public:
"The directories can use built in definitions like \n"
"CMAKE_BINARY_DIR and CMAKE_SOURCE_DIR.";
}
cmTypeMacro(cmLinkDirectoriesCommand, cmCommand);
};
......
......@@ -76,6 +76,8 @@ public:
"down to all other commands. The library name should be\n"
"the same as the name used in the LIBRARY(library) command.";
}
cmTypeMacro(cmLinkLibrariesCommand, cmCommand);
};
......
......@@ -74,6 +74,8 @@ public:
return
"PROJECT(projectname) Sets the name of the Microsoft workspace .dsw file. Does nothing on UNIX currently\n";
}
cmTypeMacro(cmProjectCommand, cmCommand);
};
......
......@@ -68,6 +68,8 @@ public:
return
"SOURCE_FILES(file1 file2 ...)";
}
cmTypeMacro(cmSourceFilesCommand, cmCommand);
};
......
......@@ -67,6 +67,8 @@ public:
return
"SOURCE_FILES_REQUIRE(var1 var2 ... SOURCES_BEGIN file1 file2 ...)";
}
cmTypeMacro(cmSourceFilesRequireCommand, cmCommand);
};
......
......@@ -67,6 +67,8 @@ public:
"This will cause any CMakeLists.txt files in the sub directories\n"
"to be processed by CMake.";
}
cmTypeMacro(cmSubdirCommand, cmCommand);
};
......
......@@ -67,6 +67,8 @@ public:
return
"TESTS(file1 file2 ...)";
}
cmTypeMacro(cmTestsCommand, cmCommand);
};
......
......@@ -75,6 +75,8 @@ public:
"UNIX_DEFINES(-DFOO -DBAR)\n"
"Add -D flags to the command line for Unix only.";
}
cmTypeMacro(cmUnixDefinesCommand, cmCommand);
};
......
......@@ -74,6 +74,8 @@ public:
return
"UNIX_LIBRARIES(library -lm ...)";
}
cmTypeMacro(cmUnixLibrariesCommand, cmCommand);
};
......
......@@ -75,6 +75,8 @@ public:
"WIN32_DEFINES(-DFOO -DBAR ...)\n"
"Add -D define flags to command line for Win32 environments.";
}
cmTypeMacro(cmWin32DefinesCommand, cmCommand);
};
......
......@@ -74,6 +74,8 @@ public:
return
"WIN32_LIBRARIES(library -lm ...)";
}
cmTypeMacro(cmWin32LibrariesCommand, cmCommand);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment