cmVariableWatch.h 1.9 KB

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