IOLink 1.11.0
Loading...
Searching...
No Matches
DataTypeTraits.h
1#pragma once
2
3#include <iolink/DataType.h>
4
5namespace iolink
6{
7
8template <typename T>
10{
11public:
12 using ScalarType = T;
13 inline static DataType toDataType() { return DataTypeId::UNKNOWN; }
14};
15
16template <>
17class DataTypeTraits<uint8_t>
18{
19public:
20 using ScalarType = uint8_t;
21 inline static DataType toDataType() { return DataTypeId::UINT8; }
22};
23
24template <>
25class DataTypeTraits<uint16_t>
26{
27public:
28 using ScalarType = uint16_t;
29 inline static DataType toDataType() { return DataTypeId::UINT16; }
30};
31
32template <>
33class DataTypeTraits<uint32_t>
34{
35public:
36 using ScalarType = uint32_t;
37 inline static DataType toDataType() { return DataTypeId::UINT32; }
38};
39
40template <>
41class DataTypeTraits<uint64_t>
42{
43public:
44 using ScalarType = uint64_t;
45 inline static DataType toDataType() { return DataTypeId::UINT64; }
46};
47
48template <>
49class DataTypeTraits<int8_t>
50{
51public:
52 using ScalarType = int8_t;
53 inline static DataType toDataType() { return DataTypeId::INT8; }
54};
55
56template <>
57class DataTypeTraits<int16_t>
58{
59public:
60 using ScalarType = int16_t;
61 inline static DataType toDataType() { return DataTypeId::INT16; }
62};
63
64template <>
65class DataTypeTraits<int32_t>
66{
67public:
68 using ScalarType = int32_t;
69 inline static DataType toDataType() { return DataTypeId::INT32; }
70};
71
72template <>
73class DataTypeTraits<int64_t>
74{
75public:
76 using ScalarType = int64_t;
77 inline static DataType toDataType() { return DataTypeId::INT64; }
78};
79
80template <>
81class DataTypeTraits<float>
82{
83public:
84 using ScalarType = float;
85 inline static DataType toDataType() { return DataTypeId::FLOAT; }
86};
87
88template <>
89class DataTypeTraits<double>
90{
91public:
92 using ScalarType = double;
93 inline static DataType toDataType() { return DataTypeId::DOUBLE; }
94};
95
96template <>
97class DataTypeTraits<const char*>
98{
99public:
100 using ScalarType = const char*;
101 inline static DataType toDataType() { return DataTypeId::UTF8_STRING; }
102};
103
104template <>
105class DataTypeTraits<std::string>
106{
107public:
108 using ScalarType = std::string;
109 inline static DataType toDataType() { return DataTypeId::UTF8_STRING; }
110};
111
112template <>
113class DataTypeTraits<std::u16string>
114{
115public:
116 using ScalarType = std::string;
117 inline static DataType toDataType() { return DataTypeId::UTF16_STRING; }
118};
119
120template <>
121class DataTypeTraits<std::u32string>
122{
123public:
124 using ScalarType = std::string;
125 inline static DataType toDataType() { return DataTypeId::UTF32_STRING; }
126};
127
128template <typename T, size_t N>
130{
131public:
132 using ScalarType = 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