cmVariableWatch.h 2.1 KB

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