| IOLink 1.11.0

Loading...
Searching...
No Matches
DataType.h
1#pragma once
2
3#include <iolink/IOLinkAPI.h>
4#include <iolink/Vector.h>
5
6#include <iostream>
7
8 namespace iolink
9{
10
19 enum class PrimitiveTypeId : uint16_t
20{
22 UNKNOWN = 0x0000,
23
25 UNSIGNED_INTEGER = 0x0001,
26
28 SIGNED_INTEGER = 0x0002,
29
31 FLOATING_POINT = 0x0003,
32
34 UNICODE_STRING = 0x0004,
35};
36
40 enum class DataTypeInterpretation : uint32_t
41{
43 RAW = 0,
44
51 COMPLEX,
52
65 SQUARE_MATRIX,
66
79 SYMMETRIC_MATRIX,
80};
81
85 enum class DataTypeId : uint64_t
86{
87 UNKNOWN = 0x0000000000000000,
88 UINT8 = 0x0000000000010108,
89 UINT16 = 0x0000000000010110,
90 UINT32 = 0x0000000000010120,
91 UINT64 = 0x0000000000010140,
92 INT8 = 0x0000000000020108,
93 INT16 = 0x0000000000020110,
94 INT32 = 0x0000000000020120,
95 INT64 = 0x0000000000020140,
96 FLOAT = 0x0000000000030120,
97 DOUBLE = 0x0000000000030140,
98 UTF8_STRING = 0x0000000000040108,
99 UTF16_STRING = 0x0000000000040110,
100 UTF32_STRING = 0x0000000000040120,
101 VEC2_UINT8 = 0x0000000000010208,
102 VEC2_UINT16 = 0x0000000000010210,
103 VEC2_UINT32 = 0x0000000000010220,
104 VEC2_UINT64 = 0x0000000000010240,
105 VEC2_INT8 = 0x0000000000020208,
106 VEC2_INT16 = 0x0000000000020210,
107 VEC2_INT32 = 0x0000000000020220,
108 VEC2_INT64 = 0x0000000000020240,
109 VEC2_FLOAT = 0x0000000000030220,
110 VEC2_DOUBLE = 0x0000000000030240,
111 VEC3_UINT8 = 0x0000000000010308,
112 VEC3_UINT16 = 0x0000000000010310,
113 VEC3_UINT32 = 0x0000000000010320,
114 VEC3_UINT64 = 0x0000000000010340,
115 VEC3_INT8 = 0x0000000000020308,
116 VEC3_INT16 = 0x0000000000020310,
117 VEC3_INT32 = 0x0000000000020320,
118 VEC3_INT64 = 0x0000000000020340,
119 VEC3_FLOAT = 0x0000000000030320,
120 VEC3_DOUBLE = 0x0000000000030340,
121 VEC4_UINT8 = 0x0000000000010408,
122 VEC4_UINT16 = 0x0000000000010410,
123 VEC4_UINT32 = 0x0000000000010420,
124 VEC4_UINT64 = 0x0000000000010440,
125 VEC4_INT8 = 0x0000000000020408,
126 VEC4_INT16 = 0x0000000000020410,
127 VEC4_INT32 = 0x0000000000020420,
128 VEC4_INT64 = 0x0000000000020440,
129 VEC4_FLOAT = 0x0000000000030420,
130 VEC4_DOUBLE = 0x0000000000030440,
131 COMPLEX_FLOAT = 0x0000000100030220,
132 COMPLEX_DOUBLE = 0x0000000100030240,
133 MATRIX2_FLOAT = 0x0000000200030420,
134 MATRIX2_DOUBLE = 0x0000000200030440,
135 MATRIX3_FLOAT = 0x0000000200030920,
136 MATRIX3_DOUBLE = 0x0000000200030940,
137 MATRIX4_FLOAT = 0x0000000200031020,
138 MATRIX4_DOUBLE = 0x0000000200031040,
139 SYM_MATRIX2_FLOAT = 0x0000000300030320,
140 SYM_MATRIX2_DOUBLE = 0x0000000300030340,
141 SYM_MATRIX3_FLOAT = 0x0000000300030620,
142 SYM_MATRIX3_DOUBLE = 0x0000000300030640
143};
144
161 class IOLINK_API DataType
162{
163
164 public:
170 static DataType extractScalarType(DataType dtype);
171
183 static Vector2d standardRange(DataType dtype);
184
190 DataType() noexcept;
191
195 explicit DataType(uint64_t value) noexcept;
196
200 DataType(DataTypeId value) noexcept;
201
205 DataType(PrimitiveTypeId primitiveType,
206 size_t dimension,
207 size_t bitDepth,
208 DataTypeInterpretation interpretation) noexcept;
209
213 DataType(PrimitiveTypeId primitiveType, size_t dimension, size_t bitDepth) noexcept;
214
218 bool isNumeric() const;
219
223 bool isScalar() const;
224
228 bool isVector() const;
229
235 bool isConvertibleTo(DataType other) const;
236
241 uint64_t id() const noexcept;
242
246 inline size_t bitDepth() const noexcept { return m_bitDepth; }
247
255 inline size_t elementCount() const noexcept { return m_dimension; }
256
262 inline PrimitiveTypeId primitiveType() const noexcept { return m_primitiveType; }
263
269 inline DataTypeInterpretation interpretation() const noexcept { return m_interpretation; }
270
274 inline size_t bitCount() const { return m_bitDepth * m_dimension; }
275
283 size_t byteCount() const { return (m_bitDepth * m_dimension - 1) / 8 + 1; }
284
288 std::string toString() const;
289
290 bool operator==(DataType other) const;
291 bool operator!=(DataType other) const;
292
293 private:
294 uint8_t m_bitDepth;
295 uint8_t m_dimension;
296 PrimitiveTypeId m_primitiveType;
297 DataTypeInterpretation m_interpretation;
298};
299
300 inline std::ostream&
301operator<<(std::ostream& os, const DataType datatype)
302{
303 os << datatype.toString().c_str();
304 return os;
305}
306
307} // end namespace iolink
iolink::DataType
Stores information about a data type.
Definition DataType.h:162
iolink::DataType::extractScalarType
static DataType extractScalarType(DataType dtype)
Return scalar type in case of multi dimensionnal DataType.
iolink::DataType::standardRange
static Vector2d standardRange(DataType dtype)
Return conventional range for given DataType.
iolink::DataType::primitiveType
PrimitiveTypeId primitiveType() const noexcept
Return the primitive type of the current type.
Definition DataType.h:262
iolink::DataType::byteCount
size_t byteCount() const
Get the number of bits required to store the type.
Definition DataType.h:283
iolink::DataType::DataType
DataType() noexcept
Default constructor, creating an opaque type.
iolink::DataType::toString
std::string toString() const
Return a readable version of the DataType.
iolink::DataType::elementCount
size_t elementCount() const noexcept
Return the number of sub-values included in this type.
Definition DataType.h:255
iolink::DataType::interpretation
DataTypeInterpretation interpretation() const noexcept
The DataType interpretation.
Definition DataType.h:269
iolink::DataType::bitCount
size_t bitCount() const
Get the number of bits required to store the type.
Definition DataType.h:274
iolink::Vector
An arithmetic vector.
Definition Vector.h:37
iolink
All IOLink symbols are enclosed in this namespace.
Definition ArrayX.h:8
iolink::DataTypeId
DataTypeId
A collection of built-in data types.
Definition DataType.h:86
iolink::DataTypeId::SYM_MATRIX3_FLOAT
@ SYM_MATRIX3_FLOAT
A single precision floating point 3x3 symmetric Matrix.
iolink::DataTypeId::MATRIX3_FLOAT
@ MATRIX3_FLOAT
A single precision floating point 3x3 Matrix.
iolink::DataTypeId::MATRIX3_DOUBLE
@ MATRIX3_DOUBLE
A double precision floating point 3x3 Matrix.
iolink::DataTypeId::UINT32
@ UINT32
32 bits unsigned integer
iolink::DataTypeId::VEC4_UINT16
@ VEC4_UINT16
A vector of 4 elements that are 16 bits unsigned integer.
iolink::DataTypeId::MATRIX4_FLOAT
@ MATRIX4_FLOAT
A single precision floating point 4x4 Matrix.
iolink::DataTypeId::VEC4_INT32
@ VEC4_INT32
A vector of 4 elements that are 32 bits signed integer.
iolink::DataTypeId::SYM_MATRIX2_DOUBLE
@ SYM_MATRIX2_DOUBLE
A double precision floating point 2x2 symmetric Matrix.
iolink::DataTypeId::VEC4_FLOAT
@ VEC4_FLOAT
A vector of 4 elements that are single precision floating point.
iolink::DataTypeId::VEC3_INT32
@ VEC3_INT32
A vector of 3 elements that are 32 bits signed integer.
iolink::DataTypeId::MATRIX4_DOUBLE
@ MATRIX4_DOUBLE
A double precision floating point 4x4 Matrix.
iolink::DataTypeId::UINT16
@ UINT16
16 bits unsigned integer
iolink::DataTypeId::INT64
@ INT64
64 bits signed integer
iolink::DataTypeId::MATRIX2_FLOAT
@ MATRIX2_FLOAT
A single precision floating point 2x2 Matrix.
iolink::DataTypeId::INT16
@ INT16
16 bits signed integer
iolink::DataTypeId::VEC3_UINT32
@ VEC3_UINT32
A vector of 3 elements that are 32 bits unsigned integer.
iolink::DataTypeId::INT32
@ INT32
32 bits signed integer
iolink::DataTypeId::SYM_MATRIX2_FLOAT
@ SYM_MATRIX2_FLOAT
A single precision floating point 2x2 symmetric Matrix.
iolink::DataTypeId::VEC3_FLOAT
@ VEC3_FLOAT
A vector of 3 elements that are single precision floating point.
iolink::DataTypeId::VEC3_UINT64
@ VEC3_UINT64
A vector of 3 elements that are 64 bits unsigned integer.
iolink::DataTypeId::VEC4_UINT8
@ VEC4_UINT8
A vector of 4 elements that are 8 bits unsigned integer.
iolink::DataTypeId::UINT64
@ UINT64
64 bits unsigned integer
iolink::DataTypeId::VEC4_INT16
@ VEC4_INT16
A vector of 4 elements that are 16 bits signed integer.
iolink::DataTypeId::VEC4_DOUBLE
@ VEC4_DOUBLE
A vector of 4 elements that are double precision floating point.
iolink::DataTypeId::VEC2_INT64
@ VEC2_INT64
A vector of 2 elements that are 64 bits signed integer.
iolink::DataTypeId::VEC4_INT8
@ VEC4_INT8
A vector of 4 elements that are 8 bits signed 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::VEC2_UINT64
@ VEC2_UINT64
A vector of 2 elements that are 64 bits unsigned integer.
iolink::DataTypeId::VEC2_UINT32
@ VEC2_UINT32
A vector of 2 elements that are 32 bits unsigned integer.
iolink::DataTypeId::VEC2_INT32
@ VEC2_INT32
A vector of 2 elements that are 32 bits signed integer.
iolink::DataTypeId::VEC4_INT64
@ VEC4_INT64
A vector of 4 elements that are 64 bits signed integer.
iolink::DataTypeId::COMPLEX_DOUBLE
@ COMPLEX_DOUBLE
A double precision floating point complex number.
iolink::DataTypeId::VEC3_UINT16
@ VEC3_UINT16
A vector of 3 elements that are 16 bits unsigned integer.
iolink::DataTypeId::MATRIX2_DOUBLE
@ MATRIX2_DOUBLE
A double precision floating point 2x2 Matrix.
iolink::DataTypeId::UTF32_STRING
@ UTF32_STRING
Unicode string encoded in UTF-32.
iolink::DataTypeId::VEC2_FLOAT
@ VEC2_FLOAT
A vector of 2 elements that are single precision floating point.
iolink::DataTypeId::VEC2_DOUBLE
@ VEC2_DOUBLE
A vector of 2 elements that are double precision floating point.
iolink::DataTypeId::VEC3_UINT8
@ VEC3_UINT8
A vector of 2 elements that are 8 bits unsigned integer.
iolink::DataTypeId::VEC4_UINT64
@ VEC4_UINT64
A vector of 4 elements that are 64 bits unsigned integer.
iolink::DataTypeId::VEC3_DOUBLE
@ VEC3_DOUBLE
A vector of 3 elements that are double precision floating point.
iolink::DataTypeId::VEC3_INT16
@ VEC3_INT16
A vector of 3 elements that are 16 bits signed integer.
iolink::DataTypeId::VEC2_UINT16
@ VEC2_UINT16
A vector of 2 elements that are 16 bits unsigned integer.
iolink::DataTypeId::FLOAT
@ FLOAT
Single precision floating point.
iolink::DataTypeId::COMPLEX_FLOAT
@ COMPLEX_FLOAT
A single precision floating point complex number.
iolink::DataTypeId::VEC3_INT8
@ VEC3_INT8
A vector of 3 elements that are 8 bits signed integer.
iolink::DataTypeId::VEC2_UINT8
@ VEC2_UINT8
A vector of 2 elements that are 8 bits unsigned integer.
iolink::DataTypeId::UINT8
@ UINT8
8 bits unsigned integer
iolink::DataTypeId::INT8
@ INT8
8 bits signed integer
iolink::DataTypeId::VEC2_INT16
@ VEC2_INT16
A vector of 2 elements that are 16 bits signed integer.
iolink::DataTypeId::VEC2_INT8
@ VEC2_INT8
A vector of 2 elements that are 8 bits signed integer.
iolink::DataTypeId::SYM_MATRIX3_DOUBLE
@ SYM_MATRIX3_DOUBLE
A double precision floating point 3x3 symmetric Matrix.
iolink::DataTypeId::VEC3_INT64
@ VEC3_INT64
A vector of 3 elements that are 64 bits signed integer.
iolink::DataTypeId::VEC4_UINT32
@ VEC4_UINT32
A vector of 4 elements that are 32 bits unsigned integer.
iolink::DataTypeId::DOUBLE
@ DOUBLE
Double precision floating point.
iolink::DataTypeInterpretation
DataTypeInterpretation
An enumeration to describe how the data should be interpreted.
Definition DataType.h:41
iolink::DataTypeInterpretation::SYMMETRIC_MATRIX
@ SYMMETRIC_MATRIX
A symmetric matrix.
iolink::DataTypeInterpretation::RAW
@ RAW
No particular interpretation, classic vectors and scalars.
iolink::DataTypeInterpretation::COMPLEX
@ COMPLEX
A complex number.
iolink::DataTypeInterpretation::SQUARE_MATRIX
@ SQUARE_MATRIX
A square matrix.
iolink::PrimitiveTypeId
PrimitiveTypeId
Enum to describe the primitive family of a data type.
Definition DataType.h:20
iolink::PrimitiveTypeId::UNICODE_STRING
@ UNICODE_STRING
A text string, using the Unicode coding system.
iolink::PrimitiveTypeId::UNSIGNED_INTEGER
@ UNSIGNED_INTEGER
A classic integer number.
iolink::PrimitiveTypeId::FLOATING_POINT
@ FLOATING_POINT
A floating point number, encoded according to IEEE 754.
iolink::PrimitiveTypeId::UNKNOWN
@ UNKNOWN
An opaque type, that the no one knows about.
iolink::PrimitiveTypeId::SIGNED_INTEGER
@ SIGNED_INTEGER
An integer number, using the two complement for negative numbers.