Re-implemented integer support for the Variant class.

This commit is contained in:
Gunnar Beutner 2012-07-13 13:09:09 +02:00
parent a17c614d96
commit c0d7241eaf
1 changed files with 28 additions and 4 deletions

View File

@ -35,10 +35,22 @@ public:
: m_Value() : m_Value()
{ } { }
inline Variant(int value)
: m_Value(static_cast<long>(value))
{ }
inline Variant(long value)
: m_Value(value)
{ }
inline Variant(double value) inline Variant(double value)
: m_Value(value) : m_Value(value)
{ } { }
inline Variant(bool value)
: m_Value(static_cast<long>(value))
{ }
inline Variant(const string& value) inline Variant(const string& value)
: m_Value(value) : m_Value(value)
{ } { }
@ -58,17 +70,29 @@ public:
m_Value = object; m_Value = object;
} }
operator long(void) const
{
if (m_Value.type() != typeid(long)) {
return boost::lexical_cast<long>(m_Value);
} else {
return boost::get<long>(m_Value);
}
}
operator double(void) const operator double(void) const
{ {
if (m_Value.type() != typeid(double)) { if (m_Value.type() != typeid(double)) {
double result = boost::lexical_cast<double>(m_Value); return boost::lexical_cast<double>(m_Value);
m_Value = result;
return result;
} else { } else {
return boost::get<double>(m_Value); return boost::get<double>(m_Value);
} }
} }
operator bool(void) const
{
return static_cast<long>(*this);
}
operator string(void) const operator string(void) const
{ {
if (m_Value.type() != typeid(string)) { if (m_Value.type() != typeid(string)) {
@ -105,7 +129,7 @@ public:
} }
private: private:
mutable boost::variant<boost::blank, double, string, Object::Ptr> m_Value; mutable boost::variant<boost::blank, long, double, string, Object::Ptr> m_Value;
}; };
} }