resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmDefinitions.h
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
5 #include "cmConfigure.h" // IWYU pragma: keep
6
7 #include <functional>
8 #include <string>
9 #include <unordered_map>
10 #include <vector>
11
12 #include <cm/string_view>
13
14 #include "cmLinkedTree.h"
15 #include "cmString.hxx"
16 #include "cmValue.h"
17
18 /** \class cmDefinitions
19  * \brief Store a scope of variable definitions for CMake language.
20  *
21  * This stores the state of variable definitions (set or unset) for
22  * one scope.  Sets are always local.  Gets search parent scopes
23  * transitively and save results locally.
24  */
25 class cmDefinitions
26 {
27   using StackIter = cmLinkedTree<cmDefinitions>::iterator;
28
29 public:
30   // -- Static member functions
31
32   static cmValue Get(const std::string& key, StackIter begin, StackIter end);
33
34   static void Raise(const std::string& key, StackIter begin, StackIter end);
35
36   static bool HasKey(const std::string& key, StackIter begin, StackIter end);
37
38   static std::vector<std::string> ClosureKeys(StackIter begin, StackIter end);
39
40   static cmDefinitions MakeClosure(StackIter begin, StackIter end);
41
42   // -- Member functions
43
44   /** Set a value associated with a key.  */
45   void Set(const std::string& key, cm::string_view value);
46
47   /** Unset a definition.  */
48   void Unset(const std::string& key);
49
50 private:
51   /** String with existence boolean.  */
52   struct Def
53   {
54   public:
55     Def() = default;
56     Def(cm::string_view value)
57       : Value(value)
58     {
59     }
60     cm::String Value;
61   };
62   static Def NoDef;
63
64   std::unordered_map<cm::String, Def> Map;
65
66   static Def const& GetInternal(const std::string& key, StackIter begin,
67                                 StackIter end, bool raise);
68 };