From: Gunnar Beutner Date: Fri, 13 Jul 2012 11:09:09 +0000 (+0200) Subject: Re-implemented integer support for the Variant class. X-Git-Tag: v0.0.1~250 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c0d7241eaf99a87c9315c8f6fd1de3088d673ab2;p=icinga2 Re-implemented integer support for the Variant class. --- diff --git a/base/variant.h b/base/variant.h index 7919f759f..bcd63d4fb 100644 --- a/base/variant.h +++ b/base/variant.h @@ -35,10 +35,22 @@ public: : m_Value() { } + inline Variant(int value) + : m_Value(static_cast(value)) + { } + + inline Variant(long value) + : m_Value(value) + { } + inline Variant(double value) : m_Value(value) { } + inline Variant(bool value) + : m_Value(static_cast(value)) + { } + inline Variant(const string& value) : m_Value(value) { } @@ -58,17 +70,29 @@ public: m_Value = object; } + operator long(void) const + { + if (m_Value.type() != typeid(long)) { + return boost::lexical_cast(m_Value); + } else { + return boost::get(m_Value); + } + } + operator double(void) const { if (m_Value.type() != typeid(double)) { - double result = boost::lexical_cast(m_Value); - m_Value = result; - return result; + return boost::lexical_cast(m_Value); } else { return boost::get(m_Value); } } + operator bool(void) const + { + return static_cast(*this); + } + operator string(void) const { if (m_Value.type() != typeid(string)) { @@ -105,7 +129,7 @@ public: } private: - mutable boost::variant m_Value; + mutable boost::variant m_Value; }; }