1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
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 cmVariableWatch_h
13 #define cmVariableWatch_h
15 #include "cmStandardIncludes.h"
19 /** \class cmVariableWatch
20 * \brief Helper class for watching of variable accesses.
22 * Calls function when variable is accessed
27 typedef void (*WatchMethod)(const std::string& variable, int access_type,
28 void* client_data, const char* newValue, const cmMakefile* mf);
29 typedef void (*DeleteData)(void* client_data);
35 * Add watch to the variable
37 bool AddWatch(const std::string& variable, WatchMethod method,
38 void* client_data=0, DeleteData delete_data=0);
39 void RemoveWatch(const std::string& variable, WatchMethod method,
43 * This method is called when variable is accessed
45 void VariableAccessed(const std::string& variable, int access_type,
46 const char* newValue, const cmMakefile* mf) const;
49 * Different access types.
53 VARIABLE_READ_ACCESS = 0,
54 UNKNOWN_VARIABLE_READ_ACCESS,
55 UNKNOWN_VARIABLE_DEFINED_ACCESS,
56 ALLOWED_UNKNOWN_VARIABLE_READ_ACCESS,
57 VARIABLE_MODIFIED_ACCESS,
58 VARIABLE_REMOVED_ACCESS,
63 * Return the access as string
65 static const char* GetAccessAsString(int access_type);
72 DeleteData DeleteDataCall;
73 Pair() : Method(0), ClientData(0), DeleteDataCall(0) {}
76 if (this->DeleteDataCall && this->ClientData)
78 this->DeleteDataCall(this->ClientData);
83 typedef std::vector< Pair* > VectorOfPairs;
84 typedef std::map<cmStdString, VectorOfPairs > StringToVectorOfPairs;
86 StringToVectorOfPairs WatchMap;