[icinga-checkins] icinga.org: icinga2/master: Allow Value class members to be inlined

git at icinga.org git at icinga.org
Tue Nov 11 23:28:57 CET 2014


Module: icinga2
Branch: master
Commit: 36d108528f4e3f05337778d47415ea261873af0c
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=36d108528f4e3f05337778d47415ea261873af0c

Author: Gunnar Beutner <gunnar at beutner.name>
Date:   Tue Nov 11 23:28:53 2014 +0100

Allow Value class members to be inlined

---

 lib/base/value-operators.cpp |   10 ++--
 lib/base/value.cpp           |   92 -----------------------------------
 lib/base/value.hpp           |  110 ++++++++++++++++++++++++++++++++++++------
 3 files changed, 103 insertions(+), 109 deletions(-)

diff --git a/lib/base/value-operators.cpp b/lib/base/value-operators.cpp
index eb43582..554c96d 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<double>() == rhs.Get<double>();
+	else if ((IsNumber() || IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(IsEmpty() && rhs.IsEmpty()))
 		return static_cast<double>(*this) == static_cast<double>(rhs);
 
-	if ((IsString() || IsEmpty()) && (rhs.IsString() || rhs.IsEmpty()) && !(IsEmpty() && rhs.IsEmpty()))
+	if (IsString() && rhs.IsString())
+		return Get<String>() == rhs.Get<String>();
+	else if ((IsString() || IsEmpty()) && (rhs.IsString() || rhs.IsEmpty()) && !(IsEmpty() && rhs.IsEmpty()))
 		return static_cast<String>(*this) == static_cast<String>(rhs);
 
 	if (IsEmpty() != rhs.IsEmpty())
@@ -165,7 +169,7 @@ bool Value::operator==(const Value& rhs) const
 			return true;
 		}
 
-		return static_cast<Object::Ptr>(*this) == static_cast<Object::Ptr>(rhs);
+		return Get<Object::Ptr>() == rhs.Get<Object::Ptr>();
 	}
 
 	return false;
diff --git a/lib/base/value.cpp b/lib/base/value.cpp
index 0f68ef7..15cf954 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<ValueType>(m_Value.which());
-}
-
 String Value::GetTypeName(void) const
 {
 	Type::Ptr t;
diff --git a/lib/base/value.hpp b/lib/base/value.hpp
index b890807..6c64840 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<typename T>
 	bool IsObjectType(void) const
@@ -136,11 +203,26 @@ public:
 		return (dynamic_pointer_cast<T>(boost::get<Object::Ptr>(m_Value)) != NULL);
 	}
 
-	ValueType GetType(void) const;
+	/**
+	* Returns the type of the value.
+	*
+	* @returns The type.
+	*/
+	ValueType GetType(void) const
+	{
+		return static_cast<ValueType>(m_Value.which());
+	}
+
 	String GetTypeName(void) const;
 
 private:
 	boost::variant<boost::blank, double, String, Object::Ptr> m_Value;
+
+	template<typename T>
+	const T& Get(void) const
+	{
+		return boost::get<T>(m_Value);
+	}
 };
 
 static Value Empty;



More information about the icinga-checkins mailing list