From 7b91b200f52a8814a155fc1f3e19a1d9c9927798 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Fri, 26 Aug 2022 17:02:19 +0200 Subject: [PATCH] Use simplified if conditions where applicable --- lib/base/value-operators.cpp | 16 ++++++++-------- lib/config/configitem.cpp | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/base/value-operators.cpp b/lib/base/value-operators.cpp index 69974d038..d00c3e262 100644 --- a/lib/base/value-operators.cpp +++ b/lib/base/value-operators.cpp @@ -211,18 +211,18 @@ Value icinga::operator+(const Value& lhs, const Value& rhs) return static_cast(lhs) + static_cast(rhs); if ((lhs.IsString() || lhs.IsEmpty() || lhs.IsNumber()) && (rhs.IsString() || rhs.IsEmpty() || rhs.IsNumber()) && (!(lhs.IsEmpty() && rhs.IsEmpty()) || lhs.IsString() || rhs.IsString())) return static_cast(lhs) + static_cast(rhs); - else if ((lhs.IsNumber() || lhs.IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) + else if ((lhs.IsNumber() || lhs.IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) return static_cast(lhs) + static_cast(rhs); else if (lhs.IsObjectType() && rhs.IsNumber()) return new DateTime(Convert::ToDateTimeValue(lhs) + rhs); - else if ((lhs.IsObjectType() || lhs.IsEmpty()) && (rhs.IsObjectType() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) { + else if ((lhs.IsObjectType() || lhs.IsEmpty()) && (rhs.IsObjectType() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) { Array::Ptr result = new Array(); if (!lhs.IsEmpty()) static_cast(lhs)->CopyTo(result); if (!rhs.IsEmpty()) static_cast(rhs)->CopyTo(result); return result; - } else if ((lhs.IsObjectType() || lhs.IsEmpty()) && (rhs.IsObjectType() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) { + } else if ((lhs.IsObjectType() || lhs.IsEmpty()) && (rhs.IsObjectType() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) { Dictionary::Ptr result = new Dictionary(); if (!lhs.IsEmpty()) static_cast(lhs)->CopyTo(result); @@ -262,7 +262,7 @@ Value icinga::operator-(const Value& lhs, const Value& rhs) return new DateTime(Convert::ToDateTimeValue(lhs) - rhs); else if (lhs.IsObjectType() && rhs.IsObjectType()) return Convert::ToDateTimeValue(lhs) - Convert::ToDateTimeValue(rhs); - else if ((lhs.IsObjectType() || lhs.IsEmpty()) && (rhs.IsObjectType() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) + else if ((lhs.IsObjectType() || lhs.IsEmpty()) && (rhs.IsObjectType() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) return new DateTime(Convert::ToDateTimeValue(lhs) - Convert::ToDateTimeValue(rhs)); else if ((lhs.IsObjectType() || lhs.IsEmpty()) && (rhs.IsObjectType() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) { if (lhs.IsEmpty()) @@ -554,7 +554,7 @@ bool icinga::operator<(const Value& lhs, const Value& rhs) return static_cast(lhs) < static_cast(rhs); else if ((lhs.IsNumber() || lhs.IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) return static_cast(lhs) < static_cast(rhs); - else if ((lhs.IsObjectType() || lhs.IsEmpty()) && (rhs.IsObjectType() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) + else if ((lhs.IsObjectType() || lhs.IsEmpty()) && (rhs.IsObjectType() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) return Convert::ToDateTimeValue(lhs) < Convert::ToDateTimeValue(rhs); else if (lhs.IsObjectType() && rhs.IsObjectType()) { Array::Ptr larr = lhs; @@ -607,7 +607,7 @@ bool icinga::operator>(const Value& lhs, const Value& rhs) return static_cast(lhs) > static_cast(rhs); else if ((lhs.IsNumber() || lhs.IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) return static_cast(lhs) > static_cast(rhs); - else if ((lhs.IsObjectType() || lhs.IsEmpty()) && (rhs.IsObjectType() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) + else if ((lhs.IsObjectType() || lhs.IsEmpty()) && (rhs.IsObjectType() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) return Convert::ToDateTimeValue(lhs) > Convert::ToDateTimeValue(rhs); else if (lhs.IsObjectType() && rhs.IsObjectType()) { Array::Ptr larr = lhs; @@ -660,7 +660,7 @@ bool icinga::operator<=(const Value& lhs, const Value& rhs) return static_cast(lhs) <= static_cast(rhs); else if ((lhs.IsNumber() || lhs.IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) return static_cast(lhs) <= static_cast(rhs); - else if ((lhs.IsObjectType() || lhs.IsEmpty()) && (rhs.IsObjectType() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) + else if ((lhs.IsObjectType() || lhs.IsEmpty()) && (rhs.IsObjectType() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) return Convert::ToDateTimeValue(lhs) <= Convert::ToDateTimeValue(rhs); else BOOST_THROW_EXCEPTION(std::invalid_argument("Operator <= cannot be applied to values of type '" + lhs.GetTypeName() + "' and '" + rhs.GetTypeName() + "'")); @@ -692,7 +692,7 @@ bool icinga::operator>=(const Value& lhs, const Value& rhs) return static_cast(lhs) >= static_cast(rhs); else if ((lhs.IsNumber() || lhs.IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) return static_cast(lhs) >= static_cast(rhs); - else if ((lhs.IsObjectType() || lhs.IsEmpty()) && (rhs.IsObjectType() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) + else if ((lhs.IsObjectType() || lhs.IsEmpty()) && (rhs.IsObjectType() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) return Convert::ToDateTimeValue(lhs) >= Convert::ToDateTimeValue(rhs); else BOOST_THROW_EXCEPTION(std::invalid_argument("Operator >= cannot be applied to values of type '" + lhs.GetTypeName() + "' and '" + rhs.GetTypeName() + "'")); diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index 82303b421..9dc0f1aa2 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -148,7 +148,7 @@ public: { ConfigItem::Ptr item = ConfigItem::GetByTypeAndName(Type::GetByName(type), name); - if (!item || (item && item->IsAbstract())) + if (!item || item->IsAbstract()) return false; return true;