cmVariableWatch.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #ifndef cmVariableWatch_h
  11. #define cmVariableWatch_h
  12. #include "cmStandardIncludes.h"
  13. class cmMakefile;
  14. /** \class cmVariableWatch
  15. * \brief Helper class for watching of variable accesses.
  16. *
  17. * Calls function when variable is accessed
  18. */
  19. class cmVariableWatch
  20. {
  21. public:
  22. typedef void (*WatchMethod)(const std::string& variable, int access_type,
  23. void* client_data, const char* newValue, const cmMakefile* mf);
  24. cmVariableWatch();
  25. ~cmVariableWatch();
  26. /**
  27. * Add watch to the variable
  28. */
  29. void AddWatch(const std::string& variable, WatchMethod method,
  30. 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,
  36. const char* newValue, const cmMakefile* mf) const;
  37. /**
  38. * Different access types.
  39. */
  40. enum
  41. {
  42. VARIABLE_READ_ACCESS = 0,
  43. UNKNOWN_VARIABLE_READ_ACCESS,
  44. UNKNOWN_VARIABLE_DEFINED_ACCESS,
  45. ALLOWED_UNKNOWN_VARIABLE_READ_ACCESS,
  46. VARIABLE_MODIFIED_ACCESS,
  47. VARIABLE_REMOVED_ACCESS,
  48. NO_ACCESS
  49. };
  50. /**
  51. * Return the access as string
  52. */
  53. static const char* GetAccessAsString(int access_type);
  54. protected:
  55. struct Pair
  56. {
  57. WatchMethod Method;
  58. void* ClientData;
  59. Pair() : Method(0), ClientData(0) {}
  60. };
  61. typedef std::vector< Pair > VectorOfPairs;
  62. typedef std::map<cmStdString, VectorOfPairs > StringToVectorOfPairs;
  63. StringToVectorOfPairs WatchMap;
  64. };
  65. #endif