cmDefinitions.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 cmDefinitions_h
  11. #define cmDefinitions_h
  12. #include "cmStandardIncludes.h"
  13. /** \class cmDefinitions
  14. * \brief Store a scope of variable definitions for CMake language.
  15. *
  16. * This stores the state of variable definitions (set or unset) for
  17. * one scope. Sets are always local. Gets search parent scopes
  18. * transitively and save results locally.
  19. */
  20. class cmDefinitions
  21. {
  22. public:
  23. /** Construct with the given parent scope. */
  24. cmDefinitions(cmDefinitions* parent = 0);
  25. /** Reset object as if newly constructed. */
  26. void Reset(cmDefinitions* parent = 0);
  27. /** Returns the parent scope, if any. */
  28. cmDefinitions* GetParent() const { return this->Up; }
  29. /** Get the value associated with a key; null if none.
  30. Store the result locally if it came from a parent. */
  31. const char* Get(const char* key);
  32. /** Set (or unset if null) a value associated with a key. */
  33. const char* Set(const char* key, const char* value);
  34. /** Get the set of all local keys. */
  35. std::set<cmStdString> LocalKeys() const;
  36. /** Compute the closure of all defined keys with values.
  37. This flattens the scope. The result has no parent. */
  38. cmDefinitions Closure() const;
  39. /** Compute the set of all defined keys. */
  40. std::set<cmStdString> ClosureKeys() const;
  41. private:
  42. // String with existence boolean.
  43. struct Def: public cmStdString
  44. {
  45. Def(): cmStdString(), Exists(false) {}
  46. Def(const char* v): cmStdString(v?v:""), Exists(v?true:false) {}
  47. Def(Def const& d): cmStdString(d), Exists(d.Exists) {}
  48. bool Exists;
  49. };
  50. static Def NoDef;
  51. // Parent scope, if any.
  52. cmDefinitions* Up;
  53. // Local definitions, set or unset.
  54. typedef std::map<cmStdString, Def> MapType;
  55. MapType Map;
  56. // Internal query and update methods.
  57. Def const& GetInternal(const char* key);
  58. Def const& SetInternal(const char* key, Def const& def);
  59. // Implementation of Closure() method.
  60. struct ClosureTag {};
  61. cmDefinitions(ClosureTag const&, cmDefinitions const* root);
  62. void ClosureImpl(std::set<cmStdString>& undefined,
  63. cmDefinitions const* defs);
  64. // Implementation of ClosureKeys() method.
  65. void ClosureKeys(std::set<cmStdString>& defined,
  66. std::set<cmStdString>& undefined) const;
  67. };
  68. #endif