mirror of
https://github.com/Kitware/CMake.git
synced 2026-08-04 14:50:23 +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 <vector>
|
||||
|
||||
std::string const& cmVariableWatch::GetAccessAsString(int access_type)
|
||||
std::string const& cmVariableWatch::GetAccessAsString(AccessType accessType)
|
||||
{
|
||||
static std::array<std::string, 6> const cmVariableWatchAccessStrings = {
|
||||
{ "READ_ACCESS", "UNKNOWN_READ_ACCESS", "UNKNOWN_DEFINED_ACCESS",
|
||||
"MODIFIED_ACCESS", "REMOVED_ACCESS", "NO_ACCESS" }
|
||||
};
|
||||
if (access_type < 0 || access_type >= cmVariableWatch::NO_ACCESS) {
|
||||
access_type = cmVariableWatch::NO_ACCESS;
|
||||
if (accessType >= cmVariableWatch::NO_ACCESS) {
|
||||
accessType = cmVariableWatch::NO_ACCESS;
|
||||
}
|
||||
return cmVariableWatchAccessStrings[access_type];
|
||||
return cmVariableWatchAccessStrings[accessType];
|
||||
}
|
||||
|
||||
cmVariableWatch::cmVariableWatch() = default;
|
||||
@@ -63,7 +63,8 @@ void cmVariableWatch::RemoveWatch(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
|
||||
{
|
||||
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
|
||||
// memory
|
||||
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;
|
||||
|
||||
@@ -19,8 +19,21 @@ class cmMakefile;
|
||||
class cmVariableWatch
|
||||
{
|
||||
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*);
|
||||
|
||||
cmVariableWatch();
|
||||
@@ -37,26 +50,13 @@ public:
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
static std::string const& GetAccessAsString(int access_type);
|
||||
static std::string const& GetAccessAsString(AccessType accessType);
|
||||
|
||||
protected:
|
||||
struct Pair
|
||||
|
||||
@@ -25,20 +25,19 @@ struct cmVariableWatchCallbackData
|
||||
std::string Command;
|
||||
};
|
||||
|
||||
void cmVariableWatchCommandVariableAccessed(std::string const& variable,
|
||||
int access_type, void* client_data,
|
||||
char const* newValue,
|
||||
cmMakefile const* mf)
|
||||
void cmVariableWatchCommandVariableAccessed(
|
||||
std::string const& variable, cmVariableWatch::AccessType accessType,
|
||||
void* clientData, char const* newValue, cmMakefile const* mf)
|
||||
{
|
||||
cmVariableWatchCallbackData* data =
|
||||
static_cast<cmVariableWatchCallbackData*>(client_data);
|
||||
static_cast<cmVariableWatchCallbackData*>(clientData);
|
||||
|
||||
if (data->InCallback) {
|
||||
return;
|
||||
}
|
||||
data->InCallback = true;
|
||||
|
||||
auto accessString = cmVariableWatch::GetAccessAsString(access_type);
|
||||
auto accessString = cmVariableWatch::GetAccessAsString(accessType);
|
||||
|
||||
/// Ultra bad!!
|
||||
cmMakefile* makefile = const_cast<cmMakefile*>(mf);
|
||||
|
||||
@@ -166,8 +166,9 @@ using CommandArgument =
|
||||
cmCommandLineArgument<bool(std::string const& value, cmake* state)>;
|
||||
|
||||
#ifndef CMAKE_BOOTSTRAP
|
||||
void cmWarnUnusedCliWarning(std::string const& variable, int /*unused*/,
|
||||
void* ctx, char const* /*unused*/,
|
||||
void cmWarnUnusedCliWarning(std::string const& variable,
|
||||
cmVariableWatch::AccessType /*unused*/, void* ctx,
|
||||
char const* /*unused*/,
|
||||
cmMakefile const* /*unused*/)
|
||||
{
|
||||
cmake* cm = reinterpret_cast<cmake*>(ctx);
|
||||
|
||||
Reference in New Issue
Block a user