cmDefinitions.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 char* 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()
  38. : std_string()
  39. , Exists(false)
  40. , Used(false)
  41. {
  42. }
  43. Def(const char* v)
  44. : std_string(v ? v : "")
  45. , Exists(v ? true : false)
  46. , Used(false)
  47. {
  48. }
  49. Def(const std_string& v)
  50. : std_string(v)
  51. , Exists(true)
  52. , Used(false)
  53. {
  54. }
  55. bool Exists;
  56. bool Used;
  57. };
  58. static Def NoDef;
  59. typedef std::unordered_map<std::string, Def> MapType;
  60. MapType Map;
  61. static Def const& GetInternal(const std::string& key, StackIter begin,
  62. StackIter end, bool raise);
  63. };
  64. #endif