cmVariableWatch.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. typedef void (*DeleteData)(void* client_data);
  25. cmVariableWatch();
  26. ~cmVariableWatch();
  27. /**
  28. * Add watch to the variable
  29. */
  30. bool AddWatch(const std::string& variable, WatchMethod method,
  31. void* client_data=0, DeleteData delete_data=0);
  32. void RemoveWatch(const std::string& variable, WatchMethod method);
  33. /**
  34. * This method is called when variable is accessed
  35. */
  36. void VariableAccessed(const std::string& variable, int access_type,
  37. const char* newValue, const cmMakefile* mf) const;
  38. /**
  39. * Different access types.
  40. */
  41. enum
  42. {
  43. VARIABLE_READ_ACCESS = 0,
  44. UNKNOWN_VARIABLE_READ_ACCESS,
  45. UNKNOWN_VARIABLE_DEFINED_ACCESS,
  46. ALLOWED_UNKNOWN_VARIABLE_READ_ACCESS,
  47. VARIABLE_MODIFIED_ACCESS,
  48. VARIABLE_REMOVED_ACCESS,
  49. NO_ACCESS
  50. };
  51. /**
  52. * Return the access as string
  53. */
  54. static const char* GetAccessAsString(int access_type);
  55. protected:
  56. struct Pair
  57. {
  58. WatchMethod Method;
  59. void* ClientData;
  60. DeleteData DeleteDataCall;
  61. Pair() : Method(0), ClientData(0), DeleteDataCall(0) {}
  62. ~Pair()
  63. {
  64. if (this->DeleteDataCall && this->ClientData)
  65. {
  66. this->DeleteDataCall(this->ClientData);
  67. }
  68. }
  69. };
  70. typedef std::vector< Pair* > VectorOfPairs;
  71. typedef std::map<cmStdString, VectorOfPairs > StringToVectorOfPairs;
  72. StringToVectorOfPairs WatchMap;
  73. };
  74. #endif