cmPolicies: Implement PolicyMap in terms of bitset.

This commit is contained in:
Stephen Kelly 2015-05-03 10:12:34 +02:00
parent be6664c208
commit 013ada80ea
2 changed files with 42 additions and 5 deletions

View File

@ -343,24 +343,51 @@ cmPolicies::GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id)
return e.str(); return e.str();
} }
cmPolicies::PolicyMap::PolicyMap()
{
this->UNDEFINED.set();
}
cmPolicies::PolicyStatus cmPolicies::PolicyStatus
cmPolicies::PolicyMap::Get(cmPolicies::PolicyID id) const cmPolicies::PolicyMap::Get(cmPolicies::PolicyID id) const
{ {
return this->find(id)->second; PolicyStatus status = cmPolicies::WARN;
if (this->OLD[id])
{
status = cmPolicies::OLD;
}
else if (this->NEW[id])
{
status = cmPolicies::NEW;
}
else if (this->REQUIRED_ALWAYS[id])
{
status = cmPolicies::REQUIRED_ALWAYS;
}
else if (this->REQUIRED_IF_USED[id])
{
status = cmPolicies::REQUIRED_IF_USED;
}
return status;
} }
void cmPolicies::PolicyMap::Set(cmPolicies::PolicyID id, void cmPolicies::PolicyMap::Set(cmPolicies::PolicyID id,
cmPolicies::PolicyStatus status) cmPolicies::PolicyStatus status)
{ {
(*this)[id] = status; this->UNDEFINED.reset(id);
this->OLD[id] = (status == cmPolicies::OLD);
this->NEW[id] = (status == cmPolicies::NEW);
this->REQUIRED_ALWAYS[id] = (status == cmPolicies::REQUIRED_ALWAYS);
this->REQUIRED_IF_USED[id] = (status == cmPolicies::REQUIRED_IF_USED);
} }
bool cmPolicies::PolicyMap::IsDefined(cmPolicies::PolicyID id) const bool cmPolicies::PolicyMap::IsDefined(cmPolicies::PolicyID id) const
{ {
return this->find(id) != this->end(); return !this->UNDEFINED[id];
} }
bool cmPolicies::PolicyMap::IsEmpty() const bool cmPolicies::PolicyMap::IsEmpty() const
{ {
return this->empty(); return !this->UNDEFINED.none();
} }

View File

@ -14,6 +14,8 @@
#include "cmCustomCommand.h" #include "cmCustomCommand.h"
#include <bitset>
class cmMakefile; class cmMakefile;
class cmPolicy; class cmPolicy;
@ -268,12 +270,20 @@ public:
static std::string GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id); static std::string GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id);
/** Represent a set of policy values. */ /** Represent a set of policy values. */
struct PolicyMap : private std::map<PolicyID, PolicyStatus> struct PolicyMap
{ {
PolicyMap();
PolicyStatus Get(PolicyID id) const; PolicyStatus Get(PolicyID id) const;
void Set(PolicyID id, PolicyStatus status); void Set(PolicyID id, PolicyStatus status);
bool IsDefined(PolicyID id) const; bool IsDefined(PolicyID id) const;
bool IsEmpty() const; bool IsEmpty() const;
private:
std::bitset<cmPolicies::CMPCOUNT> UNDEFINED;
std::bitset<cmPolicies::CMPCOUNT> OLD;
std::bitset<cmPolicies::CMPCOUNT> NEW;
std::bitset<cmPolicies::CMPCOUNT> REQUIRED_IF_USED;
std::bitset<cmPolicies::CMPCOUNT> REQUIRED_ALWAYS;
}; };
}; };