cmDefinitions.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmDefinitions_h
  4. #define cmDefinitions_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include <string>
  7. #include <unordered_map>
  8. #include <vector>
  9. #include "cmLinkedTree.h"
  10. /** \class cmDefinitions
  11. * \brief Store a scope of variable definitions for CMake language.
  12. *
  13. * This stores the state of variable definitions (set or unset) for
  14. * one scope. Sets are always local. Gets search parent scopes
  15. * transitively and save results locally.
  16. */
  17. class cmDefinitions
  18. {
  19. typedef cmLinkedTree<cmDefinitions>::iterator StackIter;
  20. public:
  21. static const std::string* Get(const std::string& key, StackIter begin,
  22. StackIter end);
  23. static void Raise(const std::string& key, StackIter begin, StackIter end);
  24. static bool HasKey(const std::string& key, StackIter begin, StackIter end);
  25. /** Set (or unset if null) a value associated with a key. */
  26. void Set(const std::string& key, const char* value);
  27. std::vector<std::string> UnusedKeys() const;
  28. static std::vector<std::string> ClosureKeys(StackIter begin, StackIter end);
  29. static cmDefinitions MakeClosure(StackIter begin, StackIter end);
  30. private:
  31. // String with existence boolean.
  32. struct Def : public std::string
  33. {
  34. private:
  35. typedef std::string std_string;
  36. public:
  37. Def() = default;
  38. Def(const char* v)
  39. : std_string(v ? v : "")
  40. , Exists(v ? true : false)
  41. {
  42. }
  43. Def(const std_string& v)
  44. : std_string(v)
  45. , Exists(true)
  46. {
  47. }
  48. bool Exists = false;
  49. bool Used = false;
  50. };
  51. static Def NoDef;
  52. typedef std::unordered_map<std::string, Def> MapType;
  53. MapType Map;
  54. static Def const& GetInternal(const std::string& key, StackIter begin,
  55. StackIter end, bool raise);
  56. };
  57. #endif