cmDefinitions.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 <functional>
  7. #include <string>
  8. #include <unordered_map>
  9. #include <vector>
  10. #include <cm/string_view>
  11. #include "cmLinkedTree.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 const std::string* Get(const std::string& key, StackIter begin,
  26. StackIter end);
  27. static void Raise(const std::string& key, StackIter begin, StackIter end);
  28. static bool HasKey(const std::string& key, StackIter begin, StackIter end);
  29. static std::vector<std::string> ClosureKeys(StackIter begin, StackIter end);
  30. static cmDefinitions MakeClosure(StackIter begin, StackIter end);
  31. // -- Member functions
  32. /** Set a value associated with a key. */
  33. void Set(const std::string& key, cm::string_view value);
  34. /** Unset a definition. */
  35. void Unset(const std::string& key);
  36. private:
  37. /** String with existence boolean. */
  38. struct Def
  39. {
  40. public:
  41. Def() = default;
  42. Def(cm::string_view value)
  43. : Value(value)
  44. {
  45. }
  46. cm::String Value;
  47. };
  48. static Def NoDef;
  49. std::unordered_map<cm::String, Def> Map;
  50. static Def const& GetInternal(const std::string& key, StackIter begin,
  51. StackIter end, bool raise);
  52. };
  53. #endif