| IOLink 1.11.0

Loading...
Searching...
No Matches
DataTypeTraits.h
1#pragma once
2
3#include <iolink/DataType.h>
4
5 namespace iolink
6{
7
8 template <typename T>
9 class DataTypeTraits
10{
11 public:
12 using ScalarType = T;
13 inline static DataType toDataType() { return DataTypeId::UNKNOWN; }
14};
15
16 template <>
17 class DataTypeTraits<uint8_t>
18{
19 public:
20 using ScalarType = uint8_t;
21 inline static DataType toDataType() { return DataTypeId::UINT8; }
22};
23
24 template <>
25 class DataTypeTraits<uint16_t>
26{
27 public:
28 using ScalarType = uint16_t;
29 inline static DataType toDataType() { return DataTypeId::UINT16; }
30};
31
32 template <>
33 class DataTypeTraits<uint32_t>
34{
35 public:
36 using ScalarType = uint32_t;
37 inline static DataType toDataType() { return DataTypeId::UINT32; }
38};
39
40 template <>
41 class DataTypeTraits<uint64_t>
42{
43 public:
44 using ScalarType = uint64_t;
45 inline static DataType toDataType() { return DataTypeId::UINT64; }
46};
47
48 template <>
49 class DataTypeTraits<int8_t>
50{
51 public:
52 using ScalarType = int8_t;
53 inline static DataType toDataType() { return DataTypeId::INT8; }
54};
55
56 template <>
57 class DataTypeTraits<int16_t>
58{
59 public:
60 using ScalarType = int16_t;
61 inline static DataType toDataType() { return DataTypeId::INT16; }
62};
63
64 template <>
65 class DataTypeTraits<int32_t>
66{
67 public:
68 using ScalarType = int32_t;
69 inline static DataType toDataType() { return DataTypeId::INT32; }
70};
71
72 template <>
73 class DataTypeTraits<int64_t>
74{
75 public:
76 using ScalarType = int64_t;
77 inline static DataType toDataType() { return DataTypeId::INT64; }
78};
79
80 template <>
81 class DataTypeTraits<float>
82{
83 public:
84 using ScalarType = float;
85 inline static DataType toDataType() { return DataTypeId::FLOAT; }
86};
87
88 template <>
89 class DataTypeTraits<double>
90{
91 public:
92 using ScalarType = double;
93 inline static DataType toDataType() { return DataTypeId::DOUBLE; }
94};
95
96 template <>
97 class DataTypeTraits<const char*>
98{
99 public:
100 using ScalarType = const char*;
101 inline static DataType toDataType() { return DataTypeId::UTF8_STRING; }
102};
103
104 template <>
105 class DataTypeTraits<std::string>
106{
107 public:
108 using ScalarType = std::string;
109 inline static DataType toDataType() { return DataTypeId::UTF8_STRING; }
110};
111
112 template <>
113 class DataTypeTraits<std::u16string>
114{
115 public:
116 using ScalarType = std::string;
117 inline static DataType toDataType() { return DataTypeId::UTF16_STRING; }
118};
119
120 template <>
121 class DataTypeTraits<std::u32string>
122{
123 public:
124 using ScalarType = std::string;
125 inline static DataType toDataType() { return DataTypeId::UTF32_STRING; }
126};
127
128 template <typename T, size_t N>
129 class DataTypeTraits<Vector<T, N>>
130{
131 public:
132 using ScalarType = T;
133 using ScalarTypeTraits = DataTypeTraits<T>;
134
135 inline static DataType toDataType()
136 {
137 return DataType(ScalarTypeTraits::toDataType().primitiveType(),
138 N,
139 ScalarTypeTraits::toDataType().bitDepth(),
140 ScalarTypeTraits::toDataType().interpretation());
141 }
142};
143
144} // end namespace iolink
iolink::DataType
Stores information about a data type.
Definition DataType.h:162
iolink::DataTypeTraits
Definition DataTypeTraits.h:10
iolink::Vector
An arithmetic vector.
Definition Vector.h:37
iolink
All IOLink symbols are enclosed in this namespace.
Definition ArrayX.h:8
iolink::DataTypeId::UINT32
@ UINT32
32 bits unsigned integer
iolink::DataTypeId::UINT16
@ UINT16
16 bits unsigned integer
iolink::DataTypeId::INT64
@ INT64
64 bits signed integer
iolink::DataTypeId::INT16
@ INT16
16 bits signed integer
iolink::DataTypeId::INT32
@ INT32
32 bits signed integer
iolink::DataTypeId::UNKNOWN
@ UNKNOWN
An opaque type.
iolink::DataTypeId::UINT64
@ UINT64
64 bits unsigned integer
iolink::DataTypeId::UTF16_STRING
@ UTF16_STRING
Unicode string encoded in UTF-16.
iolink::DataTypeId::UTF8_STRING
@ UTF8_STRING
Unicode string encoded in UTF-8.
iolink::DataTypeId::UTF32_STRING
@ UTF32_STRING
Unicode string encoded in UTF-32.
iolink::DataTypeId::FLOAT
@ FLOAT
Single precision floating point.
iolink::DataTypeId::UINT8
@ UINT8
8 bits unsigned integer
iolink::DataTypeId::INT8
@ INT8
8 bits signed integer
iolink::DataTypeId::DOUBLE
@ DOUBLE
Double precision floating point.