FIX: stupid pb fixed (close to being medieval'ed by The Ken)
[cmake.git] / Source / cmCommand.h
blob1fa0b5eb6906b9837cde1413ba58d5b01bcea0b9
1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmCommand.h,v $
5 Language: C++
6 Date: $Date: 2002-01-21 20:30:21 $
7 Version: $Revision: 1.11 $
9 Copyright (c) 2002 Insight Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #ifndef cmCommand_h
18 #define cmCommand_h
20 #include "cmStandardIncludes.h"
21 #include "cmMakefile.h"
23 /** \class cmCommand
24 * \brief Superclass for all commands in CMake.
26 * cmCommand is the base class for all commands in CMake. A command
27 * manifests as an entry in CMakeLists.txt and produces one or
28 * more makefile rules. Commands are associated with a particular
29 * makefile. This base class cmCommand defines the API for commands
30 * to support such features as enable/disable, inheritance,
31 * documentation, and construction.
33 class cmCommand
35 public:
36 /**
37 * Construct the command. By default it is enabled with no makefile.
39 cmCommand()
40 {m_Makefile = 0; m_Enabled = true;}
42 /**
43 * Need virtual destructor to destroy real command type.
45 virtual ~cmCommand() {}
47 /**
48 * Specify the makefile.
50 void SetMakefile(cmMakefile*m)
51 {m_Makefile = m; }
53 /**
54 * This is called when the command is first encountered in
55 * the CMakeLists.txt file.
57 virtual bool InitialPass(std::vector<std::string> const& args) = 0;
59 /**
60 * This is called at the end after all the information
61 * specified by the command is accumulated. Most commands do
62 * not implement this method. At this point, reading and
63 * writing to the cache can be done.
65 virtual void FinalPass() {};
67 /**
68 * This is a virtual constructor for the command.
70 virtual cmCommand* Clone() = 0;
72 /**
73 * This determines if the command gets propagated down
74 * to makefiles located in subdirectories.
76 virtual bool IsInherited()
78 return false;
81 /**
82 * The name of the command as specified in CMakeList.txt.
84 virtual const char* GetName() = 0;
86 /**
87 * Succinct documentation.
89 virtual const char* GetTerseDocumentation() = 0;
91 /**
92 * More documentation.
94 virtual const char* GetFullDocumentation() = 0;
96 /**
97 * Enable the command.
99 void EnabledOn()
100 {m_Enabled = true;}
103 * Disable the command.
105 void EnabledOff()
106 {m_Enabled = false;}
109 * Query whether the command is enabled.
111 bool GetEnabled()
112 {return m_Enabled;}
115 * Disable or enable the command.
117 void SetEnabled(bool enabled)
118 {m_Enabled = enabled;}
121 * Return the last error string.
123 const char* GetError()
125 if(m_Error.length() == 0)
127 m_Error = this->GetName();
128 m_Error += " unknown error.";
130 return m_Error.c_str();
134 * Returns true if this class is the given class, or a subclass of it.
136 static bool IsTypeOf(const char *type)
137 { return !strcmp("cmCommand", type); }
140 * Returns true if this object is an instance of the given class or
141 * a subclass of it.
143 virtual bool IsA(const char *type)
144 { return cmCommand::IsTypeOf(type); }
146 protected:
147 void SetError(const char* e)
149 m_Error = this->GetName();
150 m_Error += " ";
151 m_Error += e;
153 cmMakefile* m_Makefile;
155 private:
156 bool m_Enabled;
157 std::string m_Error;
160 // All subclasses of cmCommand should invoke this macro.
161 #define cmTypeMacro(thisClass,superclass) \
162 static bool IsTypeOf(const char *type) \
164 if ( !strcmp(#thisClass,type) ) \
166 return true; \
168 return superclass::IsTypeOf(type); \
170 virtual bool IsA(const char *type) \
172 return thisClass::IsTypeOf(type); \
174 static thisClass* SafeDownCast(cmCommand *c) \
176 if ( c && c->IsA(#thisClass) ) \
178 return (thisClass *)c; \
180 return 0;\
184 #endif