1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #include "cmVariableWatch.h"
14 static const char* const cmVariableWatchAccessStrings[] =
17 "UNKNOWN_READ_ACCESS",
18 "UNKNOWN_DEFINED_ACCESS",
19 "ALLOWED_UNKNOWN_READ_ACCESS",
25 const char* cmVariableWatch::GetAccessAsString(int access_type)
27 if ( access_type < 0 || access_type >= cmVariableWatch::NO_ACCESS )
31 return cmVariableWatchAccessStrings[access_type];
34 cmVariableWatch::cmVariableWatch()
38 cmVariableWatch::~cmVariableWatch()
40 cmVariableWatch::StringToVectorOfPairs::iterator svp_it;
42 for ( svp_it = this->WatchMap.begin();
43 svp_it != this->WatchMap.end(); ++svp_it )
45 cmVariableWatch::VectorOfPairs::iterator p_it;
47 for ( p_it = svp_it->second.begin();
48 p_it != svp_it->second.end(); ++p_it )
55 bool cmVariableWatch::AddWatch(const std::string& variable,
56 WatchMethod method, void* client_data /*=0*/,
57 DeleteData delete_data /*=0*/)
59 cmVariableWatch::Pair* p = new cmVariableWatch::Pair;
61 p->ClientData = client_data;
62 p->DeleteDataCall = delete_data;
63 cmVariableWatch::VectorOfPairs* vp = &this->WatchMap[variable];
64 cmVariableWatch::VectorOfPairs::size_type cc;
65 for ( cc = 0; cc < vp->size(); cc ++ )
67 cmVariableWatch::Pair* pair = (*vp)[cc];
68 if ( pair->Method == method &&
69 client_data && client_data == pair->ClientData)
71 // Callback already exists
79 void cmVariableWatch::RemoveWatch(const std::string& variable,
81 void* client_data /*=0*/)
83 if ( !this->WatchMap.count(variable) )
87 cmVariableWatch::VectorOfPairs* vp = &this->WatchMap[variable];
88 cmVariableWatch::VectorOfPairs::iterator it;
89 for ( it = vp->begin(); it != vp->end(); ++it )
91 if ( (*it)->Method == method &&
92 // If client_data is NULL, we want to disconnect all watches against
93 // the given method; otherwise match ClientData as well.
94 (!client_data || (client_data == (*it)->ClientData)))
103 void cmVariableWatch::VariableAccessed(const std::string& variable,
105 const char* newValue,
106 const cmMakefile* mf) const
108 cmVariableWatch::StringToVectorOfPairs::const_iterator mit =
109 this->WatchMap.find(variable);
110 if ( mit != this->WatchMap.end() )
112 const cmVariableWatch::VectorOfPairs* vp = &mit->second;
113 cmVariableWatch::VectorOfPairs::const_iterator it;
114 for ( it = vp->begin(); it != vp->end(); it ++ )
116 (*it)->Method(variable, access_type, (*it)->ClientData,