Imported Upstream version 2.8.9
[platform/upstream/cmake.git] / Source / cmVariableWatchCommand.h
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #ifndef cmVariableWatchCommand_h
13 #define cmVariableWatchCommand_h
14
15 #include "cmCommand.h"
16
17 class cmVariableWatchCommandHandler
18 {
19 public:
20   typedef std::vector<std::string> VectorOfCommands;
21   VectorOfCommands Commands;
22 };
23
24 /** \class cmVariableWatchCommand
25  * \brief Watch when the variable changes and invoke command
26  *
27  */
28 class cmVariableWatchCommand : public cmCommand
29 {
30 public:
31   /**
32    * This is a virtual constructor for the command.
33    */
34   virtual cmCommand* Clone() 
35     {
36     return new cmVariableWatchCommand;
37     }
38
39   //! Default constructor
40   cmVariableWatchCommand();
41
42   /**
43    * This is called when the command is first encountered in
44    * the CMakeLists.txt file.
45    */
46   virtual bool InitialPass(std::vector<std::string> const& args,
47                            cmExecutionStatus &status);
48
49   /**
50    * This determines if the command is invoked when in script mode.
51    */
52   virtual bool IsScriptable() const { return true; }
53
54   /** This command does not really have a final pass but it needs to
55       stay alive since it owns variable watch callback information. */
56   virtual bool HasFinalPass() const { return true; }
57
58   /**
59    * The name of the command as specified in CMakeList.txt.
60    */
61   virtual const char* GetName() const { return "variable_watch";}
62
63   /**
64    * Succinct documentation.
65    */
66   virtual const char* GetTerseDocumentation() const
67     {
68     return "Watch the CMake variable for change.";
69     }
70   
71   /**
72    * More documentation.
73    */
74   virtual const char* GetFullDocumentation() const
75     {
76     return
77       "  variable_watch(<variable name> [<command to execute>])\n"
78       "If the specified variable changes, the message will be printed about "
79       "the variable being changed. If the command is specified, the command "
80       "will be executed. The command will receive the following arguments:"
81       " COMMAND(<variable> <access> <value> <current list file> <stack>)";
82     }
83   
84   cmTypeMacro(cmVariableWatchCommand, cmCommand);
85
86   void VariableAccessed(const std::string& variable, int access_type,
87     const char* newValue, const cmMakefile* mf);
88
89 protected:
90   std::map<std::string, cmVariableWatchCommandHandler> Handlers;
91
92   bool InCallback;
93 };
94
95
96 #endif
97
98