variable_watch: Allow specifying the data to match in RemoveWatch

Now that watches are dependent on their client_data when adding, it also
makes sense to allow matching the data for removal.
This commit is contained in:
Ben Boeckel 2013-08-06 14:12:54 -04:00 committed by Brad King
parent e43e207c7b
commit 34b397e8de
2 changed files with 8 additions and 3 deletions

View File

@ -77,13 +77,17 @@ bool cmVariableWatch::AddWatch(const std::string& variable,
} }
void cmVariableWatch::RemoveWatch(const std::string& variable, void cmVariableWatch::RemoveWatch(const std::string& variable,
WatchMethod method) WatchMethod method,
void* client_data /*=0*/)
{ {
cmVariableWatch::VectorOfPairs* vp = &this->WatchMap[variable]; cmVariableWatch::VectorOfPairs* vp = &this->WatchMap[variable];
cmVariableWatch::VectorOfPairs::iterator it; cmVariableWatch::VectorOfPairs::iterator it;
for ( it = vp->begin(); it != vp->end(); ++it ) for ( it = vp->begin(); it != vp->end(); ++it )
{ {
if ( (*it)->Method == method ) if ( (*it)->Method == method &&
// If client_data is NULL, we want to disconnect all watches against
// the given method; otherwise match ClientData as well.
(!client_data || (client_data == (*it)->ClientData)))
{ {
delete *it; delete *it;
vp->erase(it); vp->erase(it);

View File

@ -36,7 +36,8 @@ public:
*/ */
bool AddWatch(const std::string& variable, WatchMethod method, bool AddWatch(const std::string& variable, WatchMethod method,
void* client_data=0, DeleteData delete_data=0); void* client_data=0, DeleteData delete_data=0);
void RemoveWatch(const std::string& variable, WatchMethod method); void RemoveWatch(const std::string& variable, WatchMethod method,
void* client_data=0);
/** /**
* This method is called when variable is accessed * This method is called when variable is accessed