cmVariableWatch.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #ifndef cmVariableWatch_h
  14. #define cmVariableWatch_h
  15. #include "cmStandardIncludes.h"
  16. /** \class cmVariableWatch
  17. * \brief Helper class for watching of variable accesses.
  18. *
  19. * Calls function when variable is accessed
  20. */
  21. class cmVariableWatch
  22. {
  23. public:
  24. typedef void (*WatchMethod)(const std::string& variable, int access_type,
  25. void* client_data);
  26. cmVariableWatch();
  27. ~cmVariableWatch();
  28. /**
  29. * Add watch to the variable
  30. */
  31. void AddWatch(const std::string& variable, WatchMethod method, void* client_data=0);
  32. void RemoveWatch(const std::string& variable, WatchMethod method);
  33. /**
  34. * This method is called when variable is accessed
  35. */
  36. void VariableAccessed(const std::string& variable, int access_type) const;
  37. /**
  38. * Different access types.
  39. */
  40. enum
  41. {
  42. VARIABLE_READ_ACCESS,
  43. UNKNOWN_VARIABLE_READ_ACCESS,
  44. ALLOWED_UNKNOWN_VARIABLE_READ_ACCESS,
  45. VARIABLE_MODIFIED_ACCESS,
  46. VARIABLE_REMOVED_ACCESS,
  47. NO_ACCESS
  48. };
  49. protected:
  50. struct Pair
  51. {
  52. WatchMethod m_Method;
  53. void* m_ClientData;
  54. Pair() : m_Method(0), m_ClientData(0) {}
  55. };
  56. typedef std::vector< Pair > VectorOfPairs;
  57. typedef std::map<cmStdString, VectorOfPairs > StringToVectorOfPairs;
  58. StringToVectorOfPairs m_WatchMap;
  59. };
  60. #endif