cmVariableWatch.h 1.8 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. #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, void* client_data);
  25. cmVariableWatch();
  26. ~cmVariableWatch();
  27. /**
  28. * Add watch to the variable
  29. */
  30. void AddWatch(const std::string& variable, WatchMethod method, void* client_data=0);
  31. /**
  32. * This method is called when variable is accessed
  33. */
  34. void VariableAccessed(const std::string& variable, int access_type) const;
  35. /**
  36. * Different access types.
  37. */
  38. enum
  39. {
  40. VARIABLE_READ_ACCESS,
  41. UNKNOWN_VARIABLE_READ_ACCESS,
  42. ALLOWED_UNKNOWN_VARIABLE_READ_ACCESS,
  43. VARIABLE_MODIFIED_ACCESS,
  44. VARIABLE_REMOVED_ACCESS,
  45. NO_ACCESS
  46. };
  47. protected:
  48. struct Pair
  49. {
  50. WatchMethod m_Method;
  51. void* m_ClientData;
  52. Pair() : m_Method(0), m_ClientData(0) {}
  53. };
  54. typedef std::vector< Pair > VectorOfPairs;
  55. typedef std::map<cmStdString, VectorOfPairs > StringToVectorOfPairs;
  56. StringToVectorOfPairs m_WatchMap;
  57. };
  58. #endif