Fixes to testing if condition is always or never true

move
Aesylwinn 9 years ago
parent 5315866f61
commit 20942e6658

@ -706,6 +706,13 @@ bool CSMWorld::ConstInfoSelectWrapper::rangeContains(T1 value, std::pair<T2,T2>
return (value >= range.first && value <= range.second);
}
template <typename T1, typename T2>
bool CSMWorld::ConstInfoSelectWrapper::rangeFullyContains(std::pair<T1,T1> containingRange,
std::pair<T2,T2> testRange) const
{
return (containingRange.first <= testRange.first) && (testRange.second <= containingRange.second);
}
template <typename T1, typename T2>
bool CSMWorld::ConstInfoSelectWrapper::rangesOverlap(std::pair<T1,T1> range1, std::pair<T2,T2> range2) const
{
@ -727,21 +734,22 @@ template <typename T1, typename T2>
bool CSMWorld::ConstInfoSelectWrapper::conditionIsAlwaysTrue(std::pair<T1,T1> conditionRange,
std::pair<T2,T2> validRange) const
{
switch (mRelationType)
{
case Relation_Equal:
case Relation_Greater:
case Relation_GreaterOrEqual:
case Relation_Less:
case Relation_LessOrEqual:
// If ranges are same, it will always be true
return rangesMatch(conditionRange, validRange);
return false;
case Relation_NotEqual:
// If value is not within range, it will always be true
return !rangeContains(conditionRange.first, validRange);
case Relation_Greater:
case Relation_GreaterOrEqual:
case Relation_Less:
case Relation_LessOrEqual:
// If the valid range is completely within the condition range, it will always be true
return rangeFullyContains(conditionRange, validRange);
default:
throw std::logic_error("InfoCondition: operator can not be used to compare");
}
@ -756,6 +764,11 @@ bool CSMWorld::ConstInfoSelectWrapper::conditionIsNeverTrue(std::pair<T1,T1> con
switch (mRelationType)
{
case Relation_Equal:
return !rangeContains(conditionRange.first, validRange);
case Relation_NotEqual:
return false;
case Relation_Greater:
case Relation_GreaterOrEqual:
case Relation_Less:
@ -763,10 +776,6 @@ bool CSMWorld::ConstInfoSelectWrapper::conditionIsNeverTrue(std::pair<T1,T1> con
// If ranges do not overlap, it will never be true
return !rangesOverlap(conditionRange, validRange);
case Relation_NotEqual:
// If the value is the only value withing the range, it will never be true
return rangesMatch(conditionRange, validRange);
default:
throw std::logic_error("InfoCondition: operator can not be used to compare");
}

@ -164,7 +164,7 @@ namespace CSMWorld
bool variantTypeIsValid() const;
const ESM::Variant& getVariant() const;
std::string toString() const;
protected:
@ -188,6 +188,9 @@ namespace CSMWorld
template <typename Type1, typename Type2>
bool rangesOverlap(std::pair<Type1,Type1> range1, std::pair<Type2,Type2> range2) const;
template <typename Type1, typename Type2>
bool rangeFullyContains(std::pair<Type1,Type1> containing, std::pair<Type2,Type2> test) const;
template <typename Type1, typename Type2>
bool rangesMatch(std::pair<Type1,Type1> range1, std::pair<Type2,Type2> range2) const;

Loading…
Cancel
Save