Implement comparison operators for operands of different types.

Refs #5846
This commit is contained in:
Gunnar Beutner 2014-03-22 08:40:35 +01:00
parent 2a6a75d52e
commit 3afad7a96d
1 changed files with 8 additions and 0 deletions

View File

@ -440,6 +440,8 @@ Value icinga::operator<(const Value& lhs, const Value& rhs)
return static_cast<String>(lhs) < static_cast<String>(rhs);
else if ((lhs.IsNumber() || lhs.IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
return static_cast<int>(lhs) < static_cast<int>(rhs);
else if (lhs.GetTypeName() != rhs.GetTypeName())
return lhs.GetTypeName() < rhs.GetTypeName();
else
BOOST_THROW_EXCEPTION(std::invalid_argument("Operator < cannot be applied to values of type '" + lhs.GetTypeName() + "' and '" + rhs.GetTypeName() + "'"));
}
@ -470,6 +472,8 @@ Value icinga::operator>(const Value& lhs, const Value& rhs)
return static_cast<String>(lhs) > static_cast<String>(rhs);
else if ((lhs.IsNumber() || lhs.IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
return static_cast<int>(lhs) > static_cast<int>(rhs);
else if (lhs.GetTypeName() != rhs.GetTypeName())
return lhs.GetTypeName() > rhs.GetTypeName();
else
BOOST_THROW_EXCEPTION(std::invalid_argument("Operator > cannot be applied to values of type '" + lhs.GetTypeName() + "' and '" + rhs.GetTypeName() + "'"));
}
@ -500,6 +504,8 @@ Value icinga::operator<=(const Value& lhs, const Value& rhs)
return static_cast<String>(lhs) <= static_cast<String>(rhs);
else if ((lhs.IsNumber() || lhs.IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
return static_cast<int>(lhs) <= static_cast<int>(rhs);
else if (lhs.GetTypeName() != rhs.GetTypeName())
return lhs.GetTypeName() <= rhs.GetTypeName();
else
BOOST_THROW_EXCEPTION(std::invalid_argument("Operator <= cannot be applied to values of type '" + lhs.GetTypeName() + "' and '" + rhs.GetTypeName() + "'"));
}
@ -530,6 +536,8 @@ Value icinga::operator>=(const Value& lhs, const Value& rhs)
return static_cast<String>(lhs) >= static_cast<String>(rhs);
else if ((lhs.IsNumber() || lhs.IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
return static_cast<int>(lhs) >= static_cast<int>(rhs);
else if (lhs.GetTypeName() != rhs.GetTypeName())
return lhs.GetTypeName() >= rhs.GetTypeName();
else
BOOST_THROW_EXCEPTION(std::invalid_argument("Operator >= cannot be applied to values of type '" + lhs.GetTypeName() + "' and '" + rhs.GetTypeName() + "'"));
}