ENH: check in almost building VMS stuff with VMSBuild directory since the bootstrap...
[cmake.git] / Source / cmVariableWatch.cxx
blobbd4cf4560de11fe9d4c5ca949139f2d6546bb1ea
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmVariableWatch.cxx,v $
5 Language: C++
6 Date: $Date: 2007-04-11 19:13:05 $
7 Version: $Revision: 1.5 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmVariableWatch.h"
19 static const char* const cmVariableWatchAccessStrings[] =
21 "READ_ACCESS",
22 "UNKNOWN_READ_ACCESS",
23 "ALLOWED_UNKNOWN_READ_ACCESS",
24 "MODIFIED_ACCESS",
25 "REMOVED_ACCESS",
26 "NO_ACCESS"
29 const char* cmVariableWatch::GetAccessAsString(int access_type)
31 if ( access_type < 0 || access_type >= cmVariableWatch::NO_ACCESS )
33 return "NO_ACCESS";
35 return cmVariableWatchAccessStrings[access_type];
38 cmVariableWatch::cmVariableWatch()
42 cmVariableWatch::~cmVariableWatch()
46 void cmVariableWatch::AddWatch(const std::string& variable,
47 WatchMethod method, void* client_data /*=0*/)
49 cmVariableWatch::Pair p;
50 p.Method = method;
51 p.ClientData = client_data;
52 cmVariableWatch::VectorOfPairs* vp = &this->WatchMap[variable];
53 cmVariableWatch::VectorOfPairs::size_type cc;
54 for ( cc = 0; cc < vp->size(); cc ++ )
56 cmVariableWatch::Pair* pair = &(*vp)[cc];
57 if ( pair->Method == method )
59 (*vp)[cc] = p;
60 return;
63 vp->push_back(p);
66 void cmVariableWatch::RemoveWatch(const std::string& variable,
67 WatchMethod method)
69 cmVariableWatch::VectorOfPairs* vp = &this->WatchMap[variable];
70 cmVariableWatch::VectorOfPairs::iterator it;
71 for ( it = vp->begin(); it != vp->end(); ++it )
73 if ( it->Method == method )
75 vp->erase(it);
76 return;
81 void cmVariableWatch::VariableAccessed(const std::string& variable,
82 int access_type,
83 const char* newValue,
84 const cmMakefile* mf) const
86 cmVariableWatch::StringToVectorOfPairs::const_iterator mit =
87 this->WatchMap.find(variable);
88 if ( mit != this->WatchMap.end() )
90 const cmVariableWatch::VectorOfPairs* vp = &mit->second;
91 cmVariableWatch::VectorOfPairs::const_iterator it;
92 for ( it = vp->begin(); it != vp->end(); it ++ )
94 it->Method(variable, access_type, it->ClientData,
95 newValue, mf);