cmDefinitions.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. /** Compute the closure of all defined keys with values.
  35. This flattens the scope. The result has no parent. */
  36. cmDefinitions Closure() const;
  37. /** Compute the set of all defined keys. */
  38. std::set<cmStdString> ClosureKeys() const;
  39. private:
  40. // String with existence boolean.
  41. struct Def: public cmStdString
  42. {
  43. Def(): cmStdString(), Exists(false) {}
  44. Def(const char* v): cmStdString(v?v:""), Exists(v?true:false) {}
  45. Def(Def const& d): cmStdString(d), Exists(d.Exists) {}
  46. bool Exists;
  47. };
  48. static Def NoDef;
  49. // Parent scope, if any.
  50. cmDefinitions* Up;
  51. // Local definitions, set or unset.
  52. typedef std::map<cmStdString, Def> MapType;
  53. MapType Map;
  54. // Internal query and update methods.
  55. Def const& GetInternal(const char* key);
  56. Def const& SetInternal(const char* key, Def const& def);
  57. // Implementation of Closure() method.
  58. struct ClosureTag {};
  59. cmDefinitions(ClosureTag const&, cmDefinitions const* root);
  60. void ClosureImpl(std::set<cmStdString>& undefined,
  61. cmDefinitions const* defs);
  62. // Implementation of ClosureKeys() method.
  63. void ClosureKeys(std::set<cmStdString>& defined,
  64. std::set<cmStdString>& undefined) const;
  65. };
  66. #endif