/src/CMake/Source/cmDefinitions.h
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #pragma once |
4 | | |
5 | | #include "cmConfigure.h" // IWYU pragma: keep |
6 | | |
7 | | #include <string> |
8 | | #include <unordered_map> |
9 | | #include <vector> |
10 | | |
11 | | #include <cm/string_view> |
12 | | |
13 | | #include "cmLinkedTree.h" |
14 | | #include "cmString.hxx" |
15 | | #include "cmValue.h" |
16 | | |
17 | | /** \class cmDefinitions |
18 | | * \brief Store a scope of variable definitions for CMake language. |
19 | | * |
20 | | * This stores the state of variable definitions (set or unset) for |
21 | | * one scope. Sets are always local. Gets search parent scopes |
22 | | * transitively and save results locally. |
23 | | */ |
24 | | class cmDefinitions |
25 | | { |
26 | | using StackIter = cmLinkedTree<cmDefinitions>::iterator; |
27 | | |
28 | | public: |
29 | | // -- Static member functions |
30 | | |
31 | | static cmValue Get(std::string const& key, StackIter begin, StackIter end); |
32 | | |
33 | | static void Raise(std::string const& key, StackIter begin, StackIter end); |
34 | | |
35 | | static bool HasKey(std::string const& key, StackIter begin, StackIter end); |
36 | | |
37 | | enum class UnsetKeys |
38 | | { |
39 | | Exclude, |
40 | | Include, |
41 | | }; |
42 | | |
43 | | static std::vector<std::string> ClosureKeys( |
44 | | StackIter begin, StackIter end, UnsetKeys unsetKeys = UnsetKeys::Exclude); |
45 | | |
46 | | static cmDefinitions MakeClosure(StackIter begin, StackIter end); |
47 | | |
48 | | // -- Member functions |
49 | | |
50 | | /** Set a value associated with a key. */ |
51 | | void Set(std::string const& key, cm::string_view value); |
52 | | |
53 | | /** Unset a definition. */ |
54 | | void Unset(std::string const& key); |
55 | | |
56 | | private: |
57 | | /** String with existence boolean. */ |
58 | | struct Def |
59 | | { |
60 | | public: |
61 | 405k | Def() = default; |
62 | | Def(cm::string_view value) |
63 | 447k | : Value(value) |
64 | 447k | { |
65 | 447k | } |
66 | | cm::String Value; |
67 | | }; |
68 | | static Def NoDef; |
69 | | |
70 | | std::unordered_map<cm::String, Def> Map; |
71 | | |
72 | | static Def const& GetInternal(std::string const& key, StackIter begin, |
73 | | StackIter end, bool raise); |
74 | | }; |