icinga2/base/variant.h

54 lines
1.0 KiB
C
Raw Normal View History

2012-04-18 15:22:25 +02:00
#ifndef VARIANT_H
#define VARIANT_H
namespace icinga
{
enum I2_BASE_API VariantType
{
VariantEmpty,
VariantInteger,
VariantString,
VariantObject
};
class I2_BASE_API Variant
{
private:
mutable long m_IntegerValue;
mutable string m_StringValue;
mutable Object::Ptr m_ObjectValue;
mutable VariantType m_Type;
void Convert(VariantType newType) const;
public:
2012-04-20 13:52:32 +02:00
inline Variant(void) : m_Type(VariantEmpty) { }
2012-04-20 13:49:04 +02:00
2012-04-20 13:52:32 +02:00
inline Variant(long value) : m_Type(VariantInteger), m_IntegerValue(value) { }
2012-04-20 13:49:04 +02:00
2012-04-20 13:52:32 +02:00
inline Variant(const char *value) : m_Type(VariantString), m_StringValue(string(value)) { }
2012-04-20 13:49:04 +02:00
2012-04-20 13:52:32 +02:00
inline Variant(string value) : m_Type(VariantString), m_StringValue(value) { }
2012-04-20 13:49:04 +02:00
template<typename T>
Variant(const shared_ptr<T>& value) : m_Type(VariantObject), m_ObjectValue(value) { }
2012-04-18 15:22:25 +02:00
VariantType GetType(void) const;
long GetInteger(void) const;
string GetString(void) const;
Object::Ptr GetObject(void) const;
2012-04-20 13:49:04 +02:00
bool IsEmpty(void) const;
2012-04-18 15:22:25 +02:00
operator long(void) const;
operator string(void) const;
operator Object::Ptr(void) const;
};
}
#endif /* VARIANT_H */