mirror of
https://github.com/Kitware/CMake.git
synced 2026-08-05 23:30:25 +00:00
cmVariableWatch: Use enum for access type
Adjust variable watches to pass the access type as the `enum` rather than as an `int`.
This commit is contained in:
@@ -7,16 +7,16 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
std::string const& cmVariableWatch::GetAccessAsString(int access_type)
|
std::string const& cmVariableWatch::GetAccessAsString(AccessType accessType)
|
||||||
{
|
{
|
||||||
static std::array<std::string, 6> const cmVariableWatchAccessStrings = {
|
static std::array<std::string, 6> const cmVariableWatchAccessStrings = {
|
||||||
{ "READ_ACCESS", "UNKNOWN_READ_ACCESS", "UNKNOWN_DEFINED_ACCESS",
|
{ "READ_ACCESS", "UNKNOWN_READ_ACCESS", "UNKNOWN_DEFINED_ACCESS",
|
||||||
"MODIFIED_ACCESS", "REMOVED_ACCESS", "NO_ACCESS" }
|
"MODIFIED_ACCESS", "REMOVED_ACCESS", "NO_ACCESS" }
|
||||||
};
|
};
|
||||||
if (access_type < 0 || access_type >= cmVariableWatch::NO_ACCESS) {
|
if (accessType >= cmVariableWatch::NO_ACCESS) {
|
||||||
access_type = cmVariableWatch::NO_ACCESS;
|
accessType = cmVariableWatch::NO_ACCESS;
|
||||||
}
|
}
|
||||||
return cmVariableWatchAccessStrings[access_type];
|
return cmVariableWatchAccessStrings[accessType];
|
||||||
}
|
}
|
||||||
|
|
||||||
cmVariableWatch::cmVariableWatch() = default;
|
cmVariableWatch::cmVariableWatch() = default;
|
||||||
@@ -63,7 +63,8 @@ void cmVariableWatch::RemoveWatch(std::string const& variable,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool cmVariableWatch::VariableAccessed(std::string const& variable,
|
bool cmVariableWatch::VariableAccessed(std::string const& variable,
|
||||||
int access_type, char const* newValue,
|
AccessType accessType,
|
||||||
|
char const* newValue,
|
||||||
cmMakefile const* mf) const
|
cmMakefile const* mf) const
|
||||||
{
|
{
|
||||||
auto mit = this->WatchMap.find(variable);
|
auto mit = this->WatchMap.find(variable);
|
||||||
@@ -77,7 +78,7 @@ bool cmVariableWatch::VariableAccessed(std::string const& variable,
|
|||||||
// lockable, and so this ensures we don't attempt to call into freed
|
// lockable, and so this ensures we don't attempt to call into freed
|
||||||
// memory
|
// memory
|
||||||
if (auto it = weak_it.lock()) {
|
if (auto it = weak_it.lock()) {
|
||||||
it->Method(variable, access_type, it->ClientData, newValue, mf);
|
it->Method(variable, accessType, it->ClientData, newValue, mf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -19,8 +19,21 @@ class cmMakefile;
|
|||||||
class cmVariableWatch
|
class cmVariableWatch
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using WatchMethod = void (*)(std::string const&, int, void*, char const*,
|
/**
|
||||||
cmMakefile const*);
|
* Different access types.
|
||||||
|
*/
|
||||||
|
enum AccessType : unsigned
|
||||||
|
{
|
||||||
|
VARIABLE_READ_ACCESS,
|
||||||
|
UNKNOWN_VARIABLE_READ_ACCESS,
|
||||||
|
UNKNOWN_VARIABLE_DEFINED_ACCESS,
|
||||||
|
VARIABLE_MODIFIED_ACCESS,
|
||||||
|
VARIABLE_REMOVED_ACCESS,
|
||||||
|
NO_ACCESS
|
||||||
|
};
|
||||||
|
|
||||||
|
using WatchMethod = void (*)(std::string const&, AccessType, void*,
|
||||||
|
char const*, cmMakefile const*);
|
||||||
using DeleteData = void (*)(void*);
|
using DeleteData = void (*)(void*);
|
||||||
|
|
||||||
cmVariableWatch();
|
cmVariableWatch();
|
||||||
@@ -37,26 +50,13 @@ public:
|
|||||||
/**
|
/**
|
||||||
* This method is called when variable is accessed
|
* This method is called when variable is accessed
|
||||||
*/
|
*/
|
||||||
bool VariableAccessed(std::string const& variable, int access_type,
|
bool VariableAccessed(std::string const& variable, AccessType accessType,
|
||||||
char const* newValue, cmMakefile const* mf) const;
|
char const* newValue, cmMakefile const* mf) const;
|
||||||
|
|
||||||
/**
|
|
||||||
* Different access types.
|
|
||||||
*/
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
VARIABLE_READ_ACCESS,
|
|
||||||
UNKNOWN_VARIABLE_READ_ACCESS,
|
|
||||||
UNKNOWN_VARIABLE_DEFINED_ACCESS,
|
|
||||||
VARIABLE_MODIFIED_ACCESS,
|
|
||||||
VARIABLE_REMOVED_ACCESS,
|
|
||||||
NO_ACCESS
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the access as string
|
* Return the access as string
|
||||||
*/
|
*/
|
||||||
static std::string const& GetAccessAsString(int access_type);
|
static std::string const& GetAccessAsString(AccessType accessType);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
struct Pair
|
struct Pair
|
||||||
|
|||||||
@@ -25,20 +25,19 @@ struct cmVariableWatchCallbackData
|
|||||||
std::string Command;
|
std::string Command;
|
||||||
};
|
};
|
||||||
|
|
||||||
void cmVariableWatchCommandVariableAccessed(std::string const& variable,
|
void cmVariableWatchCommandVariableAccessed(
|
||||||
int access_type, void* client_data,
|
std::string const& variable, cmVariableWatch::AccessType accessType,
|
||||||
char const* newValue,
|
void* clientData, char const* newValue, cmMakefile const* mf)
|
||||||
cmMakefile const* mf)
|
|
||||||
{
|
{
|
||||||
cmVariableWatchCallbackData* data =
|
cmVariableWatchCallbackData* data =
|
||||||
static_cast<cmVariableWatchCallbackData*>(client_data);
|
static_cast<cmVariableWatchCallbackData*>(clientData);
|
||||||
|
|
||||||
if (data->InCallback) {
|
if (data->InCallback) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
data->InCallback = true;
|
data->InCallback = true;
|
||||||
|
|
||||||
auto accessString = cmVariableWatch::GetAccessAsString(access_type);
|
auto accessString = cmVariableWatch::GetAccessAsString(accessType);
|
||||||
|
|
||||||
/// Ultra bad!!
|
/// Ultra bad!!
|
||||||
cmMakefile* makefile = const_cast<cmMakefile*>(mf);
|
cmMakefile* makefile = const_cast<cmMakefile*>(mf);
|
||||||
|
|||||||
@@ -166,8 +166,9 @@ using CommandArgument =
|
|||||||
cmCommandLineArgument<bool(std::string const& value, cmake* state)>;
|
cmCommandLineArgument<bool(std::string const& value, cmake* state)>;
|
||||||
|
|
||||||
#ifndef CMAKE_BOOTSTRAP
|
#ifndef CMAKE_BOOTSTRAP
|
||||||
void cmWarnUnusedCliWarning(std::string const& variable, int /*unused*/,
|
void cmWarnUnusedCliWarning(std::string const& variable,
|
||||||
void* ctx, char const* /*unused*/,
|
cmVariableWatch::AccessType /*unused*/, void* ctx,
|
||||||
|
char const* /*unused*/,
|
||||||
cmMakefile const* /*unused*/)
|
cmMakefile const* /*unused*/)
|
||||||
{
|
{
|
||||||
cmake* cm = reinterpret_cast<cmake*>(ctx);
|
cmake* cm = reinterpret_cast<cmake*>(ctx);
|
||||||
|
|||||||
Reference in New Issue
Block a user