cmake/Source/cmVariableWatch.h

90 lines
2.1 KiB
C
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#ifndef cmVariableWatch_h
#define cmVariableWatch_h
2017-07-20 19:35:53 +02:00
#include "cmConfigure.h" // IWYU pragma: keep
2016-10-30 18:24:19 +01:00
#include <map>
2018-01-26 17:06:56 +01:00
#include <memory> // IWYU pragma: keep
2016-10-30 18:24:19 +01:00
#include <string>
#include <vector>
class cmMakefile;
/** \class cmVariableWatch
* \brief Helper class for watching of variable accesses.
*
* Calls function when variable is accessed
*/
class cmVariableWatch
{
public:
typedef void (*WatchMethod)(const std::string& variable, int access_type,
2016-07-09 11:21:54 +02:00
void* client_data, const char* newValue,
const cmMakefile* mf);
2013-11-03 12:27:13 +02:00
typedef void (*DeleteData)(void* client_data);
cmVariableWatch();
~cmVariableWatch();
/**
* Add watch to the variable
*/
2013-11-03 12:27:13 +02:00
bool AddWatch(const std::string& variable, WatchMethod method,
2018-01-26 17:06:56 +01:00
void* client_data = nullptr, DeleteData delete_data = nullptr);
2013-11-03 12:27:13 +02:00
void RemoveWatch(const std::string& variable, WatchMethod method,
2018-01-26 17:06:56 +01:00
void* client_data = nullptr);
2013-03-16 19:13:01 +02:00
/**
* This method is called when variable is accessed
*/
2016-03-29 18:52:50 +02:00
bool VariableAccessed(const std::string& variable, int access_type,
2016-07-09 11:21:54 +02:00
const char* newValue, const cmMakefile* mf) const;
/**
* Different access types.
*/
enum
2016-07-09 11:21:54 +02:00
{
VARIABLE_READ_ACCESS = 0,
UNKNOWN_VARIABLE_READ_ACCESS,
UNKNOWN_VARIABLE_DEFINED_ACCESS,
VARIABLE_MODIFIED_ACCESS,
VARIABLE_REMOVED_ACCESS,
NO_ACCESS
2016-07-09 11:21:54 +02:00
};
/**
* Return the access as string
*/
static const char* GetAccessAsString(int access_type);
2013-03-16 19:13:01 +02:00
protected:
struct Pair
{
WatchMethod Method;
2016-07-09 11:21:54 +02:00
void* ClientData;
DeleteData DeleteDataCall;
Pair()
2018-01-26 17:06:56 +01:00
: Method(nullptr)
, ClientData(nullptr)
, DeleteDataCall(nullptr)
2016-07-09 11:21:54 +02:00
{
}
2013-11-03 12:27:13 +02:00
~Pair()
2016-07-09 11:21:54 +02:00
{
if (this->DeleteDataCall && this->ClientData) {
2013-11-03 12:27:13 +02:00
this->DeleteDataCall(this->ClientData);
}
2016-07-09 11:21:54 +02:00
}
};
2018-01-26 17:06:56 +01:00
typedef std::vector<std::shared_ptr<Pair>> VectorOfPairs;
2016-07-09 11:21:54 +02:00
typedef std::map<std::string, VectorOfPairs> StringToVectorOfPairs;
StringToVectorOfPairs WatchMap;
};
#endif