2012-05-10 12:06:41 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
|
|
|
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-04-23 09:48:20 +02:00
|
|
|
#endif /* VARIANT_H */
|