cmake/Source/cmDefinitions.h

95 lines
2.7 KiB
C
Raw Normal View History

2009-10-04 10:30:41 +03:00
/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#ifndef cmDefinitions_h
#define cmDefinitions_h
#include "cmStandardIncludes.h"
2015-11-17 17:22:37 +01:00
#include "cmLinkedTree.h"
2015-04-27 22:25:09 +02:00
#if defined(CMAKE_BUILD_WITH_CMAKE)
2015-08-17 11:37:30 +02:00
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
#include <unordered_map>
#else
2015-04-27 22:25:09 +02:00
#include "cmsys/hash_map.hxx"
#endif
2015-08-17 11:37:30 +02:00
#endif
#include <list>
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;
2009-10-04 10:30:41 +03:00
public:
2015-08-17 11:37:30 +02:00
static const char* Get(const std::string& key,
StackIter begin, StackIter end);
2009-10-04 10:30:41 +03:00
2015-11-17 17:22:37 +01:00
static void Raise(const std::string& key,
StackIter begin, StackIter end);
2009-10-04 10:30:41 +03:00
2015-08-17 11:37:30 +02:00
static bool HasKey(const std::string& key,
2015-11-17 17:22:37 +01:00
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
2015-11-17 17:22:37 +01: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.
2015-04-27 22:25:09 +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;
public:
2015-08-17 11:37:30 +02:00
Def(): std_string(), Exists(false), Used(false) {}
Def(const char* v)
: 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) {}
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;
2015-04-27 22:25:09 +02:00
#if defined(CMAKE_BUILD_WITH_CMAKE)
2015-08-17 11:37:30 +02:00
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
typedef std::unordered_map<std::string, Def> MapType;
#else
2015-04-27 22:25:09 +02:00
typedef cmsys::hash_map<std::string, Def> MapType;
2015-08-17 11:37:30 +02:00
#endif
2015-04-27 22:25:09 +02:00
#else
typedef std::map<std::string, Def> MapType;
#endif
2009-10-04 10:30:41 +03:00
MapType Map;
2015-08-17 11:37:30 +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