summaryrefslogtreecommitdiffstats
path: root/Source/cmDefinitions.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmDefinitions.h')
-rw-r--r--Source/cmDefinitions.h72
1 files changed, 33 insertions, 39 deletions
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index a2f053f..5fdcaab 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -14,8 +14,14 @@
#include "cmStandardIncludes.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
+#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
+#include <unordered_map>
+#else
#include "cmsys/hash_map.hxx"
#endif
+#endif
+
+#include <list>
/** \class cmDefinitions
* \brief Store a scope of variable definitions for CMake language.
@@ -26,32 +32,26 @@
*/
class cmDefinitions
{
+ typedef std::list<cmDefinitions>::reverse_iterator StackIter;
+ typedef std::list<cmDefinitions>::const_reverse_iterator StackConstIter;
public:
- /** Construct with the given parent scope. */
- cmDefinitions(cmDefinitions* parent = 0);
+ static const char* Get(const std::string& key,
+ StackIter begin, StackIter end);
- /** Reset object as if newly constructed. */
- void Reset(cmDefinitions* parent = 0);
+ static void Raise(const std::string& key, StackIter begin, StackIter end);
- /** Returns the parent scope, if any. */
- cmDefinitions* GetParent() const { return this->Up; }
-
- /** Get the value associated with a key; null if none.
- Store the result locally if it came from a parent. */
- const char* Get(const std::string& key);
+ static bool HasKey(const std::string& key,
+ StackConstIter begin, StackConstIter end);
/** Set (or unset if null) a value associated with a key. */
- const char* Set(const std::string& key, const char* value);
+ void Set(const std::string& key, const char* value);
- /** Get the set of all local keys. */
- std::set<std::string> LocalKeys() const;
+ std::vector<std::string> UnusedKeys() const;
- /** Compute the closure of all defined keys with values.
- This flattens the scope. The result has no parent. */
- cmDefinitions Closure() const;
+ static std::vector<std::string> ClosureKeys(StackConstIter begin,
+ StackConstIter end);
- /** Compute the set of all defined keys. */
- std::set<std::string> ClosureKeys() const;
+ static cmDefinitions MakeClosure(StackConstIter begin, StackConstIter end);
private:
// String with existence boolean.
@@ -60,38 +60,32 @@ private:
private:
typedef std::string std_string;
public:
- Def(): std_string(), Exists(false) {}
- Def(const char* v): std_string(v?v:""), Exists(v?true:false) {}
- Def(const std_string& v): std_string(v), Exists(true) {}
- Def(Def const& d): std_string(d), Exists(d.Exists) {}
+ 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) {}
bool Exists;
+ bool Used;
};
static Def NoDef;
- // Parent scope, if any.
- cmDefinitions* Up;
-
- // Local definitions, set or unset.
#if defined(CMAKE_BUILD_WITH_CMAKE)
+#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
+ typedef std::unordered_map<std::string, Def> MapType;
+#else
typedef cmsys::hash_map<std::string, Def> MapType;
+#endif
#else
typedef std::map<std::string, Def> MapType;
#endif
MapType Map;
- // Internal query and update methods.
- Def const& GetInternal(const std::string& key);
- Def const& SetInternal(const std::string& key, Def const& def);
-
- // Implementation of Closure() method.
- struct ClosureTag {};
- cmDefinitions(ClosureTag const&, cmDefinitions const* root);
- void ClosureImpl(std::set<std::string>& undefined,
- cmDefinitions const* defs);
-
- // Implementation of ClosureKeys() method.
- void ClosureKeys(std::set<std::string>& defined,
- std::set<std::string>& undefined) const;
+ static Def const& GetInternal(const std::string& key,
+ StackIter begin, StackIter end, bool raise);
};
#endif