mirror of https://github.com/Icinga/icinga2.git
Allow Value class members to be inlined
This commit is contained in:
parent
ee980a788b
commit
36d108528f
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue