cmDefinitions.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 std::string& key);
  32. /** Set (or unset if null) a value associated with a key. */
  33. const char* Set(const std::string& key, const char* value);
  34. /** Get the set of all local keys. */
  35. std::set<std::string> 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<std::string> ClosureKeys() const;
  41. private:
  42. // String with existence boolean.
  43. struct Def: public std::string
  44. {
  45. private:
  46. typedef std::string std_string;
  47. public:
  48. Def(): std_string(), Exists(false) {}
  49. Def(const char* v): std_string(v?v:""), Exists(v?true:false) {}
  50. Def(const std_string& v): std_string(v), Exists(true) {}
  51. Def(Def const& d): std_string(d), Exists(d.Exists) {}
  52. bool Exists;
  53. };
  54. static Def NoDef;
  55. // Parent scope, if any.
  56. cmDefinitions* Up;
  57. // Local definitions, set or unset.
  58. typedef std::map<std::string, Def> MapType;
  59. MapType Map;
  60. // Internal query and update methods.
  61. Def const& GetInternal(const std::string& key);
  62. Def const& SetInternal(const std::string& key, Def const& def);
  63. // Implementation of Closure() method.
  64. struct ClosureTag {};
  65. cmDefinitions(ClosureTag const&, cmDefinitions const* root);
  66. void ClosureImpl(std::set<std::string>& undefined,
  67. cmDefinitions const* defs);
  68. // Implementation of ClosureKeys() method.
  69. void ClosureKeys(std::set<std::string>& defined,
  70. std::set<std::string>& undefined) const;
  71. };
  72. #endif