1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
5 #include "cmConfigure.h" // IWYU pragma: keep
14 /** \class cmVariableWatch
15 * \brief Helper class for watching of variable accesses.
17 * Calls function when variable is accessed
22 using WatchMethod
= void (*)(const std::string
&, int, void*, const char*,
24 using DeleteData
= void (*)(void*);
30 * Add watch to the variable
32 bool AddWatch(const std::string
& variable
, WatchMethod method
,
33 void* client_data
= nullptr, DeleteData delete_data
= nullptr);
34 void RemoveWatch(const std::string
& variable
, WatchMethod method
,
35 void* client_data
= nullptr);
38 * This method is called when variable is accessed
40 bool VariableAccessed(const std::string
& variable
, int access_type
,
41 const char* newValue
, const cmMakefile
* mf
) const;
44 * Different access types.
49 UNKNOWN_VARIABLE_READ_ACCESS
,
50 UNKNOWN_VARIABLE_DEFINED_ACCESS
,
51 VARIABLE_MODIFIED_ACCESS
,
52 VARIABLE_REMOVED_ACCESS
,
57 * Return the access as string
59 static const std::string
& GetAccessAsString(int access_type
);
64 WatchMethod Method
= nullptr;
65 void* ClientData
= nullptr;
66 DeleteData DeleteDataCall
= nullptr;
69 if (this->DeleteDataCall
&& this->ClientData
) {
70 this->DeleteDataCall(this->ClientData
);
74 Pair(const Pair
&) = delete;
75 Pair
& operator=(const Pair
&) = delete;
78 using VectorOfPairs
= std::vector
<std::shared_ptr
<Pair
>>;
79 using StringToVectorOfPairs
= std::map
<std::string
, VectorOfPairs
>;
81 StringToVectorOfPairs WatchMap
;