cgv
Loading...
Searching...
No Matches
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
7namespace cgv {
8 namespace type {
9 namespace info {
10
12template <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}
complete implementation of method actions that only call one method when entering a node
Definition action.h:113
TypeId
ids for the different types and type constructs
Definition type_id.h:12
@ TI_INT16
signed integer stored in 8 bits
Definition type_id.h:20
@ TI_INT8
boolean
Definition type_id.h:19
@ TI_INT32
signed integer stored in 16 bits
Definition type_id.h:21
@ TI_FLT32
floating point type stored in 16 bits
Definition type_id.h:28
@ TI_UINT32
unsigned integer stored in 16 bits
Definition type_id.h:25
@ TI_UINT8
signed integer stored in 64 bits
Definition type_id.h:23
@ TI_INT64
signed integer stored in 32 bits
Definition type_id.h:22
@ TI_BOOL
void
Definition type_id.h:18
@ TI_UINT16
unsigned integer stored in 8 bits
Definition type_id.h:24
@ TI_FLT64
floating point type stored in 32 bits
Definition type_id.h:29
@ TI_UINT64
unsigned integer stored in 32 bits
Definition type_id.h:26
the cgv namespace
Definition print.h:11
access value whos type is given by a TypeId
Definition type_access.h:14
static T get(const void *ptr, TypeId tid)
return stored value converted into type T
Definition type_access.h:16
static bool set(void *ptr, TypeId tid, const T &v)
convert value from type T and store it
Definition type_access.h:37