cmVariableWatch.h 1.9 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. #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,
  32. void* client_data=0);
  33. void RemoveWatch(const std::string& variable, WatchMethod method);
  34. /**
  35. * This method is called when variable is accessed
  36. */
  37. void VariableAccessed(const std::string& variable, int access_type) const;
  38. /**
  39. * Different access types.
  40. */
  41. enum
  42. {
  43. VARIABLE_READ_ACCESS,
  44. UNKNOWN_VARIABLE_READ_ACCESS,
  45. ALLOWED_UNKNOWN_VARIABLE_READ_ACCESS,
  46. VARIABLE_MODIFIED_ACCESS,
  47. VARIABLE_REMOVED_ACCESS,
  48. NO_ACCESS
  49. };
  50. protected:
  51. struct Pair
  52. {
  53. WatchMethod Method;
  54. void* ClientData;
  55. Pair() : Method(0), ClientData(0) {}
  56. };
  57. typedef std::vector< Pair > VectorOfPairs;
  58. typedef std::map<cmStdString, VectorOfPairs > StringToVectorOfPairs;
  59. StringToVectorOfPairs WatchMap;
  60. };
  61. #endif