33 #ifndef __H__UG_variant__
34 #define __H__UG_variant__
100 VT_SMART_POINTER = 10,
101 VT_CONST_SMART_POINTER = 11
103 ,VT_LUA_FUNCTION_HANDLE = 12
104 ,VT_LUA_TABLE_HANDLE = 13
116 Variant(
const std::string& val);
134 template <
typename T>
138 bool to_bool()
const;
140 size_t to_size_t()
const;
141 float to_float()
const;
143 double to_double()
const;
144 const char* to_c_string()
const;
145 const std::string& to_std_string()
const;
146 void* to_pointer()
const;
147 const void* to_const_pointer()
const;
155 template <
typename T>
160 void assign_variant(
const Variant& v);
163 const char* type_name()
const;
187 template <>
inline bool Variant::to<bool>()
const {
return to_bool();}
188 template <>
inline int Variant::to<int>()
const {
return to_int();}
189 template <>
inline size_t Variant::to<size_t>()
const {
return to_size_t();}
190 template <>
inline float Variant::to<float>()
const {
return to_float();}
191 template <>
inline double Variant::to<double>()
const {
return to_double();}
192 template <>
inline const char* Variant::to<const char*>()
const {
return to_c_string();}
193 template <>
inline std::string Variant::to<std::string>()
const {
return to_std_string();}
194 template <>
inline const std::string& Variant::to<const std::string&>()
const {
return to_std_string();}
195 template <>
inline void* Variant::to<void*>()
const {
return to_pointer();}
196 template <>
inline const void* Variant::to<const void*>()
const {
return to_const_pointer();}
197 template <>
inline SmartPtr<void> Variant::to<SmartPtr<void> >()
const {
return to_smart_pointer();}
198 template <>
inline ConstSmartPtr<void> Variant::to<ConstSmartPtr<void> >()
const {
return to_const_smart_pointer();}
200 template <>
inline LuaFunctionHandle Variant::to<LuaFunctionHandle>()
const {
return to_lua_function_handle();}
201 template <>
inline LuaTableHandle Variant::to<LuaTableHandle>()
const {
return to_lua_table_handle();}
210 template <>
inline Variant::Type Variant::type<std::string>() {
return VT_STDSTRING;}
211 template <>
inline Variant::Type Variant::type<const std::string&>() {
return VT_STDSTRING;}
214 template <>
inline Variant::Type Variant::type<SmartPtr<void> >() {
return VT_SMART_POINTER;}
215 template <>
inline Variant::Type Variant::type<ConstSmartPtr<void> >() {
return VT_CONST_SMART_POINTER;}
217 template <>
inline Variant::Type Variant::type<LuaFunctionHandle>() {
return VT_LUA_FUNCTION_HANDLE;}
218 template <>
inline Variant::Type Variant::type<LuaTableHandle>() {
return VT_LUA_TABLE_HANDLE;}
Definition: smart_pointer.h:650
Definition: smart_pointer.h:525
Handle for a lua reference.
Definition: lua_function_handle.h:40
Handle for a lua reference.
Definition: lua_table_handle.h:49
A variant can represent variables of different types.
Definition: variant.h:87
static Type type()
Definition: variant.h:135
ConstSmartPtr< void > * m_constsmartptr
Definition: variant.h:177
size_t to_size_t() const
Definition: variant.cpp:245
bool m_bool
Definition: variant.h:167
double to_double() const
Definition: variant.cpp:291
const char * m_cstring
Definition: variant.h:172
const void * m_constptr
Definition: variant.h:175
std::string * m_stdstring
Definition: variant.h:173
const void * to_const_pointer() const
Definition: variant.cpp:338
float to_float() const
Definition: variant.cpp:259
bool to_bool() const
Definition: variant.cpp:213
double m_double
Definition: variant.h:171
Type
Definition: variant.h:89
@ VT_SIZE_T
Definition: variant.h:93
@ VT_BOOL
Definition: variant.h:91
@ VT_CONST_POINTER
Definition: variant.h:99
@ VT_INT
Definition: variant.h:92
@ VT_CSTRING
Definition: variant.h:96
@ VT_DOUBLE
Definition: variant.h:95
@ VT_FLOAT
Definition: variant.h:94
@ VT_POINTER
Definition: variant.h:98
bool is_valid() const
Definition: variant.h:137
size_t m_size_t
Definition: variant.h:169
int m_int
Definition: variant.h:168
void * to_pointer() const
Definition: variant.cpp:330
SmartPtr< void > * m_smartptr
Definition: variant.h:176
Type type() const
Definition: variant.h:132
const char * to_c_string() const
Definition: variant.cpp:307
float m_float
Definition: variant.h:170
Type m_type
Definition: variant.h:184
void * m_pointer
Definition: variant.h:174
int to_int() const
Definition: variant.cpp:229
#define UG_API
Definition: ug_config.h:65
double number
Definition: types.h:124
UG_API std::ostream & operator<<(std::ostream &outStream, const ug::Variant &v)
Definition: variant.cpp:401