cgv
type_access.h
1 #pragma once
2 
3 #include <string>
4 #include <cgv/type/info/type_id.h>
5 #include <cgv/type/standard_types.h>
6 
7 namespace cgv {
8  namespace type {
9  namespace info {
10 
12 template <typename T>
14 {
16  static T get(const void* ptr, TypeId tid)
17  {
18  static T dummy = T();
19  switch (tid) {
20  case TI_BOOL : return(T)*static_cast<const bool*>(ptr);
21  case TI_INT8 : return(T)*static_cast<const int8_type*>(ptr);
22  case TI_INT16 : return(T)*static_cast<const int16_type*>(ptr);
23  case TI_INT32 : return(T)*static_cast<const int32_type*>(ptr);
24  case TI_INT64 : return(T)*static_cast<const int64_type*>(ptr);
25  case TI_UINT8 : return(T)*static_cast<const uint8_type*>(ptr);
26  case TI_UINT16 : return(T)*static_cast<const uint16_type*>(ptr);
27  case TI_UINT32 : return(T)*static_cast<const uint32_type*>(ptr);
28  case TI_UINT64 : return(T)*static_cast<const uint64_type*>(ptr);
29  case TI_FLT32 : return(T)*static_cast<const flt32_type*>(ptr);
30  case TI_FLT64 : return(T)*static_cast<const flt64_type*>(ptr);
31  default:
32  return dummy;
33  }
34  return dummy;
35  }
37  static bool set(void* ptr, TypeId tid, const T& v)
38  {
39  switch (tid) {
40  case TI_BOOL : *static_cast<bool*>(ptr) = (v != 0); break;
41  case TI_INT8 : *static_cast<int8_type*>(ptr) = (int8_type) v; break;
42  case TI_INT16 : *static_cast<int16_type*>(ptr) = (int16_type) v; break;
43  case TI_INT32 : *static_cast<int32_type*>(ptr) = (int32_type) v; break;
44  case TI_INT64 : *static_cast<int64_type*>(ptr) = (int64_type) v; break;
45  case TI_UINT8 : *static_cast<uint8_type*>(ptr) = (uint8_type) v; break;
46  case TI_UINT16 : *static_cast<uint16_type*>(ptr) = (uint16_type) v; break;
47  case TI_UINT32 : *static_cast<uint32_type*>(ptr) = (uint32_type) v; break;
48  case TI_UINT64 : *static_cast<uint64_type*>(ptr) = (uint64_type) v; break;
49  case TI_FLT32 : *static_cast<flt32_type*>(ptr) = (flt32_type) v; break;
50  case TI_FLT64 : *static_cast<flt64_type*>(ptr) = (flt64_type) v; break;
51  default:
52  return false;
53  }
54  return true;
55  }
56 };
57 
58  }
59  }
60 }
cgv::type::int32_type
int int32_type
this type provides an 32 bit signed integer type
Definition: standard_types.h:12
cgv::type::flt64_type
double flt64_type
this type provides a 64 bit floating point type
Definition: standard_types.h:26
cgv::type::info::TI_INT32
@ TI_INT32
signed integer stored in 16 bits
Definition: type_id.h:21
cgv::type::info::TypeId
TypeId
ids for the different types and type constructs
Definition: type_id.h:12
cgv::type::uint8_type
unsigned char uint8_type
this type provides an 8 bit unsigned integer type
Definition: standard_types.h:16
cgv::type::info::TI_UINT64
@ TI_UINT64
unsigned integer stored in 32 bits
Definition: type_id.h:26
cgv::type::uint16_type
unsigned short uint16_type
this type provides an 16 bit unsigned integer type
Definition: standard_types.h:18
cgv::type::int16_type
short int16_type
this type provides an 16 bit signed integer type
Definition: standard_types.h:10
cgv::type::info::TI_FLT64
@ TI_FLT64
floating point type stored in 32 bits
Definition: type_id.h:29
cgv::type::info::TI_INT16
@ TI_INT16
signed integer stored in 8 bits
Definition: type_id.h:20
cgv::type::info::TI_UINT32
@ TI_UINT32
unsigned integer stored in 16 bits
Definition: type_id.h:25
cgv::type::info::TI_UINT16
@ TI_UINT16
unsigned integer stored in 8 bits
Definition: type_id.h:24
cgv::type::info::TI_INT8
@ TI_INT8
boolean
Definition: type_id.h:19
cgv::type::info::TI_FLT32
@ TI_FLT32
floating point type stored in 16 bits
Definition: type_id.h:28
cgv::type::info::type_access::set
static bool set(void *ptr, TypeId tid, const T &v)
convert value from type T and store it
Definition: type_access.h:37
cgv::type::int64_type
long long int64_type
this type provides an 64 bit signed integer type
Definition: standard_types.h:14
cgv::type::info::TI_INT64
@ TI_INT64
signed integer stored in 32 bits
Definition: type_id.h:22
cgv::type::uint32_type
unsigned int uint32_type
this type provides an 32 bit unsigned integer type
Definition: standard_types.h:20
cgv::type::info::type_access
access value whos type is given by a TypeId
Definition: type_access.h:14
cgv::type::flt32_type
float flt32_type
this type provides a 32 bit floating point type
Definition: standard_types.h:24
cgv::type::info::TI_BOOL
@ TI_BOOL
void
Definition: type_id.h:18
cgv::type::info::TI_UINT8
@ TI_UINT8
signed integer stored in 64 bits
Definition: type_id.h:23
cgv
the cgv namespace
Definition: vr_calib.cxx:9
cgv::type::info::type_access::get
static T get(const void *ptr, TypeId tid)
return stored value converted into type T
Definition: type_access.h:16
cgv::type::uint64_type
unsigned long long uint64_type
this type provides an 64 bit unsigned integer type
Definition: standard_types.h:22
cgv::type::int8_type
char int8_type
this type provides an 8 bit signed integer type
Definition: standard_types.h:8