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; }; }