cmVariableWatch.cxx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmVariableWatch.h"
  14. cmVariableWatch::cmVariableWatch()
  15. {
  16. }
  17. cmVariableWatch::~cmVariableWatch()
  18. {
  19. }
  20. void cmVariableWatch::AddWatch(const std::string& variable,
  21. WatchMethod method, void* client_data /*=0*/)
  22. {
  23. cmVariableWatch::Pair p;
  24. p.Method = method;
  25. p.ClientData = client_data;
  26. cmVariableWatch::VectorOfPairs* vp = &this->WatchMap[variable];
  27. cmVariableWatch::VectorOfPairs::size_type cc;
  28. for ( cc = 0; cc < vp->size(); cc ++ )
  29. {
  30. cmVariableWatch::Pair* pair = &(*vp)[cc];
  31. if ( pair->Method == method )
  32. {
  33. (*vp)[cc] = p;
  34. return;
  35. }
  36. }
  37. vp->push_back(p);
  38. }
  39. void cmVariableWatch::RemoveWatch(const std::string& variable,
  40. WatchMethod method)
  41. {
  42. cmVariableWatch::VectorOfPairs* vp = &this->WatchMap[variable];
  43. cmVariableWatch::VectorOfPairs::iterator it;
  44. for ( it = vp->begin(); it != vp->end(); ++it )
  45. {
  46. if ( it->Method == method )
  47. {
  48. vp->erase(it);
  49. return;
  50. }
  51. }
  52. }
  53. void cmVariableWatch::VariableAccessed(const std::string& variable,
  54. int access_type) const
  55. {
  56. cmVariableWatch::StringToVectorOfPairs::const_iterator mit =
  57. this->WatchMap.find(variable);
  58. if ( mit != this->WatchMap.end() )
  59. {
  60. const cmVariableWatch::VectorOfPairs* vp = &mit->second;
  61. cmVariableWatch::VectorOfPairs::const_iterator it;
  62. for ( it = vp->begin(); it != vp->end(); it ++ )
  63. {
  64. it->Method(variable, access_type, it->ClientData);
  65. }
  66. }
  67. }