From 9058e27a431b01319b18cc4099780fa017ada113 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 6 Jun 2015 09:46:38 +0200 Subject: [PATCH] Constify property definition API. --- Source/cmGetPropertyCommand.cxx | 6 ++---- Source/cmPropertyDefinitionMap.cxx | 8 ++++---- Source/cmPropertyDefinitionMap.h | 4 ++-- Source/cmState.cxx | 28 +++++++++++++++++++++------- Source/cmState.h | 10 ++++++---- 5 files changed, 35 insertions(+), 21 deletions(-) diff --git a/Source/cmGetPropertyCommand.cxx b/Source/cmGetPropertyCommand.cxx index 250bd3551..36b6c6435 100644 --- a/Source/cmGetPropertyCommand.cxx +++ b/Source/cmGetPropertyCommand.cxx @@ -142,8 +142,7 @@ bool cmGetPropertyCommand { // Lookup brief documentation. std::string output; - if(cmPropertyDefinition* def = - this->Makefile->GetState()-> + if(cmPropertyDefinition const* def = this->Makefile->GetState()-> GetPropertyDefinition(this->PropertyName, scope)) { output = def->GetShortDescription(); @@ -158,8 +157,7 @@ bool cmGetPropertyCommand { // Lookup full documentation. std::string output; - if(cmPropertyDefinition* def = - this->Makefile->GetState()-> + if(cmPropertyDefinition const* def = this->Makefile->GetState()-> GetPropertyDefinition(this->PropertyName, scope)) { output = def->GetFullDescription(); diff --git a/Source/cmPropertyDefinitionMap.cxx b/Source/cmPropertyDefinitionMap.cxx index 3875318f4..776fad1dc 100644 --- a/Source/cmPropertyDefinitionMap.cxx +++ b/Source/cmPropertyDefinitionMap.cxx @@ -29,9 +29,9 @@ void cmPropertyDefinitionMap } } -bool cmPropertyDefinitionMap::IsPropertyDefined(const std::string& name) +bool cmPropertyDefinitionMap::IsPropertyDefined(const std::string& name) const { - cmPropertyDefinitionMap::iterator it = this->find(name); + cmPropertyDefinitionMap::const_iterator it = this->find(name); if (it == this->end()) { return false; @@ -40,9 +40,9 @@ bool cmPropertyDefinitionMap::IsPropertyDefined(const std::string& name) return true; } -bool cmPropertyDefinitionMap::IsPropertyChained(const std::string& name) +bool cmPropertyDefinitionMap::IsPropertyChained(const std::string& name) const { - cmPropertyDefinitionMap::iterator it = this->find(name); + cmPropertyDefinitionMap::const_iterator it = this->find(name); if (it == this->end()) { return false; diff --git a/Source/cmPropertyDefinitionMap.h b/Source/cmPropertyDefinitionMap.h index 00c7328c6..f95c721a8 100644 --- a/Source/cmPropertyDefinitionMap.h +++ b/Source/cmPropertyDefinitionMap.h @@ -27,10 +27,10 @@ public: bool chain); // has a named property been defined - bool IsPropertyDefined(const std::string& name); + bool IsPropertyDefined(const std::string& name) const; // is a named property set to chain - bool IsPropertyChained(const std::string& name); + bool IsPropertyChained(const std::string& name) const; }; #endif diff --git a/Source/cmState.cxx b/Source/cmState.cxx index c6fb2998e..15a463804 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -256,27 +256,41 @@ void cmState::DefineProperty(const std::string& name, chained); } -cmPropertyDefinition *cmState +cmPropertyDefinition const* cmState ::GetPropertyDefinition(const std::string& name, - cmProperty::ScopeType scope) + cmProperty::ScopeType scope) const { if (this->IsPropertyDefined(name,scope)) { - return &(this->PropertyDefinitions[scope][name]); + cmPropertyDefinitionMap const& defs = + this->PropertyDefinitions.find(scope)->second; + return &defs.find(name)->second; } return 0; } bool cmState::IsPropertyDefined(const std::string& name, - cmProperty::ScopeType scope) + cmProperty::ScopeType scope) const { - return this->PropertyDefinitions[scope].IsPropertyDefined(name); + std::map::const_iterator it + = this->PropertyDefinitions.find(scope); + if (it == this->PropertyDefinitions.end()) + { + return false; + } + return it->second.IsPropertyDefined(name); } bool cmState::IsPropertyChained(const std::string& name, - cmProperty::ScopeType scope) + cmProperty::ScopeType scope) const { - return this->PropertyDefinitions[scope].IsPropertyChained(name); + std::map::const_iterator it + = this->PropertyDefinitions.find(scope); + if (it == this->PropertyDefinitions.end()) + { + return false; + } + return it->second.IsPropertyChained(name); } void cmState::SetLanguageEnabled(std::string const& l) diff --git a/Source/cmState.h b/Source/cmState.h index 60b024f33..b06f77c9a 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -102,12 +102,14 @@ public: bool chain = false); // get property definition - cmPropertyDefinition *GetPropertyDefinition - (const std::string& name, cmProperty::ScopeType scope); + cmPropertyDefinition const* GetPropertyDefinition + (const std::string& name, cmProperty::ScopeType scope) const; // Is a property defined? - bool IsPropertyDefined(const std::string& name, cmProperty::ScopeType scope); - bool IsPropertyChained(const std::string& name, cmProperty::ScopeType scope); + bool IsPropertyDefined(const std::string& name, + cmProperty::ScopeType scope) const; + bool IsPropertyChained(const std::string& name, + cmProperty::ScopeType scope) const; void SetLanguageEnabled(std::string const& l); bool GetLanguageEnabled(std::string const& l) const;