cmake/Source/cmDefinitions.h

69 lines
1.7 KiB
C
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2021-09-14 00:13:48 +02:00
#pragma once
2009-10-04 10:30:41 +03:00
2017-07-20 19:35:53 +02:00
#include "cmConfigure.h" // IWYU pragma: keep
2015-11-17 17:22:37 +01:00
2020-02-01 23:06:01 +01:00
#include <functional>
2016-10-30 18:24:19 +01:00
#include <string>
2018-01-26 17:06:56 +01:00
#include <unordered_map>
2016-10-30 18:24:19 +01:00
#include <vector>
2020-02-01 23:06:01 +01:00
#include <cm/string_view>
2017-04-14 19:02:05 +02:00
#include "cmLinkedTree.h"
2020-02-01 23:06:01 +01:00
#include "cmString.hxx"
2021-11-20 13:41:27 +01:00
#include "cmValue.h"
2015-08-17 11:37:30 +02:00
2009-10-04 10:30:41 +03:00
/** \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
{
2020-02-01 23:06:01 +01:00
using StackIter = cmLinkedTree<cmDefinitions>::iterator;
2016-07-09 11:21:54 +02:00
2009-10-04 10:30:41 +03:00
public:
2020-02-01 23:06:01 +01:00
// -- Static member functions
2021-11-20 13:41:27 +01:00
static cmValue Get(const std::string& key, StackIter begin, StackIter end);
2009-10-04 10:30:41 +03:00
2016-07-09 11:21:54 +02:00
static void Raise(const std::string& key, StackIter begin, StackIter end);
2009-10-04 10:30:41 +03:00
2016-07-09 11:21:54 +02:00
static bool HasKey(const std::string& key, StackIter begin, StackIter end);
2009-10-04 10:30:41 +03:00
2016-07-09 11:21:54 +02:00
static std::vector<std::string> ClosureKeys(StackIter begin, StackIter end);
2009-10-04 10:30:41 +03:00
2015-11-17 17:22:37 +01:00
static cmDefinitions MakeClosure(StackIter begin, StackIter end);
2009-10-04 10:30:41 +03:00
2020-02-01 23:06:01 +01:00
// -- Member functions
/** Set a value associated with a key. */
void Set(const std::string& key, cm::string_view value);
/** Unset a definition. */
void Unset(const std::string& key);
2009-10-04 10:30:41 +03:00
private:
2020-02-01 23:06:01 +01:00
/** String with existence boolean. */
struct Def
2009-10-04 10:30:41 +03:00
{
2015-04-27 22:25:09 +02:00
public:
2019-11-11 23:01:05 +01:00
Def() = default;
2020-02-01 23:06:01 +01:00
Def(cm::string_view value)
: Value(value)
2016-07-09 11:21:54 +02:00
{
}
2020-02-01 23:06:01 +01:00
cm::String Value;
2009-10-04 10:30:41 +03:00
};
static Def NoDef;
2020-02-01 23:06:01 +01:00
std::unordered_map<cm::String, Def> Map;
2009-10-04 10:30:41 +03:00
2016-07-09 11:21:54 +02:00
static Def const& GetInternal(const std::string& key, StackIter begin,
StackIter end, bool raise);
2009-10-04 10:30:41 +03:00
};