cmDefinitions.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <functional>
  6. #include <string>
  7. #include <unordered_map>
  8. #include <vector>
  9. #include <cm/string_view>
  10. #include "cmLinkedTree.h"
  11. #include "cmProperty.h"
  12. #include "cmString.hxx"
  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. using StackIter = cmLinkedTree<cmDefinitions>::iterator;
  23. public:
  24. // -- Static member functions
  25. static cmProp Get(const std::string& key, StackIter begin, StackIter end);
  26. static void Raise(const std::string& key, StackIter begin, StackIter end);
  27. static bool HasKey(const std::string& key, StackIter begin, StackIter end);
  28. static std::vector<std::string> ClosureKeys(StackIter begin, StackIter end);
  29. static cmDefinitions MakeClosure(StackIter begin, StackIter end);
  30. // -- Member functions
  31. /** Set a value associated with a key. */
  32. void Set(const std::string& key, cm::string_view value);
  33. /** Unset a definition. */
  34. void Unset(const std::string& key);
  35. private:
  36. /** String with existence boolean. */
  37. struct Def
  38. {
  39. public:
  40. Def() = default;
  41. Def(cm::string_view value)
  42. : Value(value)
  43. {
  44. }
  45. cm::String Value;
  46. };
  47. static Def NoDef;
  48. std::unordered_map<cm::String, Def> Map;
  49. static Def const& GetInternal(const std::string& key, StackIter begin,
  50. StackIter end, bool raise);
  51. };