mirror of https://github.com/Icinga/icinga2.git
Implement comparison operators for operands of different types.
Refs #5846
This commit is contained in:
parent
2a6a75d52e
commit
3afad7a96d
|
@ -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() + "'"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue