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
#include "cmDefinitions.h"
14
//----------------------------------------------------------------------------
15
cmDefinitions::Def cmDefinitions::NoDef;
17
//----------------------------------------------------------------------------
18
cmDefinitions::cmDefinitions(cmDefinitions* parent): Up(parent)
22
//----------------------------------------------------------------------------
23
void cmDefinitions::Reset(cmDefinitions* parent)
29
//----------------------------------------------------------------------------
30
cmDefinitions::Def const&
31
cmDefinitions::GetInternal(const char* key)
33
MapType::const_iterator i = this->Map.find(key);
34
if(i != this->Map.end())
38
else if(cmDefinitions* up = this->Up)
40
// Query the parent scope and store the result locally.
41
Def def = up->GetInternal(key);
42
return this->Map.insert(MapType::value_type(key, def)).first->second;
47
//----------------------------------------------------------------------------
48
cmDefinitions::Def const&
49
cmDefinitions::SetInternal(const char* key, Def const& def)
51
if(this->Up || def.Exists)
53
// In lower scopes we store keys, defined or not.
54
MapType::iterator i = this->Map.find(key);
55
if(i == this->Map.end())
57
i = this->Map.insert(MapType::value_type(key, def)).first;
67
// In the top-most scope we need not store undefined keys.
73
//----------------------------------------------------------------------------
74
const char* cmDefinitions::Get(const char* key)
76
Def const& def = this->GetInternal(key);
77
return def.Exists? def.c_str() : 0;
80
//----------------------------------------------------------------------------
81
const char* cmDefinitions::Set(const char* key, const char* value)
83
Def const& def = this->SetInternal(key, Def(value));
84
return def.Exists? def.c_str() : 0;
87
//----------------------------------------------------------------------------
88
cmDefinitions cmDefinitions::Closure() const
90
return cmDefinitions(ClosureTag(), this);
93
//----------------------------------------------------------------------------
94
cmDefinitions::cmDefinitions(ClosureTag const&, cmDefinitions const* root):
97
std::set<cmStdString> undefined;
98
this->ClosureImpl(undefined, root);
101
//----------------------------------------------------------------------------
102
void cmDefinitions::ClosureImpl(std::set<cmStdString>& undefined,
103
cmDefinitions const* defs)
105
// Consider local definitions.
106
for(MapType::const_iterator mi = defs->Map.begin();
107
mi != defs->Map.end(); ++mi)
109
// Use this key if it is not already set or unset.
110
if(this->Map.find(mi->first) == this->Map.end() &&
111
undefined.find(mi->first) == undefined.end())
113
if(mi->second.Exists)
115
this->Map.insert(*mi);
119
undefined.insert(mi->first);
125
if(cmDefinitions const* up = defs->Up)
127
this->ClosureImpl(undefined, up);
131
//----------------------------------------------------------------------------
132
std::set<cmStdString> cmDefinitions::ClosureKeys() const
134
std::set<cmStdString> defined;
135
std::set<cmStdString> undefined;
136
this->ClosureKeys(defined, undefined);
140
//----------------------------------------------------------------------------
141
void cmDefinitions::ClosureKeys(std::set<cmStdString>& defined,
142
std::set<cmStdString>& undefined) const
144
// Consider local definitions.
145
for(MapType::const_iterator mi = this->Map.begin();
146
mi != this->Map.end(); ++mi)
148
// Use this key if it is not already set or unset.
149
if(defined.find(mi->first) == defined.end() &&
150
undefined.find(mi->first) == undefined.end())
152
std::set<cmStdString>& m = mi->second.Exists? defined : undefined;
158
if(cmDefinitions const* up = this->Up)
160
up->ClosureKeys(defined, undefined);