From: Gunnar Beutner Date: Tue, 11 Nov 2014 22:28:53 +0000 (+0100) Subject: Allow Value class members to be inlined X-Git-Tag: v2.2.0~62 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=36d108528f4e3f05337778d47415ea261873af0c;p=icinga2 Allow Value class members to be inlined --- diff --git a/lib/base/value-operators.cpp b/lib/base/value-operators.cpp index eb43582f7..554c96dba 100644 --- a/lib/base/value-operators.cpp +++ b/lib/base/value-operators.cpp @@ -131,10 +131,14 @@ bool Value::operator!=(const String& rhs) const bool Value::operator==(const Value& rhs) const { - if ((IsNumber() || IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(IsEmpty() && rhs.IsEmpty())) + if (IsNumber() && rhs.IsNumber()) + return Get() == rhs.Get(); + else if ((IsNumber() || IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(IsEmpty() && rhs.IsEmpty())) return static_cast(*this) == static_cast(rhs); - if ((IsString() || IsEmpty()) && (rhs.IsString() || rhs.IsEmpty()) && !(IsEmpty() && rhs.IsEmpty())) + if (IsString() && rhs.IsString()) + return Get() == rhs.Get(); + else if ((IsString() || IsEmpty()) && (rhs.IsString() || rhs.IsEmpty()) && !(IsEmpty() && rhs.IsEmpty())) return static_cast(*this) == static_cast(rhs); if (IsEmpty() != rhs.IsEmpty()) @@ -165,7 +169,7 @@ bool Value::operator==(const Value& rhs) const return true; } - return static_cast(*this) == static_cast(rhs); + return Get() == rhs.Get(); } return false; diff --git a/lib/base/value.cpp b/lib/base/value.cpp index 0f68ef799..15cf95462 100644 --- a/lib/base/value.cpp +++ b/lib/base/value.cpp @@ -26,88 +26,6 @@ using namespace icinga; Value Empty; -Value::Value(void) - : m_Value() -{ } - -Value::Value(int value) - : m_Value(double(value)) -{ } - -Value::Value(unsigned int value) - : m_Value(double(value)) -{ } - -Value::Value(long value) - : m_Value(double(value)) -{ } - -Value::Value(unsigned long value) - : m_Value(double(value)) -{ } - -Value::Value(double value) - : m_Value(value) -{ } - -Value::Value(const String& value) - : m_Value(value) -{ } - -Value::Value(const char *value) - : m_Value(String(value)) -{ } - -/** - * Checks whether the variant is empty. - * - * @returns true if the variant is empty, false otherwise. - */ -bool Value::IsEmpty(void) const -{ - return (GetType() == ValueEmpty); -} - -/** - * Checks whether the variant is scalar (i.e. not an object and not empty). - * - * @returns true if the variant is scalar, false otherwise. - */ -bool Value::IsScalar(void) const -{ - return !IsEmpty() && !IsObject(); -} - -/** - * Checks whether the variant is a number. - * - * @returns true if the variant is a number. - */ -bool Value::IsNumber(void) const -{ - return (GetType() == ValueNumber); -} - -/** - * Checks whether the variant is a string. - * - * @returns true if the variant is a string. - */ -bool Value::IsString(void) const -{ - return (GetType() == ValueString); -} - -/** - * Checks whether the variant is a non-null object. - * - * @returns true if the variant is a non-null object, false otherwise. - */ -bool Value::IsObject(void) const -{ - return !IsEmpty() && (GetType() == ValueObject); -} - bool Value::ToBool(void) const { switch (GetType()) { @@ -136,16 +54,6 @@ bool Value::ToBool(void) const } } -/** - * Returns the type of the value. - * - * @returns The type. - */ -ValueType Value::GetType(void) const -{ - return static_cast(m_Value.which()); -} - String Value::GetTypeName(void) const { Type::Ptr t; diff --git a/lib/base/value.hpp b/lib/base/value.hpp index b890807ff..6c6484029 100644 --- a/lib/base/value.hpp +++ b/lib/base/value.hpp @@ -49,14 +49,37 @@ enum ValueType class I2_BASE_API Value { public: - Value(void); - Value(int value); - Value(unsigned int value); - Value(long value); - Value(unsigned long value); - Value(double value); - Value(const String& value); - Value(const char *value); + inline Value(void) + : m_Value() + { } + + inline Value(int value) + : m_Value(double(value)) + { } + + inline Value(unsigned int value) + : m_Value(double(value)) + { } + + inline Value(long value) + : m_Value(double(value)) + { } + + inline Value(unsigned long value) + : m_Value(double(value)) + { } + + inline Value(double value) + : m_Value(value) + { } + + inline Value(const String& value) + : m_Value(value) + { } + + inline Value(const char *value) + : m_Value(String(value)) + { } inline Value(Object *value) : m_Value() @@ -121,11 +144,55 @@ public: return tobject; } - bool IsEmpty(void) const; - bool IsScalar(void) const; - bool IsNumber(void) const; - bool IsString(void) const; - bool IsObject(void) const; + /** + * Checks whether the variant is empty. + * + * @returns true if the variant is empty, false otherwise. + */ + inline bool IsEmpty(void) const + { + return (GetType() == ValueEmpty); + } + + /** + * Checks whether the variant is scalar (i.e. not an object and not empty). + * + * @returns true if the variant is scalar, false otherwise. + */ + inline bool IsScalar(void) const + { + return !IsEmpty() && !IsObject(); + } + + /** + * Checks whether the variant is a number. + * + * @returns true if the variant is a number. + */ + inline bool IsNumber(void) const + { + return (GetType() == ValueNumber); + } + + /** + * Checks whether the variant is a string. + * + * @returns true if the variant is a string. + */ + inline bool IsString(void) const + { + return (GetType() == ValueString); + } + + /** + * Checks whether the variant is a non-null object. + * + * @returns true if the variant is a non-null object, false otherwise. + */ + inline bool IsObject(void) const + { + return !IsEmpty() && (GetType() == ValueObject); + } template bool IsObjectType(void) const @@ -136,11 +203,26 @@ public: return (dynamic_pointer_cast(boost::get(m_Value)) != NULL); } - ValueType GetType(void) const; + /** + * Returns the type of the value. + * + * @returns The type. + */ + ValueType GetType(void) const + { + return static_cast(m_Value.which()); + } + String GetTypeName(void) const; private: boost::variant m_Value; + + template + const T& Get(void) const + { + return boost::get(m_Value); + } }; static Value Empty;