You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.7 KiB

  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. static const char* const cmVariableWatchAccessStrings[] =
  15. {
  16. "READ_ACCESS",
  17. "UNKNOWN_READ_ACCESS",
  18. "ALLOWED_UNKNOWN_READ_ACCESS",
  19. "MODIFIED_ACCESS",
  20. "REMOVED_ACCESS",
  21. "NO_ACCESS"
  22. };
  23. const char* cmVariableWatch::GetAccessAsString(int access_type)
  24. {
  25. if ( access_type < 0 || access_type >= cmVariableWatch::NO_ACCESS )
  26. {
  27. return "NO_ACCESS";
  28. }
  29. return cmVariableWatchAccessStrings[access_type];
  30. }
  31. cmVariableWatch::cmVariableWatch()
  32. {
  33. }
  34. cmVariableWatch::~cmVariableWatch()
  35. {
  36. }
  37. void cmVariableWatch::AddWatch(const std::string& variable,
  38. WatchMethod method, void* client_data /*=0*/)
  39. {
  40. cmVariableWatch::Pair p;
  41. p.Method = method;
  42. p.ClientData = client_data;
  43. cmVariableWatch::VectorOfPairs* vp = &this->WatchMap[variable];
  44. cmVariableWatch::VectorOfPairs::size_type cc;
  45. for ( cc = 0; cc < vp->size(); cc ++ )
  46. {
  47. cmVariableWatch::Pair* pair = &(*vp)[cc];
  48. if ( pair->Method == method )
  49. {
  50. (*vp)[cc] = p;
  51. return;
  52. }
  53. }
  54. vp->push_back(p);
  55. }
  56. void cmVariableWatch::RemoveWatch(const std::string& variable,
  57. WatchMethod method)
  58. {
  59. cmVariableWatch::VectorOfPairs* vp = &this->WatchMap[variable];
  60. cmVariableWatch::VectorOfPairs::iterator it;
  61. for ( it = vp->begin(); it != vp->end(); ++it )
  62. {
  63. if ( it->Method == method )
  64. {
  65. vp->erase(it);
  66. return;
  67. }
  68. }
  69. }
  70. void cmVariableWatch::VariableAccessed(const std::string& variable,
  71. int access_type,
  72. const char* newValue,
  73. const cmMakefile* mf) const
  74. {
  75. cmVariableWatch::StringToVectorOfPairs::const_iterator mit =
  76. this->WatchMap.find(variable);
  77. if ( mit != this->WatchMap.end() )
  78. {
  79. const cmVariableWatch::VectorOfPairs* vp = &mit->second;
  80. cmVariableWatch::VectorOfPairs::const_iterator it;
  81. for ( it = vp->begin(); it != vp->end(); it ++ )
  82. {
  83. it->Method(variable, access_type, it->ClientData,
  84. newValue, mf);
  85. }
  86. }
  87. }