cmDefinitions.h 2.06 KB
Newer Older
1
2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
3
4
5
#ifndef cmDefinitions_h
#define cmDefinitions_h

6
#include <cmConfigure.h> // IWYU pragma: keep
7

8
9
10
#include <string>
#include <vector>

11
12
13
#include "cmLinkedTree.h"
#include "cm_unordered_map.hxx"

14
15
16
17
18
19
20
21
22
/** \class cmDefinitions
 * \brief Store a scope of variable definitions for CMake language.
 *
 * This stores the state of variable definitions (set or unset) for
 * one scope.  Sets are always local.  Gets search parent scopes
 * transitively and save results locally.
 */
class cmDefinitions
{
23
  typedef cmLinkedTree<cmDefinitions>::iterator StackIter;
24

25
public:
26
27
  static const char* Get(const std::string& key, StackIter begin,
                         StackIter end);
28

29
  static void Raise(const std::string& key, StackIter begin, StackIter end);
30

31
  static bool HasKey(const std::string& key, StackIter begin, StackIter end);
32

33
  /** Set (or unset if null) a value associated with a key.  */
34
  void Set(const std::string& key, const char* value);
35

36
  std::vector<std::string> UnusedKeys() const;
37

38
  static std::vector<std::string> ClosureKeys(StackIter begin, StackIter end);
39

40
  static cmDefinitions MakeClosure(StackIter begin, StackIter end);
41

42
43
private:
  // String with existence boolean.
44
  struct Def : public std::string
45
  {
46
47
  private:
    typedef std::string std_string;
48

49
  public:
50
51
52
53
54
55
    Def()
      : std_string()
      , Exists(false)
      , Used(false)
    {
    }
56
    Def(const char* v)
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
      : std_string(v ? v : "")
      , Exists(v ? true : false)
      , Used(false)
    {
    }
    Def(const std_string& v)
      : std_string(v)
      , Exists(true)
      , Used(false)
    {
    }
    Def(Def const& d)
      : std_string(d)
      , Exists(d.Exists)
      , Used(d.Used)
    {
    }
74
    bool Exists;
75
    bool Used;
76
77
78
  };
  static Def NoDef;

Daniel Pfeifer's avatar
Daniel Pfeifer committed
79
  typedef CM_UNORDERED_MAP<std::string, Def> MapType;
80
81
  MapType Map;

82
83
  static Def const& GetInternal(const std::string& key, StackIter begin,
                                StackIter end, bool raise);
84
85
86
};

#endif