cmVariableWatch.cxx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.m_Method = method;
  25. p.m_ClientData = client_data;
  26. cmVariableWatch::VectorOfPairs* vp = &m_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->m_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, WatchMethod method)
  40. {
  41. cmVariableWatch::VectorOfPairs* vp = &m_WatchMap[variable];
  42. cmVariableWatch::VectorOfPairs::iterator it;
  43. for ( it = vp->begin(); it != vp->end(); ++it )
  44. {
  45. if ( it->m_Method == method )
  46. {
  47. vp->erase(it);
  48. return;
  49. }
  50. }
  51. }
  52. void cmVariableWatch::VariableAccessed(const std::string& variable, int access_type) const
  53. {
  54. cmVariableWatch::StringToVectorOfPairs::const_iterator mit = m_WatchMap.find(variable);
  55. if ( mit != m_WatchMap.end() )
  56. {
  57. const cmVariableWatch::VectorOfPairs* vp = &mit->second;
  58. cmVariableWatch::VectorOfPairs::const_iterator it;
  59. for ( it = vp->begin(); it != vp->end(); it ++ )
  60. {
  61. it->m_Method(variable, access_type, it->m_ClientData);
  62. }
  63. }
  64. }