3 #include <cgv/utils/convert.h>
5 #include <cgv/type/standard_types.h>
6 #include <cgv/type/info/type_id.h>
23 static T
get(
const std::string& value_type,
const void* value_ptr)
26 return (T) *
static_cast<const bool*
>(value_ptr);
28 return (T) *
static_cast<const int8_type*
>(value_ptr);
30 return (T) *
static_cast<const int16_type*
>(value_ptr);
32 return (T) *
static_cast<const int32_type*
>(value_ptr);
34 return (T) *
static_cast<const int64_type*
>(value_ptr);
36 return (T) *
static_cast<const uint8_type*
>(value_ptr);
38 return (T) *
static_cast<const uint16_type*
>(value_ptr);
40 return (T) *
static_cast<const uint32_type*
>(value_ptr);
42 return (T) *
static_cast<const uint64_type*
>(value_ptr);
44 return (T) *
static_cast<const flt32_type*
>(value_ptr);
46 return (T) *
static_cast<const flt64_type*
>(value_ptr);
48 return (T) atof(
static_cast<const std::string*
>(value_ptr)->c_str());
50 return (T) *
static_cast<const short*
>(value_ptr);
56 static void set(
const T& value,
const std::string& value_type,
void* value_ptr)
59 *
static_cast<bool*
>(value_ptr) = value != T();
92 static bool get(
const std::string& value_type,
const void* value_ptr)
95 return *
static_cast<const bool*
>(value_ptr);
97 return *
static_cast<const int8_type*
>(value_ptr) != 0;
99 return *
static_cast<const int16_type*
>(value_ptr) != 0;
101 return *
static_cast<const int32_type*
>(value_ptr) != 0;
103 return *
static_cast<const int64_type*
>(value_ptr) != 0;
105 return *
static_cast<const uint8_type*
>(value_ptr) != 0;
107 return *
static_cast<const uint16_type*
>(value_ptr) != 0;
109 return *
static_cast<const uint32_type*
>(value_ptr) != 0;
111 return *
static_cast<const uint64_type*
>(value_ptr) != 0;
113 return *
static_cast<const flt32_type*
>(value_ptr) != 0;
115 return *
static_cast<const flt64_type*
>(value_ptr) != 0;
117 return *
static_cast<const wchar_type*
>(value_ptr) != 0;
119 return *
static_cast<const std::string*
>(value_ptr) ==
"true";
121 return *
static_cast<const std::wstring*
>(value_ptr) == L
"true";
124 static void set(
const bool& value,
const std::string& value_type,
void* value_ptr)
127 *
static_cast<bool*
>(value_ptr) = value;
129 *
static_cast<int8_type*
>(value_ptr) = value?1:0;
131 *
static_cast<int16_type*
>(value_ptr) = value?1:0;
133 *
static_cast<int32_type*
>(value_ptr) = value?1:0;
135 *
static_cast<int64_type*
>(value_ptr) = value?1:0;
137 *
static_cast<uint8_type*
>(value_ptr) = value?1:0;
145 *
static_cast<flt32_type*
>(value_ptr) = value?1.0f:0.0f;
147 *
static_cast<flt64_type*
>(value_ptr) = value?1:0;
149 *
static_cast<wchar_type*
>(value_ptr) = value?1:0;
151 *
static_cast<std::string*
>(value_ptr) = value?
"true":
"false";
153 *
static_cast<std::wstring*
>(value_ptr) = value?L
"true":L
"false";
159 struct variant<std::string>
161 static std::string
get(
const std::string& value_type,
const void* value_ptr)
164 return *
static_cast<const bool*
>(value_ptr)?
"true":
"false";
188 return *
static_cast<const std::string*
>(value_ptr);
193 static void set(
const std::string& value,
const std::string& value_type,
void* value_ptr)
196 *
static_cast<bool*
>(value_ptr) = value==
"true"?
true:
false;
198 *
static_cast<int8_type*
>(value_ptr) = atoi(value.c_str());
218 *
static_cast<std::string*
>(value_ptr) = value;
220 *
static_cast<wchar_type*
>(value_ptr) = value.empty() ? 0 : value[0];
227 struct variant<std::wstring>
229 static std::wstring
get(
const std::string& value_type,
const void* value_ptr)
232 return *
static_cast<const std::wstring*
>(value_ptr);
235 static void set(
const std::wstring& value,
const std::string& value_type,
void* value_ptr)
238 *
static_cast<std::wstring*
>(value_ptr) = value;
248 struct variant<const char*>
250 static void set(
const char* value,
const std::string& value_type,
void* value_ptr)
256 template <
typename T>
257 void set_variant(
const T& value,
const std::string& value_type,
void* value_ptr)
262 template <
typename T>
263 void get_variant(T& value,
const std::string& value_type,
const void* value_ptr)
268 extern CGV_API
void assign_variant(
const std::string& dst_value_type,
void* dst_value_ptr,
269 const std::string& src_value_type,
const void* src_value_ptr);
274 #include <cgv/config/lib_end.h>
int int32_type
this type provides an 32 bit signed integer type
Definition: standard_types.h:12
@ TI_WCHAR
floating point type stored in 64 bits
Definition: type_id.h:30
double flt64_type
this type provides a 64 bit floating point type
Definition: standard_types.h:26
@ TI_INT32
signed integer stored in 16 bits
Definition: type_id.h:21
unsigned char uint8_type
this type provides an 8 bit unsigned integer type
Definition: standard_types.h:16
@ TI_UINT64
unsigned integer stored in 32 bits
Definition: type_id.h:26
@ TI_STRING
wide character type
Definition: type_id.h:31
std::wstring str2wstr(const std::string &s)
convert a 8-bit string to a 16-bit string
Definition: convert.cxx:11
unsigned short uint16_type
this type provides an 16 bit unsigned integer type
Definition: standard_types.h:18
short int16_type
this type provides an 16 bit signed integer type
Definition: standard_types.h:10
@ TI_FLT64
floating point type stored in 32 bits
Definition: type_id.h:29
@ TI_INT16
signed integer stored in 8 bits
Definition: type_id.h:20
static void set(const T &value, const std::string &value_type, void *value_ptr)
convert the first parameter of type T into value_type and store the value at the location pointed to ...
Definition: variant.h:56
@ TI_UINT32
unsigned integer stored in 16 bits
Definition: type_id.h:25
@ TI_UINT16
unsigned integer stored in 8 bits
Definition: type_id.h:24
std::string wstr2str(const std::wstring &ws)
convert a 16-bit string to a 8-bit string
Definition: convert.cxx:26
@ TI_INT8
boolean
Definition: type_id.h:19
@ TI_FLT32
floating point type stored in 16 bits
Definition: type_id.h:28
static T get(const std::string &value_type, const void *value_ptr)
convert the value pointed to by value_ptr of type value_type to type T and return it
Definition: variant.h:23
long long int64_type
this type provides an 64 bit signed integer type
Definition: standard_types.h:14
@ TI_INT64
signed integer stored in 32 bits
Definition: type_id.h:22
@ TI_WSTRING
string type
Definition: type_id.h:32
unsigned int uint32_type
this type provides an 32 bit unsigned integer type
Definition: standard_types.h:20
float flt32_type
this type provides a 32 bit floating point type
Definition: standard_types.h:24
@ TI_BOOL
void
Definition: type_id.h:18
@ TI_UINT8
signed integer stored in 64 bits
Definition: type_id.h:23
const char * get_type_name(TypeId tid)
function that returns the name of a type specified through TypeId
Definition: type_id.cxx:117
wchar_t wchar_type
wide character type
Definition: standard_types.h:28
std::string to_string(const std::string &v, unsigned int w, unsigned int p)
specialization of conversion from string to strings
Definition: convert_string.cxx:7
the cgv namespace
Definition: vr_calib.cxx:9
unsigned long long uint64_type
this type provides an 64 bit unsigned integer type
Definition: standard_types.h:22
char int8_type
this type provides an 8 bit signed integer type
Definition: standard_types.h:8