cmake/Source/cmDefinitions.h

81 lines
2.0 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. */
2009-10-04 10:30:41 +03:00
#ifndef cmDefinitions_h
#define cmDefinitions_h
2017-07-20 19:35:53 +02:00
#include "cmConfigure.h" // IWYU pragma: keep
2015-11-17 17:22:37 +01:00
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>
2017-04-14 19:02:05 +02:00
#include "cmLinkedTree.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
{
2015-11-17 17:22:37 +01:00
typedef cmLinkedTree<cmDefinitions>::iterator StackIter;
2016-07-09 11:21:54 +02:00
2009-10-04 10:30:41 +03:00
public:
2016-07-09 11:21:54 +02:00
static const char* 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
/** Set (or unset if null) a value associated with a key. */
2015-08-17 11:37:30 +02:00
void Set(const std::string& key, const char* value);
2009-10-04 10:30:41 +03:00
2015-08-17 11:37:30 +02:00
std::vector<std::string> UnusedKeys() const;
2011-02-07 16:37:25 +01: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
private:
// String with existence boolean.
2016-07-09 11:21:54 +02:00
struct Def : public std::string
2009-10-04 10:30:41 +03:00
{
2015-04-27 22:25:09 +02:00
private:
typedef std::string std_string;
2016-07-09 11:21:54 +02:00
2015-04-27 22:25:09 +02:00
public:
2016-07-09 11:21:54 +02:00
Def()
: std_string()
, Exists(false)
, Used(false)
{
}
2015-08-17 11:37:30 +02:00
Def(const char* v)
2016-07-09 11:21:54 +02:00
: std_string(v ? v : "")
, Exists(v ? true : false)
, Used(false)
{
}
Def(const std_string& v)
: std_string(v)
, Exists(true)
, Used(false)
{
}
2009-10-04 10:30:41 +03:00
bool Exists;
2015-08-17 11:37:30 +02:00
bool Used;
2009-10-04 10:30:41 +03:00
};
static Def NoDef;
2018-01-26 17:06:56 +01:00
typedef std::unordered_map<std::string, Def> MapType;
2009-10-04 10:30:41 +03:00
MapType Map;
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
};
#endif