summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2001-02-26 12:07:53 -0500
committerBrad King <brad.king@kitware.com>2001-02-26 12:07:53 -0500
commit463e466be3efaada0c64beb120b98432e643e480 (patch)
tree46d1c660e37b4617bdab432c2abbea5fb699509f
parentd31ce244136205bc006967090ddd4d6fdde5b3cb (diff)
downloadcmake-463e466be3efaada0c64beb120b98432e643e480.tar.gz
ENH: Added safe downcast support (without RTTI) to cmCommand and its subclasses.
-rw-r--r--Source/cmAbstractFilesCommand.h2
-rw-r--r--Source/cmAddTargetCommand.h2
-rw-r--r--Source/cmAuxSourceDirectoryCommand.h2
-rw-r--r--Source/cmCommand.h37
-rw-r--r--Source/cmExecutablesCommand.h2
-rw-r--r--Source/cmFindIncludeCommand.h2
-rw-r--r--Source/cmFindLibraryCommand.h2
-rw-r--r--Source/cmFindProgramCommand.h2
-rw-r--r--Source/cmIncludeDirectoryCommand.h2
-rw-r--r--Source/cmLibraryCommand.h2
-rw-r--r--Source/cmLinkDirectoriesCommand.h2
-rw-r--r--Source/cmLinkLibrariesCommand.h2
-rw-r--r--Source/cmProjectCommand.h2
-rw-r--r--Source/cmSourceFilesCommand.h2
-rw-r--r--Source/cmSourceFilesRequireCommand.h2
-rw-r--r--Source/cmSubdirCommand.h2
-rw-r--r--Source/cmTestsCommand.h2
-rw-r--r--Source/cmUnixDefinesCommand.h2
-rw-r--r--Source/cmUnixLibrariesCommand.h2
-rw-r--r--Source/cmWin32DefinesCommand.h2
-rw-r--r--Source/cmWin32LibrariesCommand.h2
21 files changed, 77 insertions, 0 deletions
diff --git a/Source/cmAbstractFilesCommand.h b/Source/cmAbstractFilesCommand.h
index 6e7f73e49d..a40cce891a 100644
--- a/Source/cmAbstractFilesCommand.h
+++ b/Source/cmAbstractFilesCommand.h
@@ -54,6 +54,8 @@ public:
return
"ABSTRACT_FILES(file1 file2 ..)";
}
+
+ cmTypeMacro(cmAbstractFilesCommand, cmCommand);
};
diff --git a/Source/cmAddTargetCommand.h b/Source/cmAddTargetCommand.h
index 01653e6258..fd0aeab685 100644
--- a/Source/cmAddTargetCommand.h
+++ b/Source/cmAddTargetCommand.h
@@ -65,6 +65,8 @@ public:
return
"ADD_TARGET(Name \"command to run\")";
}
+
+ cmTypeMacro(cmAddTargetCommand, cmCommand);
};
#endif
diff --git a/Source/cmAuxSourceDirectoryCommand.h b/Source/cmAuxSourceDirectoryCommand.h
index c830a769aa..905d63ab94 100644
--- a/Source/cmAuxSourceDirectoryCommand.h
+++ b/Source/cmAuxSourceDirectoryCommand.h
@@ -67,6 +67,8 @@ public:
return
"AUX_SOURCE_DIRECTORY(dir)";
}
+
+ cmTypeMacro(cmAuxSourceDirectoryCommand, cmCommand);
};
diff --git a/Source/cmCommand.h b/Source/cmCommand.h
index aefd757bd0..55841c4329 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
diff --git a/Source/cmExecutablesCommand.h b/Source/cmExecutablesCommand.h
index c420a878ce..48b013ffa0 100644
--- a/Source/cmExecutablesCommand.h
+++ b/Source/cmExecutablesCommand.h
@@ -63,6 +63,8 @@ public:
return
"EXECUTABLES(file1 file2 ...)";
}
+
+ cmTypeMacro(cmExecutablesCommand, cmCommand);
};
diff --git a/Source/cmFindIncludeCommand.h b/Source/cmFindIncludeCommand.h
index 4b2cd4a68a..7381032939 100644
--- a/Source/cmFindIncludeCommand.h
+++ b/Source/cmFindIncludeCommand.h
@@ -70,6 +70,8 @@ public:
return
"FIND_INCLUDE(DEFINE try1 try2 ...)";
}
+
+ cmTypeMacro(cmFindIncludeCommand, cmCommand);
};
diff --git a/Source/cmFindLibraryCommand.h b/Source/cmFindLibraryCommand.h
index eca2e60b83..f1e26a28e4 100644
--- a/Source/cmFindLibraryCommand.h
+++ b/Source/cmFindLibraryCommand.h
@@ -71,6 +71,8 @@ public:
return
"FIND_LIBRARY(DEFINE libraryName path1 path2 path3...)";
}
+
+ cmTypeMacro(cmFindLibraryCommand, cmCommand);
};
diff --git a/Source/cmFindProgramCommand.h b/Source/cmFindProgramCommand.h
index 8aa7ee9ceb..4b6d58cad7 100644
--- a/Source/cmFindProgramCommand.h
+++ b/Source/cmFindProgramCommand.h
@@ -71,6 +71,8 @@ public:
return
"FIND_PROGRAM(NAME executable1 executable2 ...)";
}
+
+ cmTypeMacro(cmFindProgramCommand, cmCommand);
};
diff --git a/Source/cmIncludeDirectoryCommand.h b/Source/cmIncludeDirectoryCommand.h
index 4236880c01..8011e533a6 100644
--- a/Source/cmIncludeDirectoryCommand.h
+++ b/Source/cmIncludeDirectoryCommand.h
@@ -69,6 +69,8 @@ public:
return
"INCLUDE_DIRECTORIES(dir1 dir2 ...)";
}
+
+ cmTypeMacro(cmIncludeDirectoryCommand, cmCommand);
};
diff --git a/Source/cmLibraryCommand.h b/Source/cmLibraryCommand.h
index 74957cb66f..0abb2dd511 100644
--- a/Source/cmLibraryCommand.h
+++ b/Source/cmLibraryCommand.h
@@ -64,6 +64,8 @@ public:
return
"LIBRARY(libraryname)";
}
+
+ cmTypeMacro(cmLibraryCommand, cmCommand);
};
diff --git a/Source/cmLinkDirectoriesCommand.h b/Source/cmLinkDirectoriesCommand.h
index 783c8802f1..36a6ad8eee 100644
--- a/Source/cmLinkDirectoriesCommand.h
+++ b/Source/cmLinkDirectoriesCommand.h
@@ -74,6 +74,8 @@ public:
"The directories can use built in definitions like \n"
"CMAKE_BINARY_DIR and CMAKE_SOURCE_DIR.";
}
+
+ cmTypeMacro(cmLinkDirectoriesCommand, cmCommand);
};
diff --git a/Source/cmLinkLibrariesCommand.h b/Source/cmLinkLibrariesCommand.h
index 31e931031b..5f01d524af 100644
--- a/Source/cmLinkLibrariesCommand.h
+++ b/Source/cmLinkLibrariesCommand.h
@@ -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);
};
diff --git a/Source/cmProjectCommand.h b/Source/cmProjectCommand.h
index fe395b0563..7c0c67377c 100644
--- a/Source/cmProjectCommand.h
+++ b/Source/cmProjectCommand.h
@@ -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);
};
diff --git a/Source/cmSourceFilesCommand.h b/Source/cmSourceFilesCommand.h
index f534339826..6ff44b20d4 100644
--- a/Source/cmSourceFilesCommand.h
+++ b/Source/cmSourceFilesCommand.h
@@ -68,6 +68,8 @@ public:
return
"SOURCE_FILES(file1 file2 ...)";
}
+
+ cmTypeMacro(cmSourceFilesCommand, cmCommand);
};
diff --git a/Source/cmSourceFilesRequireCommand.h b/Source/cmSourceFilesRequireCommand.h
index e84c21e226..b7253b7a15 100644
--- a/Source/cmSourceFilesRequireCommand.h
+++ b/Source/cmSourceFilesRequireCommand.h
@@ -67,6 +67,8 @@ public:
return
"SOURCE_FILES_REQUIRE(var1 var2 ... SOURCES_BEGIN file1 file2 ...)";
}
+
+ cmTypeMacro(cmSourceFilesRequireCommand, cmCommand);
};
diff --git a/Source/cmSubdirCommand.h b/Source/cmSubdirCommand.h
index 43a501e0ba..fd8b346be3 100644
--- a/Source/cmSubdirCommand.h
+++ b/Source/cmSubdirCommand.h
@@ -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);
};
diff --git a/Source/cmTestsCommand.h b/Source/cmTestsCommand.h
index ec001b3c3d..0a9fd9318f 100644
--- a/Source/cmTestsCommand.h
+++ b/Source/cmTestsCommand.h
@@ -67,6 +67,8 @@ public:
return
"TESTS(file1 file2 ...)";
}
+
+ cmTypeMacro(cmTestsCommand, cmCommand);
};
diff --git a/Source/cmUnixDefinesCommand.h b/Source/cmUnixDefinesCommand.h
index f912ff4dad..595792c8bf 100644
--- a/Source/cmUnixDefinesCommand.h
+++ b/Source/cmUnixDefinesCommand.h
@@ -75,6 +75,8 @@ public:
"UNIX_DEFINES(-DFOO -DBAR)\n"
"Add -D flags to the command line for Unix only.";
}
+
+ cmTypeMacro(cmUnixDefinesCommand, cmCommand);
};
diff --git a/Source/cmUnixLibrariesCommand.h b/Source/cmUnixLibrariesCommand.h
index 80a77a4821..e3c883d15e 100644
--- a/Source/cmUnixLibrariesCommand.h
+++ b/Source/cmUnixLibrariesCommand.h
@@ -74,6 +74,8 @@ public:
return
"UNIX_LIBRARIES(library -lm ...)";
}
+
+ cmTypeMacro(cmUnixLibrariesCommand, cmCommand);
};
diff --git a/Source/cmWin32DefinesCommand.h b/Source/cmWin32DefinesCommand.h
index a8e0da89f3..af07265beb 100644
--- a/Source/cmWin32DefinesCommand.h
+++ b/Source/cmWin32DefinesCommand.h
@@ -75,6 +75,8 @@ public:
"WIN32_DEFINES(-DFOO -DBAR ...)\n"
"Add -D define flags to command line for Win32 environments.";
}
+
+ cmTypeMacro(cmWin32DefinesCommand, cmCommand);
};
diff --git a/Source/cmWin32LibrariesCommand.h b/Source/cmWin32LibrariesCommand.h
index 61d7b189d0..02885afbb8 100644
--- a/Source/cmWin32LibrariesCommand.h
+++ b/Source/cmWin32LibrariesCommand.h
@@ -74,6 +74,8 @@ public:
return
"WIN32_LIBRARIES(library -lm ...)";
}
+
+ cmTypeMacro(cmWin32LibrariesCommand, cmCommand);
};