Merge topic 'refactor-cmDefinitions-Get'
6c7dad41 cmDefinitions: Make Get method static. a7ce0c7b cmDefinitions: Make GetInternal method static. 7a5039fa cmDefinitions: Use static member without this->. 191573f7 cmDefinitions: Remove Parent pointer. 8b1745a1 cmDefinitions: Accept varStack iterators in Get API.
This commit is contained in:
commit
1ef88dcd46
@ -11,38 +11,39 @@
|
|||||||
============================================================================*/
|
============================================================================*/
|
||||||
#include "cmDefinitions.h"
|
#include "cmDefinitions.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
cmDefinitions::Def cmDefinitions::NoDef;
|
cmDefinitions::Def cmDefinitions::NoDef;
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
cmDefinitions::cmDefinitions(cmDefinitions* parent)
|
cmDefinitions::Def const& cmDefinitions::GetInternal(
|
||||||
: Up(parent)
|
const std::string& key,
|
||||||
|
std::list<cmDefinitions>::reverse_iterator rbegin,
|
||||||
|
std::list<cmDefinitions>::reverse_iterator rend)
|
||||||
{
|
{
|
||||||
}
|
assert(rbegin != rend);
|
||||||
|
MapType::const_iterator i = rbegin->Map.find(key);
|
||||||
//----------------------------------------------------------------------------
|
if (i != rbegin->Map.end())
|
||||||
cmDefinitions::Def const&
|
|
||||||
cmDefinitions::GetInternal(const std::string& key)
|
|
||||||
{
|
|
||||||
MapType::const_iterator i = this->Map.find(key);
|
|
||||||
if(i != this->Map.end())
|
|
||||||
{
|
{
|
||||||
return i->second;
|
return i->second;
|
||||||
}
|
}
|
||||||
cmDefinitions* up = this->Up;
|
std::list<cmDefinitions>::reverse_iterator rit = rbegin;
|
||||||
if(!up)
|
++rit;
|
||||||
|
if (rit == rend)
|
||||||
{
|
{
|
||||||
return this->NoDef;
|
return cmDefinitions::NoDef;
|
||||||
}
|
}
|
||||||
// Query the parent scope and store the result locally.
|
Def const& def = cmDefinitions::GetInternal(key, rit, rend);
|
||||||
Def def = up->GetInternal(key);
|
return rbegin->Map.insert(MapType::value_type(key, def)).first->second;
|
||||||
return this->Map.insert(MapType::value_type(key, def)).first->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
const char* cmDefinitions::Get(const std::string& key)
|
const char* cmDefinitions::Get(const std::string& key,
|
||||||
|
std::list<cmDefinitions>::reverse_iterator rbegin,
|
||||||
|
std::list<cmDefinitions>::reverse_iterator rend)
|
||||||
{
|
{
|
||||||
Def const& def = this->GetInternal(key);
|
Def const& def = cmDefinitions::GetInternal(key, rbegin, rend);
|
||||||
return def.Exists? def.c_str() : 0;
|
return def.Exists? def.c_str() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,15 +29,11 @@
|
|||||||
class cmDefinitions
|
class cmDefinitions
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/** Construct with the given parent scope. */
|
|
||||||
cmDefinitions(cmDefinitions* parent = 0);
|
|
||||||
|
|
||||||
/** Returns the parent scope, if any. */
|
|
||||||
cmDefinitions* GetParent() const { return this->Up; }
|
|
||||||
|
|
||||||
/** Get the value associated with a key; null if none.
|
/** Get the value associated with a key; null if none.
|
||||||
Store the result locally if it came from a parent. */
|
Store the result locally if it came from a parent. */
|
||||||
const char* Get(const std::string& key);
|
static const char* Get(const std::string& key,
|
||||||
|
std::list<cmDefinitions>::reverse_iterator rbegin,
|
||||||
|
std::list<cmDefinitions>::reverse_iterator rend);
|
||||||
|
|
||||||
/** Set (or unset if null) a value associated with a key. */
|
/** Set (or unset if null) a value associated with a key. */
|
||||||
void Set(const std::string& key, const char* value);
|
void Set(const std::string& key, const char* value);
|
||||||
@ -69,9 +65,6 @@ private:
|
|||||||
};
|
};
|
||||||
static Def NoDef;
|
static Def NoDef;
|
||||||
|
|
||||||
// Parent scope, if any.
|
|
||||||
cmDefinitions* Up;
|
|
||||||
|
|
||||||
// Local definitions, set or unset.
|
// Local definitions, set or unset.
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
typedef cmsys::hash_map<std::string, Def> MapType;
|
typedef cmsys::hash_map<std::string, Def> MapType;
|
||||||
@ -80,9 +73,9 @@ private:
|
|||||||
#endif
|
#endif
|
||||||
MapType Map;
|
MapType Map;
|
||||||
|
|
||||||
// Internal query and update methods.
|
static Def const& GetInternal(const std::string& key,
|
||||||
Def const& GetInternal(const std::string& key);
|
std::list<cmDefinitions>::reverse_iterator rbegin,
|
||||||
|
std::list<cmDefinitions>::reverse_iterator rend);
|
||||||
void MakeClosure(std::set<std::string>& undefined,
|
void MakeClosure(std::set<std::string>& undefined,
|
||||||
std::list<cmDefinitions>::const_reverse_iterator rbegin,
|
std::list<cmDefinitions>::const_reverse_iterator rbegin,
|
||||||
std::list<cmDefinitions>::const_reverse_iterator rend);
|
std::list<cmDefinitions>::const_reverse_iterator rend);
|
||||||
|
@ -53,12 +53,7 @@ public:
|
|||||||
|
|
||||||
void PushDefinitions()
|
void PushDefinitions()
|
||||||
{
|
{
|
||||||
cmDefinitions* parent = 0;
|
this->VarStack.push_back(cmDefinitions());
|
||||||
if (!this->VarStack.empty())
|
|
||||||
{
|
|
||||||
parent = &this->VarStack.back();
|
|
||||||
}
|
|
||||||
this->VarStack.push_back(cmDefinitions(parent));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitializeDefinitions(cmMakefile* parent)
|
void InitializeDefinitions(cmMakefile* parent)
|
||||||
@ -70,7 +65,8 @@ public:
|
|||||||
|
|
||||||
const char* GetDefinition(std::string const& name)
|
const char* GetDefinition(std::string const& name)
|
||||||
{
|
{
|
||||||
return this->VarStack.back().Get(name);
|
return cmDefinitions::Get(name, this->VarStack.rbegin(),
|
||||||
|
this->VarStack.rend());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetDefinition(std::string const& name, std::string const& value)
|
void SetDefinition(std::string const& name, std::string const& value)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user