ENH: Add superclass for all commands and handlers. Improve handlers to have initialization code, and start initializing ctest when start is invoked

This commit is contained in:
Andy Cedilnik 2005-06-17 13:04:56 -04:00
parent d3239ac68f
commit d9dc9b54a6
26 changed files with 361 additions and 53 deletions

View File

@ -31,6 +31,11 @@ cmCTestBuildAndTestHandler::cmCTestBuildAndTestHandler()
m_BuildNoCMake = false; m_BuildNoCMake = false;
} }
//----------------------------------------------------------------------
void cmCTestBuildAndTestHandler::Initialize()
{
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
const char* cmCTestBuildAndTestHandler::GetOutput() const char* cmCTestBuildAndTestHandler::GetOutput()
{ {

View File

@ -31,6 +31,7 @@ class cmake;
class cmCTestBuildAndTestHandler : public cmCTestGenericHandler class cmCTestBuildAndTestHandler : public cmCTestGenericHandler
{ {
public: public:
cmTypeMacro(cmCTestBuildAndTestHandler, cmCTestGenericHandler);
/* /*
* The main entry point for this class * The main entry point for this class
@ -49,6 +50,8 @@ public:
cmCTestBuildAndTestHandler(); cmCTestBuildAndTestHandler();
virtual void Initialize();
protected: protected:
///! Run CMake and build a test and then run it as a single test. ///! Run CMake and build a test and then run it as a single test.
int RunCMakeAndTest(std::string* output); int RunCMakeAndTest(std::string* output);

View File

@ -186,6 +186,64 @@ cmCTestBuildHandler::cmCTestBuildHandler()
} }
} }
//----------------------------------------------------------------------
void cmCTestBuildHandler::Initialize()
{
m_StartBuild = "";
m_EndBuild = "";
m_CustomErrorMatches.clear();
m_CustomErrorExceptions.clear();
m_CustomWarningMatches.clear();
m_CustomWarningExceptions.clear();
m_ErrorWarningFileLineRegex.clear();
m_ErrorMatchRegex.clear();
m_ErrorExceptionRegex.clear();
m_WarningMatchRegex.clear();
m_WarningExceptionRegex.clear();
m_BuildProcessingQueue.clear();
m_BuildProcessingQueueLocation = m_BuildProcessingQueue.end();
m_BuildOutputLogSize = 0;
m_CurrentProcessingLine.clear();
m_SimplifySourceDir = "";
m_SimplifyBuildDir = "";
m_OutputLineCounter = 0;
m_ErrorsAndWarnings.clear();
m_LastErrorOrWarning = m_ErrorsAndWarnings.end();
m_PostContextCount = 0;
m_MaxPreContext = 6;
m_MaxPostContext = 6;
m_PreContext.clear();
m_TotalErrors = 0;
m_TotalWarnings = 0;
m_LastTickChar = 0;
m_ErrorQuotaReached = false;
m_WarningQuotaReached = false;
m_MaxErrors = 50;
m_MaxWarnings = 50;
int cc;
for ( cc = 0; cmCTestWarningErrorFileLine[cc].m_RegularExpressionString; ++ cc )
{
cmCTestBuildHandler::cmCTestCompileErrorWarningRex r;
if ( r.m_RegularExpression.compile(
cmCTestWarningErrorFileLine[cc].m_RegularExpressionString) )
{
r.m_FileIndex = cmCTestWarningErrorFileLine[cc].m_FileIndex;
r.m_LineIndex = cmCTestWarningErrorFileLine[cc].m_LineIndex;
m_ErrorWarningFileLineRegex.push_back(r);
}
else
{
cmCTestLog(m_CTest, ERROR_MESSAGE, "Problem Compiling regular expression: "
<< cmCTestWarningErrorFileLine[cc].m_RegularExpressionString << std::endl);
}
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void cmCTestBuildHandler::PopulateCustomVectors(cmMakefile *mf) void cmCTestBuildHandler::PopulateCustomVectors(cmMakefile *mf)

View File

@ -33,6 +33,7 @@ class cmMakefile;
class cmCTestBuildHandler : public cmCTestGenericHandler class cmCTestBuildHandler : public cmCTestGenericHandler
{ {
public: public:
cmTypeMacro(cmCTestBuildHandler, cmCTestGenericHandler);
/* /*
* The main entry point for this class * The main entry point for this class
@ -43,6 +44,11 @@ public:
void PopulateCustomVectors(cmMakefile *mf); void PopulateCustomVectors(cmMakefile *mf);
/**
* Initialize handler
*/
virtual void Initialize();
private: private:
//! Run command specialized for make and configure. Returns process status //! Run command specialized for make and configure. Returns process status
// and retVal is return value or exception. // and retVal is return value or exception.

View File

@ -28,6 +28,10 @@ cmCTestConfigureHandler::cmCTestConfigureHandler()
{ {
} }
//----------------------------------------------------------------------
void cmCTestConfigureHandler::Initialize()
{
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
//clearly it would be nice if this were broken up into a few smaller //clearly it would be nice if this were broken up into a few smaller

View File

@ -29,6 +29,7 @@
class cmCTestConfigureHandler : public cmCTestGenericHandler class cmCTestConfigureHandler : public cmCTestGenericHandler
{ {
public: public:
cmTypeMacro(cmCTestConfigureHandler, cmCTestGenericHandler);
/* /*
* The main entry point for this class * The main entry point for this class
@ -36,6 +37,8 @@ public:
int ProcessHandler(); int ProcessHandler();
cmCTestConfigureHandler(); cmCTestConfigureHandler();
void Initialize();
}; };
#endif #endif

View File

@ -34,7 +34,11 @@
//---------------------------------------------------------------------- //----------------------------------------------------------------------
cmCTestCoverageHandler::cmCTestCoverageHandler() cmCTestCoverageHandler::cmCTestCoverageHandler()
{ {
m_CTest = 0; }
//----------------------------------------------------------------------
void cmCTestCoverageHandler::Initialize()
{
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -31,6 +31,7 @@ class cmGeneratedFileStream;
class cmCTestCoverageHandler : public cmCTestGenericHandler class cmCTestCoverageHandler : public cmCTestGenericHandler
{ {
public: public:
cmTypeMacro(cmCTestCoverageHandler, cmCTestGenericHandler);
/* /*
* The main entry point for this class * The main entry point for this class
@ -39,6 +40,8 @@ public:
cmCTestCoverageHandler(); cmCTestCoverageHandler();
virtual void Initialize();
private: private:
bool ShouldIDoCoverage(const char* file, const char* srcDir, bool ShouldIDoCoverage(const char* file, const char* srcDir,
const char* binDir); const char* binDir);

View File

@ -19,7 +19,7 @@
#define cmCTestGenericHandler_h #define cmCTestGenericHandler_h
#include "cmStandardIncludes.h" #include "cmObject.h"
class cmCTest; class cmCTest;
class cmMakefile; class cmMakefile;
@ -29,7 +29,7 @@ class cmCTestCommand;
* \brief A superclass of all CTest Handlers * \brief A superclass of all CTest Handlers
* *
*/ */
class cmCTestGenericHandler class cmCTestGenericHandler : public cmObject
{ {
public: public:
/** /**
@ -55,6 +55,11 @@ public:
const std::string& /*currentArg*/, size_t& /*idx*/, const std::string& /*currentArg*/, size_t& /*idx*/,
const std::vector<std::string>& /*allArgs*/) { return 1; } const std::vector<std::string>& /*allArgs*/) { return 1; }
/**
* Initialize handler
*/
virtual void Initialize() = 0;
/** /**
* Set the CTest instance * Set the CTest instance
*/ */

View File

@ -90,6 +90,23 @@ cmCTestMemCheckHandler::cmCTestMemCheckHandler()
m_MemCheck = true; m_MemCheck = true;
} }
//----------------------------------------------------------------------
void cmCTestMemCheckHandler::Initialize()
{
this->Superclass::Initialize();
m_MemoryTester = "";
m_MemoryTesterOptionsParsed.clear();
m_MemoryTesterOptions = "";
m_MemoryTesterStyle = UNKNOWN;
m_MemoryTesterOutputFile = "";
int cc;
for ( cc = 0; cc < NO_MEMORY_FAULT; cc ++ )
{
m_MemoryTesterGlobalResults[cc] = 0;
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int cmCTestMemCheckHandler::PreProcessHandler() int cmCTestMemCheckHandler::PreProcessHandler()
{ {

View File

@ -31,10 +31,13 @@ class cmMakefile;
class cmCTestMemCheckHandler : public cmCTestTestHandler class cmCTestMemCheckHandler : public cmCTestTestHandler
{ {
public: public:
cmTypeMacro(cmCTestMemCheckHandler, cmCTestTestHandler);
void PopulateCustomVectors(cmMakefile *mf); void PopulateCustomVectors(cmMakefile *mf);
cmCTestMemCheckHandler(); cmCTestMemCheckHandler();
void Initialize();
protected: protected:
virtual int PreProcessHandler(); virtual int PreProcessHandler();
virtual int PostProcessHandler(); virtual int PostProcessHandler();

View File

@ -97,6 +97,49 @@ cmCTestScriptHandler::cmCTestScriptHandler()
m_ContinuousDuration = -1; m_ContinuousDuration = -1;
} }
//----------------------------------------------------------------------
void cmCTestScriptHandler::Initialize()
{
m_Backup = false;
m_EmptyBinDir = false;
m_EmptyBinDirOnce = false;
m_SourceDir = "";
m_BinaryDir = "";
m_BackupSourceDir = "";
m_BackupBinaryDir = "";
m_CTestRoot = "";
m_CVSCheckOut = "";
m_CTestCmd = "";
m_CVSCmd = "";
m_CTestEnv = "";
m_InitCache = "";
m_CMakeCmd = "";
m_CMOutFile = "";
m_ExtraUpdates.clear();
m_MinimumInterval = 20*60;
m_ContinuousDuration = -1;
// what time in seconds did this script start running
m_ScriptStartTime = 0;
m_Makefile = 0;
if (m_LocalGenerator)
{
delete m_LocalGenerator;
}
m_LocalGenerator = 0;
if (m_GlobalGenerator)
{
delete m_GlobalGenerator;
}
m_GlobalGenerator = 0;
if (m_CMake)
{
delete m_CMake;
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
cmCTestScriptHandler::~cmCTestScriptHandler() cmCTestScriptHandler::~cmCTestScriptHandler()

View File

@ -66,6 +66,7 @@ class cmCTestCommand;
class cmCTestScriptHandler : public cmCTestGenericHandler class cmCTestScriptHandler : public cmCTestGenericHandler
{ {
public: public:
cmTypeMacro(cmCTestScriptHandler, cmCTestGenericHandler);
/** /**
* Add a script to run * Add a script to run
@ -97,6 +98,7 @@ public:
cmCTestScriptHandler(); cmCTestScriptHandler();
~cmCTestScriptHandler(); ~cmCTestScriptHandler();
void Initialize();
private: private:
// reads in a script // reads in a script
int ReadInScript(const std::string& total_script_arg); int ReadInScript(const std::string& total_script_arg);

View File

@ -64,6 +64,7 @@ bool cmCTestStartCommand::InitialPass(
this->SetError("binary directory not specified. Specify binary directory as an argument or set CTEST_BINARY_DIRECTORY"); this->SetError("binary directory not specified. Specify binary directory as an argument or set CTEST_BINARY_DIRECTORY");
return false; return false;
} }
m_CTest->EmptyCTestConfiguration();
m_CTest->SetCTestConfiguration("SourceDirectory", src_dir); m_CTest->SetCTestConfiguration("SourceDirectory", src_dir);
m_CTest->SetCTestConfiguration("BuildDirectory", bld_dir); m_CTest->SetCTestConfiguration("BuildDirectory", bld_dir);

View File

@ -67,6 +67,17 @@ cmCTestSubmitHandler::cmCTestSubmitHandler() : m_HTTPProxy(), m_FTPProxy()
m_FTPProxyType = 0; m_FTPProxyType = 0;
} }
//----------------------------------------------------------------------------
void cmCTestSubmitHandler::Initialize()
{
m_HTTPProxy = "";
m_HTTPProxyType = 0;
m_HTTPProxyAuth = "";
m_FTPProxy = "";
m_FTPProxyType = 0;
m_LogFile = 0;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmCTestSubmitHandler::SubmitUsingFTP(const cmStdString& localprefix, bool cmCTestSubmitHandler::SubmitUsingFTP(const cmStdString& localprefix,
const std::vector<cmStdString>& files, const std::vector<cmStdString>& files,

View File

@ -28,6 +28,8 @@
class cmCTestSubmitHandler : public cmCTestGenericHandler class cmCTestSubmitHandler : public cmCTestGenericHandler
{ {
public: public:
cmTypeMacro(cmCTestSubmitHandler, cmCTestGenericHandler);
cmCTestSubmitHandler(); cmCTestSubmitHandler();
~cmCTestSubmitHandler() { m_LogFile = 0; } ~cmCTestSubmitHandler() { m_LogFile = 0; }
@ -36,6 +38,7 @@ public:
*/ */
int ProcessHandler(); int ProcessHandler();
void Initialize();
private: private:
void SetLogFile(std::ostream* ost) { m_LogFile = ost; } void SetLogFile(std::ostream* ost) { m_LogFile = ost; }

View File

@ -293,6 +293,35 @@ cmCTestTestHandler::cmCTestTestHandler()
m_MemCheck = false; m_MemCheck = false;
} }
//----------------------------------------------------------------------
void cmCTestTestHandler::Initialize()
{
m_ElapsedTestingTime = -1;
m_TestResults.clear();
m_CustomTestsIgnore.clear();
m_StartTest = "";
m_EndTest = "";
m_CustomPreTest.clear();
m_CustomPostTest.clear();
m_CustomMaximumPassedTestOutputSize = 1 * 1024;
m_CustomMaximumFailedTestOutputSize = 300 * 1024;
m_TestsToRun.clear();
m_UseIncludeRegExp = false;
m_UseExcludeRegExp = false;
m_UseExcludeRegExpFirst = false;
m_IncludeRegExp = "";
m_ExcludeRegExp = "";
TestsToRunString = "";
m_UseUnion = false;
m_TestList.clear();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void cmCTestTestHandler::PopulateCustomVectors(cmMakefile *mf) void cmCTestTestHandler::PopulateCustomVectors(cmMakefile *mf)
{ {

View File

@ -31,6 +31,7 @@ class cmMakefile;
class cmCTestTestHandler : public cmCTestGenericHandler class cmCTestTestHandler : public cmCTestGenericHandler
{ {
public: public:
cmTypeMacro(cmCTestTestHandler, cmCTestGenericHandler);
/** /**
* The main entry point for this class * The main entry point for this class
@ -81,6 +82,8 @@ public:
int m_TestCount; int m_TestCount;
}; };
void Initialize();
protected: protected:
struct cmCTestTestProperties struct cmCTestTestProperties
{ {

View File

@ -66,6 +66,7 @@ bool cmCTestUpdateCommand::InitialPass(
} }
} }
m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "UpdateCommand", "CTEST_UPDATE_COMMAND");
m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "CVSCommand", "CTEST_CVS_COMMAND"); m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "CVSCommand", "CTEST_CVS_COMMAND");
m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "SVNCommand", "CTEST_SVN_COMMAND"); m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "SVNCommand", "CTEST_SVN_COMMAND");

View File

@ -38,6 +38,23 @@
#include <math.h> #include <math.h>
#include <float.h> #include <float.h>
//----------------------------------------------------------------------
static const char* cmCTestUpdateHandlerUpdateStrings[] =
{
"Unknown",
"CVS",
"SVN"
};
static const char* cmCTestUpdateHandlerUpdateToString(int type)
{
if ( type < cmCTestUpdateHandler::e_UNKNOWN || type >= cmCTestUpdateHandler::e_LAST )
{
return cmCTestUpdateHandlerUpdateStrings[cmCTestUpdateHandler::e_UNKNOWN];
}
return cmCTestUpdateHandlerUpdateStrings[type];
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
//********************************************************************** //**********************************************************************
class cmCTestUpdateHandlerSVNXMLParser : public cmXMLParser class cmCTestUpdateHandlerSVNXMLParser : public cmXMLParser
@ -156,14 +173,20 @@ private:
//---------------------------------------------------------------------- //----------------------------------------------------------------------
cmCTestUpdateHandler::cmCTestUpdateHandler() cmCTestUpdateHandler::cmCTestUpdateHandler()
{ {
m_CTest = 0; }
//----------------------------------------------------------------------
void cmCTestUpdateHandler::Initialize()
{
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int cmCTestUpdateHandler::DetermineType(const char* cmd, const char* type) int cmCTestUpdateHandler::DetermineType(const char* cmd, const char* type)
{ {
cmCTestLog(m_CTest, DEBUG, "Determine update type from command: " << cmd << " and type: " << type << std::endl);
if ( type && *type ) if ( type && *type )
{ {
cmCTestLog(m_CTest, DEBUG, "Type specified: " << type << std::endl);
std::string stype = cmSystemTools::LowerCase(type); std::string stype = cmSystemTools::LowerCase(type);
if ( stype.find("cvs") != std::string::npos ) if ( stype.find("cvs") != std::string::npos )
{ {
@ -176,6 +199,7 @@ int cmCTestUpdateHandler::DetermineType(const char* cmd, const char* type)
} }
else else
{ {
cmCTestLog(m_CTest, DEBUG, "Type not specified, check command: " << cmd << std::endl);
std::string stype = cmSystemTools::LowerCase(cmd); std::string stype = cmSystemTools::LowerCase(cmd);
if ( stype.find("cvs") != std::string::npos ) if ( stype.find("cvs") != std::string::npos )
{ {
@ -186,7 +210,20 @@ int cmCTestUpdateHandler::DetermineType(const char* cmd, const char* type)
return cmCTestUpdateHandler::e_SVN; return cmCTestUpdateHandler::e_SVN;
} }
} }
std::string sourceDirectory = this->GetOption("SourceDirectory");
cmCTestLog(m_CTest, DEBUG, "Check directory: " << sourceDirectory.c_str() << std::endl);
sourceDirectory += "/.svn";
if ( cmSystemTools::FileExists(sourceDirectory.c_str()) )
{
return cmCTestUpdateHandler::e_SVN;
}
sourceDirectory = this->GetOption("SourceDirectory");
sourceDirectory += "/CVS";
if ( cmSystemTools::FileExists(sourceDirectory.c_str()) )
{
return cmCTestUpdateHandler::e_CVS; return cmCTestUpdateHandler::e_CVS;
}
return cmCTestUpdateHandler::e_UNKNOWN;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -285,6 +322,8 @@ int cmCTestUpdateHandler::ProcessHandler()
updateType = this->DetermineType(updateCommand.c_str(), m_CTest->GetCTestConfiguration("UpdateType").c_str()); updateType = this->DetermineType(updateCommand.c_str(), m_CTest->GetCTestConfiguration("UpdateType").c_str());
} }
cmCTestLog(m_CTest, HANDLER_OUTPUT, " Use " << cmCTestUpdateHandlerUpdateToString(updateType) << " repository type" << std::endl;);
// And update options // And update options
std::string updateOptions = m_CTest->GetCTestConfiguration("UpdateOptions"); std::string updateOptions = m_CTest->GetCTestConfiguration("UpdateOptions");
if ( updateOptions.empty() ) if ( updateOptions.empty() )
@ -434,6 +473,7 @@ int cmCTestUpdateHandler::ProcessHandler()
&retVal, sourceDirectory, 0 /*m_TimeOut*/); &retVal, sourceDirectory, 0 /*m_TimeOut*/);
ofs << " Output: " << partialOutput.c_str() << std::endl; ofs << " Output: " << partialOutput.c_str() << std::endl;
ofs << " Errors: " << errors.c_str() << std::endl; ofs << " Errors: " << errors.c_str() << std::endl;
goutput = partialOutput;
command = updateCommand + " status"; command = updateCommand + " status";
ofs << "* Status repository: " << std::endl; ofs << "* Status repository: " << std::endl;
ofs << " Command: " << command.c_str() << std::endl; ofs << " Command: " << command.c_str() << std::endl;
@ -443,6 +483,7 @@ int cmCTestUpdateHandler::ProcessHandler()
ofs << " Errors: " << errors.c_str() << std::endl; ofs << " Errors: " << errors.c_str() << std::endl;
goutput += partialOutput; goutput += partialOutput;
res = res && res1; res = res && res1;
ofs << " Total output of update: " << goutput.c_str() << std::endl;
} }
} }
if ( ofs ) if ( ofs )
@ -467,7 +508,9 @@ int cmCTestUpdateHandler::ProcessHandler()
<< m_CTest->GetTestModelString() << "</BuildStamp>" << std::endl; << m_CTest->GetTestModelString() << "</BuildStamp>" << std::endl;
os << "\t<StartDateTime>" << start_time << "</StartDateTime>\n" os << "\t<StartDateTime>" << start_time << "</StartDateTime>\n"
<< "\t<UpdateCommand>" << m_CTest->MakeXMLSafe(command) << "\t<UpdateCommand>" << m_CTest->MakeXMLSafe(command)
<< "</UpdateCommand>\n"; << "</UpdateCommand>\n"
<< "\t<UpdateType>" << m_CTest->MakeXMLSafe(cmCTestUpdateHandlerUpdateToString(updateType))
<< "</UpdateType>\n";
// Even though it failed, we may have some useful information. Try to continue... // Even though it failed, we may have some useful information. Try to continue...
std::vector<cmStdString> lines; std::vector<cmStdString> lines;
@ -503,7 +546,11 @@ int cmCTestUpdateHandler::ProcessHandler()
} }
} }
} }
if ( updateType == cmCTestUpdateHandler::e_SVN ) if ( svn_latest_revision <= 0 )
{
cmCTestLog(m_CTest, ERROR_MESSAGE, "Problem determining the current revision of the repository from output:" << std::endl << goutput.c_str() << std::endl);
}
else if ( updateType == cmCTestUpdateHandler::e_SVN )
{ {
cmCTestLog(m_CTest, HANDLER_OUTPUT, " Current revision of repository is: " << svn_latest_revision << std::endl); cmCTestLog(m_CTest, HANDLER_OUTPUT, " Current revision of repository is: " << svn_latest_revision << std::endl);
} }

View File

@ -33,6 +33,7 @@
class cmCTestUpdateHandler : public cmCTestGenericHandler class cmCTestUpdateHandler : public cmCTestGenericHandler
{ {
public: public:
cmTypeMacro(cmCTestUpdateHandler, cmCTestGenericHandler);
/* /*
* The main entry point for this class * The main entry point for this class
@ -42,10 +43,17 @@ public:
cmCTestUpdateHandler(); cmCTestUpdateHandler();
enum { enum {
e_UNKNOWN = 0,
e_CVS, e_CVS,
e_SVN e_SVN,
e_LAST
}; };
/**
* Initialize handler
*/
virtual void Initialize();
private: private:
// Some structures needed for update // Some structures needed for update
struct StringPair : struct StringPair :

View File

@ -1799,6 +1799,12 @@ std::string cmCTest::GetCTestConfiguration(const char *name)
return m_CTestConfiguration[name]; return m_CTestConfiguration[name];
} }
//----------------------------------------------------------------------
void cmCTest::EmptyCTestConfiguration()
{
m_CTestConfiguration.clear();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void cmCTest::SetCTestConfiguration(const char *name, const char* value) void cmCTest::SetCTestConfiguration(const char *name, const char* value)
{ {

View File

@ -114,6 +114,7 @@ public:
static std::string CleanString(const std::string& str); static std::string CleanString(const std::string& str);
std::string GetCTestConfiguration(const char *name); std::string GetCTestConfiguration(const char *name);
void SetCTestConfiguration(const char *name, const char* value); void SetCTestConfiguration(const char *name, const char* value);
void EmptyCTestConfiguration();
/** /**
* constructor and destructor * constructor and destructor

View File

@ -17,6 +17,7 @@
#ifndef cmCommand_h #ifndef cmCommand_h
#define cmCommand_h #define cmCommand_h
#include "cmObject.h"
#include "cmListFileCache.h" #include "cmListFileCache.h"
#include "cmMakefile.h" #include "cmMakefile.h"
@ -30,9 +31,11 @@
* to support such features as enable/disable, inheritance, * to support such features as enable/disable, inheritance,
* documentation, and construction. * documentation, and construction.
*/ */
class cmCommand class cmCommand : public cmObject
{ {
public: public:
cmTypeMacro(cmCommand, cmObject);
/** /**
* Construct the command. By default it is enabled with no makefile. * Construct the command. By default it is enabled with no makefile.
*/ */
@ -103,11 +106,6 @@ public:
*/ */
virtual const char* GetName() = 0; virtual const char* GetName() = 0;
/**
* The class name of the command.
*/
virtual const char* GetNameOfClass() = 0;
/** /**
* Succinct documentation. * Succinct documentation.
*/ */
@ -155,19 +153,6 @@ public:
return m_Error.c_str(); 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); }
/** /**
* Set the error message * Set the error message
*/ */
@ -186,30 +171,4 @@ private:
std::string m_Error; std::string m_Error;
}; };
// All subclasses of cmCommand should invoke this macro.
#define cmTypeMacro(thisClass,superclass) \
virtual const char* GetNameOfClass() { return #thisClass; } \
typedef superclass 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 #endif

56
Source/cmObject.h Normal file
View File

@ -0,0 +1,56 @@
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef cmObject_h
#define cmObject_h
#include "cmStandardIncludes.h"
/** \class cmObject
* \brief Superclass for all commands and other classes in CMake.
*
* cmObject is the base class for all classes in CMake. It defines some methods
* such as GetNameOfClass, IsA, SafeDownCast.
*/
class cmObject
{
public:
/**
* Need virtual destructor to destroy real command type.
*/
virtual ~cmObject() {}
/**
* The class name of the command.
*/
virtual const char* GetNameOfClass() = 0;
/**
* Returns true if this class is the given class, or a subclass of it.
*/
static bool IsTypeOf(const char *type)
{ return !strcmp("cmObject", 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 cmObject::IsTypeOf(type); }
};
#endif

View File

@ -323,4 +323,31 @@ public:
# pragma reset woff 1375 /* base class destructor not virtual */ # pragma reset woff 1375 /* base class destructor not virtual */
#endif #endif
// All subclasses of cmCommand or cmCTestGenericHandler should invoke this macro.
#define cmTypeMacro(thisClass,superclass) \
virtual const char* GetNameOfClass() { return #thisClass; } \
typedef superclass 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(cmObject *c) \
{ \
if ( c && c->IsA(#thisClass) ) \
{ \
return (thisClass *)c; \
} \
return 0;\
}
#endif #endif