PdCom  5.0
Process data communication client
details.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * vim:tw=78
3  *
4  * Copyright (C) 2021 Richard Hacker (lerichi at gmx dot net),
5  * Florian Pose (fp at igh dot de),
6  * Bjarne von Horn (vh at igh dot de).
7  *
8  * This file is part of the PdCom library.
9  *
10  * The PdCom library is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or (at your
13  * option) any later version.
14  *
15  * The PdCom library is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with the PdCom library. If not, see <http://www.gnu.org/licenses/>.
22  *
23  *****************************************************************************/
24 
25 #ifndef PDCOM5_DETAILS_H
26 #define PDCOM5_DETAILS_H
27 
30 #include "SizeTypeInfo.h"
31 #include "pdcom5_export.h"
32 
33 #include <array>
34 #include <cstddef>
35 #include <cstdint>
36 #include <string>
37 #include <type_traits>
38 #include <vector>
39 
40 template <class T>
41 class QVector;
42 
43 namespace PdCom { namespace details {
44 
45 template <typename T>
47 {};
48 template <>
49 struct TypeInfoTraits<bool>
50 {
51  static constexpr TypeInfo type_info = {
52  TypeInfo::boolean_T, "bool", sizeof(bool)};
53 };
54 template <>
55 struct TypeInfoTraits<char>
56 {
57  static constexpr TypeInfo type_info = {
58  TypeInfo::char_T, "char", sizeof(char)};
59 };
60 template <>
61 struct TypeInfoTraits<uint8_t>
62 {
63  static constexpr TypeInfo type_info = {
64  TypeInfo::uint8_T, "uint8_t", sizeof(uint8_t)};
65 };
66 template <>
67 struct TypeInfoTraits<int8_t>
68 {
69  static constexpr TypeInfo type_info = {
70  TypeInfo::int8_T, "int8_t", sizeof(int8_t)};
71 };
72 template <>
73 struct TypeInfoTraits<uint16_t>
74 {
75  static constexpr TypeInfo type_info = {
76  TypeInfo::uint16_T, "uint16_t", sizeof(uint16_t)};
77 };
78 template <>
79 struct TypeInfoTraits<int16_t>
80 {
81  static constexpr TypeInfo type_info = {
82  TypeInfo::int16_T, "int16_t", sizeof(int16_t)};
83 };
84 template <>
85 struct TypeInfoTraits<uint32_t>
86 {
87  static constexpr TypeInfo type_info = {
88  TypeInfo::uint32_T, "uint32_t", sizeof(uint32_t)};
89 };
90 template <>
91 struct TypeInfoTraits<int32_t>
92 {
93  static constexpr TypeInfo type_info = {
94  TypeInfo::int32_T, "int32_t", sizeof(int32_t)};
95 };
96 template <>
97 struct TypeInfoTraits<uint64_t>
98 {
99  static constexpr TypeInfo type_info = {
100  TypeInfo::uint64_T, "uint64_t", sizeof(uint64_t)};
101 };
102 template <>
103 struct TypeInfoTraits<int64_t>
104 {
105  static constexpr TypeInfo type_info = {
106  TypeInfo::int64_T, "int64_t", sizeof(int64_t)};
107 };
108 template <>
109 struct TypeInfoTraits<double>
110 {
111  static constexpr TypeInfo type_info = {
112  TypeInfo::double_T, "double", sizeof(double)};
113 };
114 template <>
115 struct TypeInfoTraits<float>
116 {
117  static constexpr TypeInfo type_info = {
118  TypeInfo::single_T, "float", sizeof(float)};
119 };
120 
121 template <TypeInfo::DataType dtype>
123 {};
124 template <>
125 struct DataTypeTraits<TypeInfo::boolean_T>
126 {
127  using value_type = bool;
128 };
129 template <>
130 struct DataTypeTraits<TypeInfo::char_T>
131 {
132  using value_type = char;
133 };
134 template <>
135 struct DataTypeTraits<TypeInfo::uint8_T>
136 {
137  using value_type = uint8_t;
138 };
139 template <>
140 struct DataTypeTraits<TypeInfo::int8_T>
141 {
142  using value_type = int8_t;
143 };
144 template <>
145 struct DataTypeTraits<TypeInfo::uint16_T>
146 {
147  using value_type = uint16_t;
148 };
149 template <>
150 struct DataTypeTraits<TypeInfo::int16_T>
151 {
152  using value_type = int16_t;
153 };
154 template <>
155 struct DataTypeTraits<TypeInfo::uint32_T>
156 {
157  using value_type = uint32_t;
158 };
159 template <>
160 struct DataTypeTraits<TypeInfo::int32_T>
161 {
162  using value_type = int32_t;
163 };
164 template <>
165 struct DataTypeTraits<TypeInfo::uint64_T>
166 {
167  using value_type = uint64_t;
168 };
169 template <>
170 struct DataTypeTraits<TypeInfo::int64_T>
171 {
172  using value_type = int64_t;
173 };
174 template <>
175 struct DataTypeTraits<TypeInfo::double_T>
176 {
177  using value_type = double;
178 };
179 template <>
180 struct DataTypeTraits<TypeInfo::single_T>
181 {
182  using value_type = float;
183 };
184 
185 template <class T, class /* sfinae */ = void>
186 struct is_contiguous : std::false_type
187 {};
188 
189 template <class T>
190 struct is_contiguous<std::vector<T>> : std::true_type
191 {};
192 
193 template <>
194 struct is_contiguous<std::vector<bool>> : std::false_type
195 {};
196 
197 template <class T, size_t N>
198 struct is_contiguous<std::array<T, N>> : std::true_type
199 {};
200 
201 template <class T>
202 struct is_contiguous<QVector<T>> : std::true_type
203 {};
204 
205 template <class Char, class Alloc, class Traits>
206 struct is_contiguous<std::basic_string<Char, Traits, Alloc>> : std::true_type
207 {};
208 
209 
227 void PDCOM5_PUBLIC copyData(
228  void *dst,
229  TypeInfo::DataType dst_type,
230  const void *src,
231  TypeInfo::DataType src_type,
232  size_t nelem,
233  size_t offset = 0);
234 }} // namespace PdCom::details
235 
236 #endif // PDCOM5_DETAILS_H
Type of a Variable.
Definition: SizeTypeInfo.h:33
Definition: Future.h:129
Definition: details.h:41
Definition: details.h:46
Definition: details.h:186
void PDCOM5_PUBLIC copyData(void *dst, TypeInfo::DataType dst_type, const void *src, TypeInfo::DataType src_type, size_t nelem, size_t offset=0)
Data Conversion Matrix.
library version string as "major.minor.patch"
Definition: ClientStatistics.h:31
Definition: details.h:122