1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmDefinitions.h,v $
6 Date: $Date: 2009-07-22 18:22:45 $
7 Version: $Revision: 1.1 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #ifndef cmDefinitions_h
18 #define cmDefinitions_h
20 #include "cmStandardIncludes.h"
22 /** \class cmDefinitions
23 * \brief Store a scope of variable definitions for CMake language.
25 * This stores the state of variable definitions (set or unset) for
26 * one scope. Sets are always local. Gets search parent scopes
27 * transitively and save results locally.
32 /** Construct with the given parent scope. */
33 cmDefinitions(cmDefinitions
* parent
= 0);
35 /** Reset object as if newly constructed. */
36 void Reset(cmDefinitions
* parent
= 0);
38 /** Returns the parent scope, if any. */
39 cmDefinitions
* GetParent() const { return this->Up
; }
41 /** Get the value associated with a key; null if none.
42 Store the result locally if it came from a parent. */
43 const char* Get(const char* key
);
45 /** Set (or unset if null) a value associated with a key. */
46 const char* Set(const char* key
, const char* value
);
48 /** Compute the closure of all defined keys with values.
49 This flattens the scope. The result has no parent. */
50 cmDefinitions
Closure() const;
52 /** Compute the set of all defined keys. */
53 std::set
<cmStdString
> ClosureKeys() const;
56 // String with existence boolean.
57 struct Def
: public cmStdString
59 Def(): cmStdString(), Exists(false) {}
60 Def(const char* v
): cmStdString(v
?v
:""), Exists(v
?true:false) {}
61 Def(Def
const& d
): cmStdString(d
), Exists(d
.Exists
) {}
66 // Parent scope, if any.
69 // Local definitions, set or unset.
70 typedef std::map
<cmStdString
, Def
> MapType
;
73 // Internal query and update methods.
74 Def
const& GetInternal(const char* key
);
75 Def
const& SetInternal(const char* key
, Def
const& def
);
77 // Implementation of Closure() method.
79 cmDefinitions(ClosureTag
const&, cmDefinitions
const* root
);
80 void ClosureImpl(std::set
<cmStdString
>& undefined
,
81 cmDefinitions
const* defs
);
83 // Implementation of ClosureKeys() method.
84 void ClosureKeys(std::set
<cmStdString
>& defined
,
85 std::set
<cmStdString
>& undefined
) const;