cmDefinitions.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 "cm_string_view.hxx"
  7. #include "cmLinkedTree.h"
  8. #include "cmString.hxx"
  9. #include <functional>
  10. #include <string>
  11. #include <unordered_map>
  12. #include <vector>
  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. typedef cmLinkedTree<cmDefinitions>::iterator StackIter;
  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. /** List of unused keys. */
  37. std::vector<std::string> UnusedKeys() const;
  38. private:
  39. /** String with existence boolean. */
  40. struct Def
  41. {
  42. public:
  43. Def() = default;
  44. Def(cm::string_view value)
  45. : Value(value)
  46. {
  47. }
  48. cm::String Value;
  49. bool Used = false;
  50. };
  51. static Def NoDef;
  52. std::unordered_map<cm::String, Def> Map;
  53. static Def const& GetInternal(const std::string& key, StackIter begin,
  54. StackIter end, bool raise);
  55. };
  56. #endif