ug4
|
A variant can represent variables of different types. More...
#include <variant.h>
Public Types | |
enum | Type { VT_INVALID = 0 , VT_BOOL = 1 , VT_INT = 2 , VT_SIZE_T = 3 , VT_FLOAT = 4 , VT_DOUBLE = 5 , VT_CSTRING = 6 , VT_STDSTRING = 7 , VT_POINTER = 8 , VT_CONST_POINTER = 9 , VT_SMART_POINTER = 10 , VT_CONST_SMART_POINTER = 11 } |
Public Member Functions | |
bool | is_valid () const |
const Variant & | operator= (const Variant &v) |
template<typename T > | |
T | to () const |
template<> | |
bool | to () const |
template<> | |
int | to () const |
template<> | |
size_t | to () const |
template<> | |
float | to () const |
template<> | |
double | to () const |
template<> | |
const char * | to () const |
template<> | |
void * | to () const |
template<> | |
const void * | to () const |
template<> | |
ConstSmartPtr< void > | to () const |
template<> | |
SmartPtr< void > | to () const |
bool | to_bool () const |
const char * | to_c_string () const |
const void * | to_const_pointer () const |
ConstSmartPtr< void > | to_const_smart_pointer () const |
double | to_double () const |
float | to_float () const |
int | to_int () const |
number | to_number () const |
void * | to_pointer () const |
size_t | to_size_t () const |
SmartPtr< void > | to_smart_pointer () const |
const std::string & | to_std_string () const |
Type | type () const |
Variant () | |
Variant (bool val) | |
Variant (const char *val) | |
Variant (const ConstSmartPtr< void > &val) | |
Variant (const SmartPtr< void > &val) | |
Variant (const std::string &val) | |
Variant (const Variant &v) | |
Variant (const void *val) | |
Variant (double val) | |
Variant (float val) | |
Variant (int val) | |
Variant (size_t val) | |
Variant (void *val) | |
~Variant () | |
Static Public Member Functions | |
template<typename T > | |
static Type | type () |
template<> | |
Variant::Type | type () |
template<> | |
Variant::Type | type () |
template<> | |
Variant::Type | type () |
template<> | |
Variant::Type | type () |
template<> | |
Variant::Type | type () |
template<> | |
Variant::Type | type () |
template<> | |
Variant::Type | type () |
template<> | |
Variant::Type | type () |
template<> | |
Variant::Type | type () |
template<> | |
Variant::Type | type () |
Private Member Functions | |
void | assign_variant (const Variant &v) |
this method only performs assignment, no prior clean up More... | |
const char * | type_name () const |
returns the name of the current type More... | |
Private Attributes | |
union { | |
bool m_bool | |
const void * m_constptr | |
ConstSmartPtr< void > * m_constsmartptr | |
const char * m_cstring | |
double m_double | |
float m_float | |
int m_int | |
void * m_pointer | |
size_t m_size_t | |
SmartPtr< void > * m_smartptr | |
std::string * m_stdstring | |
}; | |
Type | m_type |
A variant can represent variables of different types.
A variant will represent the value, which was assigned during construction or in an assignment operation. Use the different to_.. methods, to retrieve the encapsulated value. Take care only to retrieve values, which are compatible with the encapsulated value.
Number and boolean types are automatically converted to each other: VT_BOOL, VT_INT, VT_FLOAT, VT_DOUBLE.
A stdstring is automatically converted to a cstr, but not vice-versa.
You may inspect the type represented by a variant by calling the type() method, which will return a constant enumerated in Variant::Type.
enum ug::Variant::Type |
ug::Variant::Variant | ( | ) |
ug::Variant::Variant | ( | bool | val | ) |
ug::Variant::Variant | ( | int | val | ) |
ug::Variant::Variant | ( | size_t | val | ) |
ug::Variant::Variant | ( | float | val | ) |
ug::Variant::Variant | ( | double | val | ) |
ug::Variant::Variant | ( | const char * | val | ) |
ug::Variant::Variant | ( | const std::string & | val | ) |
References new().
ug::Variant::Variant | ( | void * | val | ) |
ug::Variant::Variant | ( | const void * | val | ) |
ug::Variant::Variant | ( | const ConstSmartPtr< void > & | val | ) |
References new().
ug::Variant::Variant | ( | const Variant & | v | ) |
References assign_variant().
ug::Variant::~Variant | ( | ) |
References m_constsmartptr, m_smartptr, m_stdstring, m_type, VT_CONST_SMART_POINTER, VT_SMART_POINTER, and VT_STDSTRING.
|
private |
this method only performs assignment, no prior clean up
References m_bool, m_constptr, m_constsmartptr, m_cstring, m_double, m_float, m_int, m_pointer, m_size_t, m_smartptr, m_stdstring, m_type, untested, VT_BOOL, VT_CONST_POINTER, VT_CONST_SMART_POINTER, VT_CSTRING, VT_DOUBLE, VT_FLOAT, VT_INT, VT_POINTER, VT_SIZE_T, VT_SMART_POINTER, and VT_STDSTRING.
Referenced by operator=(), and Variant().
|
inline |
References assign_variant(), m_constsmartptr, m_smartptr, m_stdstring, m_type, VT_CONST_SMART_POINTER, VT_SMART_POINTER, and VT_STDSTRING.
|
inline |
|
inline |
References to_int().
|
inline |
References to_size_t().
|
inline |
References to_float().
|
inline |
References to_double().
|
inline |
References to_c_string().
|
inline |
References to_pointer().
|
inline |
References to_const_pointer().
|
inline |
|
inline |
bool ug::Variant::to_bool | ( | ) | const |
References m_bool, m_double, m_float, m_int, m_size_t, m_type, type_name(), UG_THROW, VT_BOOL, VT_DOUBLE, VT_FLOAT, VT_INT, and VT_SIZE_T.
Referenced by ug::ProcessHierarchy::add_partition_hint(), operator<<(), ug::Partitioner_DynamicBisection< TElem, dim >::partition(), ug::ProcessHierarchy::partition_hint(), ug::Serialize(), and to().
const char * ug::Variant::to_c_string | ( | ) | const |
References m_cstring, m_stdstring, m_type, type_name(), UG_THROW, VT_CSTRING, and VT_STDSTRING.
Referenced by operator<<(), ug::Serialize(), and to().
const void * ug::Variant::to_const_pointer | ( | ) | const |
References m_constptr, m_pointer, m_type, type_name(), UG_THROW, VT_CONST_POINTER, and VT_POINTER.
Referenced by to().
ConstSmartPtr< void > ug::Variant::to_const_smart_pointer | ( | ) | const |
References m_constsmartptr, m_smartptr, m_type, type_name(), UG_THROW, VT_CONST_SMART_POINTER, and VT_SMART_POINTER.
double ug::Variant::to_double | ( | ) | const |
float ug::Variant::to_float | ( | ) | const |
int ug::Variant::to_int | ( | ) | const |
References m_bool, m_double, m_float, m_int, m_size_t, m_type, type_name(), UG_THROW, VT_BOOL, VT_DOUBLE, VT_FLOAT, VT_INT, and VT_SIZE_T.
Referenced by ug::DimensionOfSubset(), operator<<(), ug::Serialize(), and to().
number ug::Variant::to_number | ( | ) | const |
void * ug::Variant::to_pointer | ( | ) | const |
References m_pointer, m_type, type_name(), UG_THROW, and VT_POINTER.
Referenced by to().
size_t ug::Variant::to_size_t | ( | ) | const |
References m_bool, m_size_t, m_type, type_name(), UG_THROW, VT_BOOL, and VT_SIZE_T.
Referenced by operator<<(), and to().
SmartPtr< void > ug::Variant::to_smart_pointer | ( | ) | const |
References m_smartptr, m_type, type_name(), UG_THROW, and VT_SMART_POINTER.
const std::string & ug::Variant::to_std_string | ( | ) | const |
References m_stdstring, m_type, type_name(), UG_THROW, and VT_STDSTRING.
Referenced by operator<<(), and ug::Serialize().
|
inlinestatic |
|
inlinestatic |
References VT_INT.
|
inlinestatic |
References VT_SIZE_T.
|
inlinestatic |
References VT_FLOAT.
|
inlinestatic |
References VT_DOUBLE.
|
inlinestatic |
References VT_CSTRING.
|
inlinestatic |
References VT_POINTER.
|
inlinestatic |
References VT_CONST_POINTER.
|
inlinestatic |
|
inlinestatic |
|
inline |
Referenced by operator<<(), and ug::Serialize().
|
private |
returns the name of the current type
References m_type, VT_BOOL, VT_CONST_POINTER, VT_CONST_SMART_POINTER, VT_CSTRING, VT_DOUBLE, VT_FLOAT, VT_INT, VT_INVALID, VT_POINTER, VT_SIZE_T, VT_SMART_POINTER, and VT_STDSTRING.
Referenced by to_bool(), to_c_string(), to_const_pointer(), to_const_smart_pointer(), to_double(), to_float(), to_int(), to_number(), to_pointer(), to_size_t(), to_smart_pointer(), and to_std_string().
union { ... } |
bool ug::Variant::m_bool |
Referenced by assign_variant(), to_bool(), to_double(), to_float(), to_int(), to_number(), and to_size_t().
const void* ug::Variant::m_constptr |
Referenced by assign_variant(), and to_const_pointer().
ConstSmartPtr<void>* ug::Variant::m_constsmartptr |
Referenced by assign_variant(), operator=(), to_const_smart_pointer(), and ~Variant().
const char* ug::Variant::m_cstring |
Referenced by assign_variant(), and to_c_string().
double ug::Variant::m_double |
Referenced by assign_variant(), to_bool(), to_double(), to_float(), to_int(), and to_number().
float ug::Variant::m_float |
Referenced by assign_variant(), to_bool(), to_double(), to_float(), to_int(), and to_number().
int ug::Variant::m_int |
Referenced by assign_variant(), to_bool(), to_double(), to_float(), to_int(), and to_number().
void* ug::Variant::m_pointer |
Referenced by assign_variant(), to_const_pointer(), and to_pointer().
size_t ug::Variant::m_size_t |
Referenced by assign_variant(), to_bool(), to_double(), to_float(), to_int(), to_number(), and to_size_t().
SmartPtr<void>* ug::Variant::m_smartptr |
Referenced by assign_variant(), operator=(), to_const_smart_pointer(), to_smart_pointer(), and ~Variant().
std::string* ug::Variant::m_stdstring |
Referenced by assign_variant(), operator=(), to_c_string(), to_std_string(), and ~Variant().
|
private |