cmVariableWatch.cxx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmVariableWatch.h"
  11. static const char* const cmVariableWatchAccessStrings[] =
  12. {
  13. "READ_ACCESS",
  14. "UNKNOWN_READ_ACCESS",
  15. "ALLOWED_UNKNOWN_READ_ACCESS",
  16. "MODIFIED_ACCESS",
  17. "REMOVED_ACCESS",
  18. "NO_ACCESS"
  19. };
  20. const char* cmVariableWatch::GetAccessAsString(int access_type)
  21. {
  22. if ( access_type < 0 || access_type >= cmVariableWatch::NO_ACCESS )
  23. {
  24. return "NO_ACCESS";
  25. }
  26. return cmVariableWatchAccessStrings[access_type];
  27. }
  28. cmVariableWatch::cmVariableWatch()
  29. {
  30. }
  31. cmVariableWatch::~cmVariableWatch()
  32. {
  33. }
  34. void cmVariableWatch::AddWatch(const std::string& variable,
  35. WatchMethod method, void* client_data /*=0*/)
  36. {
  37. cmVariableWatch::Pair p;
  38. p.Method = method;
  39. p.ClientData = client_data;
  40. cmVariableWatch::VectorOfPairs* vp = &this->WatchMap[variable];
  41. cmVariableWatch::VectorOfPairs::size_type cc;
  42. for ( cc = 0; cc < vp->size(); cc ++ )
  43. {
  44. cmVariableWatch::Pair* pair = &(*vp)[cc];
  45. if ( pair->Method == method )
  46. {
  47. (*vp)[cc] = p;
  48. return;
  49. }
  50. }
  51. vp->push_back(p);
  52. }
  53. void cmVariableWatch::RemoveWatch(const std::string& variable,
  54. WatchMethod method)
  55. {
  56. cmVariableWatch::VectorOfPairs* vp = &this->WatchMap[variable];
  57. cmVariableWatch::VectorOfPairs::iterator it;
  58. for ( it = vp->begin(); it != vp->end(); ++it )
  59. {
  60. if ( it->Method == method )
  61. {
  62. vp->erase(it);
  63. return;
  64. }
  65. }
  66. }
  67. void cmVariableWatch::VariableAccessed(const std::string& variable,
  68. int access_type,
  69. const char* newValue,
  70. const cmMakefile* mf) const
  71. {
  72. cmVariableWatch::StringToVectorOfPairs::const_iterator mit =
  73. this->WatchMap.find(variable);
  74. if ( mit != this->WatchMap.end() )
  75. {
  76. const cmVariableWatch::VectorOfPairs* vp = &mit->second;
  77. cmVariableWatch::VectorOfPairs::const_iterator it;
  78. for ( it = vp->begin(); it != vp->end(); it ++ )
  79. {
  80. it->Method(variable, access_type, it->ClientData,
  81. newValue, mf);
  82. }
  83. }
  84. }