1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #ifndef cmDefinitions_h
13 #define cmDefinitions_h
15 #include "cmStandardIncludes.h"
17 /** \class cmDefinitions
18 * \brief Store a scope of variable definitions for CMake language.
20 * This stores the state of variable definitions (set or unset) for
21 * one scope. Sets are always local. Gets search parent scopes
22 * transitively and save results locally.
27 /** Construct with the given parent scope. */
28 cmDefinitions(cmDefinitions* parent = 0);
30 /** Reset object as if newly constructed. */
31 void Reset(cmDefinitions* parent = 0);
33 /** Returns the parent scope, if any. */
34 cmDefinitions* GetParent() const { return this->Up; }
36 /** Get the value associated with a key; null if none.
37 Store the result locally if it came from a parent. */
38 const char* Get(const char* key);
40 /** Set (or unset if null) a value associated with a key. */
41 const char* Set(const char* key, const char* value);
43 /** Get the set of all local keys. */
44 std::set<cmStdString> LocalKeys() const;
46 /** Compute the closure of all defined keys with values.
47 This flattens the scope. The result has no parent. */
48 cmDefinitions Closure() const;
50 /** Compute the set of all defined keys. */
51 std::set<cmStdString> ClosureKeys() const;
54 // String with existence boolean.
55 struct Def: public cmStdString
57 Def(): cmStdString(), Exists(false) {}
58 Def(const char* v): cmStdString(v?v:""), Exists(v?true:false) {}
59 Def(Def const& d): cmStdString(d), Exists(d.Exists) {}
64 // Parent scope, if any.
67 // Local definitions, set or unset.
68 typedef std::map<cmStdString, Def> MapType;
71 // Internal query and update methods.
72 Def const& GetInternal(const char* key);
73 Def const& SetInternal(const char* key, Def const& def);
75 // Implementation of Closure() method.
77 cmDefinitions(ClosureTag const&, cmDefinitions const* root);
78 void ClosureImpl(std::set<cmStdString>& undefined,
79 cmDefinitions const* defs);
81 // Implementation of ClosureKeys() method.
82 void ClosureKeys(std::set<cmStdString>& defined,
83 std::set<cmStdString>& undefined) const;