~ubuntu-branches/ubuntu/lucid/cmake/lucid

« back to all changes in this revision

Viewing changes to Source/cmDefinitions.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Artur Rona
  • Date: 2009-12-16 11:11:54 UTC
  • mfrom: (3.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20091216111154-6accvv6yq86h2hkc
Tags: 2.8.0-5ubuntu1
* Merge from debian testing (LP: #497349). Remaining changes:
  - Keep the Replaces: on cmake-data to cover the Kubuntu version from
    Jaunty in case someone decides to do an (unsupported) Jaunty->Lucid
    upgrade.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*============================================================================
 
2
  CMake - Cross Platform Makefile Generator
 
3
  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
 
4
 
 
5
  Distributed under the OSI-approved BSD License (the "License");
 
6
  see accompanying file Copyright.txt for details.
 
7
 
 
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"
 
13
 
 
14
//----------------------------------------------------------------------------
 
15
cmDefinitions::Def cmDefinitions::NoDef;
 
16
 
 
17
//----------------------------------------------------------------------------
 
18
cmDefinitions::cmDefinitions(cmDefinitions* parent): Up(parent)
 
19
{
 
20
}
 
21
 
 
22
//----------------------------------------------------------------------------
 
23
void cmDefinitions::Reset(cmDefinitions* parent)
 
24
{
 
25
  this->Up = parent;
 
26
  this->Map.clear();
 
27
}
 
28
 
 
29
//----------------------------------------------------------------------------
 
30
cmDefinitions::Def const&
 
31
cmDefinitions::GetInternal(const char* key)
 
32
{
 
33
  MapType::const_iterator i = this->Map.find(key);
 
34
  if(i != this->Map.end())
 
35
    {
 
36
    return i->second;
 
37
    }
 
38
  else if(cmDefinitions* up = this->Up)
 
39
    {
 
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;
 
43
    }
 
44
  return this->NoDef;
 
45
}
 
46
 
 
47
//----------------------------------------------------------------------------
 
48
cmDefinitions::Def const&
 
49
cmDefinitions::SetInternal(const char* key, Def const& def)
 
50
{
 
51
  if(this->Up || def.Exists)
 
52
    {
 
53
    // In lower scopes we store keys, defined or not.
 
54
    MapType::iterator i = this->Map.find(key);
 
55
    if(i == this->Map.end())
 
56
      {
 
57
      i = this->Map.insert(MapType::value_type(key, def)).first;
 
58
      }
 
59
    else
 
60
      {
 
61
      i->second = def;
 
62
      }
 
63
    return i->second;
 
64
    }
 
65
  else
 
66
    {
 
67
    // In the top-most scope we need not store undefined keys.
 
68
    this->Map.erase(key);
 
69
    return this->NoDef;
 
70
    }
 
71
}
 
72
 
 
73
//----------------------------------------------------------------------------
 
74
const char* cmDefinitions::Get(const char* key)
 
75
{
 
76
  Def const& def = this->GetInternal(key);
 
77
  return def.Exists? def.c_str() : 0;
 
78
}
 
79
 
 
80
//----------------------------------------------------------------------------
 
81
const char* cmDefinitions::Set(const char* key, const char* value)
 
82
{
 
83
  Def const& def = this->SetInternal(key, Def(value));
 
84
  return def.Exists? def.c_str() : 0;
 
85
}
 
86
 
 
87
//----------------------------------------------------------------------------
 
88
cmDefinitions cmDefinitions::Closure() const
 
89
{
 
90
  return cmDefinitions(ClosureTag(), this);
 
91
}
 
92
 
 
93
//----------------------------------------------------------------------------
 
94
cmDefinitions::cmDefinitions(ClosureTag const&, cmDefinitions const* root):
 
95
  Up(0)
 
96
{
 
97
  std::set<cmStdString> undefined;
 
98
  this->ClosureImpl(undefined, root);
 
99
}
 
100
 
 
101
//----------------------------------------------------------------------------
 
102
void cmDefinitions::ClosureImpl(std::set<cmStdString>& undefined,
 
103
                                cmDefinitions const* defs)
 
104
{
 
105
  // Consider local definitions.
 
106
  for(MapType::const_iterator mi = defs->Map.begin();
 
107
      mi != defs->Map.end(); ++mi)
 
108
    {
 
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())
 
112
      {
 
113
      if(mi->second.Exists)
 
114
        {
 
115
        this->Map.insert(*mi);
 
116
        }
 
117
      else
 
118
        {
 
119
        undefined.insert(mi->first);
 
120
        }
 
121
      }
 
122
    }
 
123
 
 
124
  // Traverse parents.
 
125
  if(cmDefinitions const* up = defs->Up)
 
126
    {
 
127
    this->ClosureImpl(undefined, up);
 
128
    }
 
129
}
 
130
 
 
131
//----------------------------------------------------------------------------
 
132
std::set<cmStdString> cmDefinitions::ClosureKeys() const
 
133
{
 
134
  std::set<cmStdString> defined;
 
135
  std::set<cmStdString> undefined;
 
136
  this->ClosureKeys(defined, undefined);
 
137
  return defined;
 
138
}
 
139
 
 
140
//----------------------------------------------------------------------------
 
141
void cmDefinitions::ClosureKeys(std::set<cmStdString>& defined,
 
142
                                std::set<cmStdString>& undefined) const
 
143
{
 
144
  // Consider local definitions.
 
145
  for(MapType::const_iterator mi = this->Map.begin();
 
146
      mi != this->Map.end(); ++mi)
 
147
    {
 
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())
 
151
      {
 
152
      std::set<cmStdString>& m = mi->second.Exists? defined : undefined;
 
153
      m.insert(mi->first);
 
154
      }
 
155
    }
 
156
 
 
157
  // Traverse parents.
 
158
  if(cmDefinitions const* up = this->Up)
 
159
    {
 
160
    up->ClosureKeys(defined, undefined);
 
161
    }
 
162
}