From be6664c208c65e01dc175ae4d27e7fc18c28c97e Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 3 May 2015 10:12:28 +0200 Subject: [PATCH] cmPolicies: Implement abstraction for PolicyMap. Hide the detail that it is a std::map. --- Source/cmMakefile.cxx | 11 +++++------ Source/cmPolicies.cxx | 22 ++++++++++++++++++++++ Source/cmPolicies.h | 8 +++++++- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 29d891c22..3befbdd73 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -569,7 +569,7 @@ cmMakefile::IncludeScope::~IncludeScope() // one we pushed above. If the entry is empty, then the included // script did not set any policies that might affect the includer so // we do not need to enforce the policy. - if(this->CheckCMP0011 && this->Makefile->PolicyStack.back().empty()) + if(this->CheckCMP0011 && this->Makefile->PolicyStack.back().IsEmpty()) { this->CheckCMP0011 = false; } @@ -4772,10 +4772,9 @@ cmMakefile::GetPolicyStatusInternal(cmPolicies::PolicyID id) const for(PolicyStackType::const_reverse_iterator psi = this->PolicyStack.rbegin(); psi != this->PolicyStack.rend(); ++psi) { - PolicyStackEntry::const_iterator pse = psi->find(id); - if(pse != psi->end()) + if(psi->IsDefined(id)) { - return pse->second; + return psi->Get(id); } } @@ -4840,7 +4839,7 @@ bool cmMakefile::SetPolicy(cmPolicies::PolicyID id, for(PolicyStackType::reverse_iterator psi = this->PolicyStack.rbegin(); previous_was_weak && psi != this->PolicyStack.rend(); ++psi) { - (*psi)[id] = status; + psi->Set(id, status); previous_was_weak = psi->Weak; } @@ -4960,7 +4959,7 @@ void cmMakefile::RecordPolicies(cmPolicies::PolicyMap& pm) for(PolicyID pid = cmPolicies::CMP0000; pid != cmPolicies::CMPCOUNT; pid = PolicyID(pid+1)) { - pm[pid] = this->GetPolicyStatus(pid); + pm.Set(pid, this->GetPolicyStatus(pid)); } } diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index c95520f0d..899694309 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -342,3 +342,25 @@ cmPolicies::GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id) << "Run cmake --help-policy " << pid << " for more information."; return e.str(); } + +cmPolicies::PolicyStatus +cmPolicies::PolicyMap::Get(cmPolicies::PolicyID id) const +{ + return this->find(id)->second; +} + +void cmPolicies::PolicyMap::Set(cmPolicies::PolicyID id, + cmPolicies::PolicyStatus status) +{ + (*this)[id] = status; +} + +bool cmPolicies::PolicyMap::IsDefined(cmPolicies::PolicyID id) const +{ + return this->find(id) != this->end(); +} + +bool cmPolicies::PolicyMap::IsEmpty() const +{ + return this->empty(); +} diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index fee7dd987..46b725ac5 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -268,7 +268,13 @@ public: static std::string GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id); /** Represent a set of policy values. */ - typedef std::map PolicyMap; + struct PolicyMap : private std::map + { + PolicyStatus Get(PolicyID id) const; + void Set(PolicyID id, PolicyStatus status); + bool IsDefined(PolicyID id) const; + bool IsEmpty() const; + }; }; #endif