PdCom  5.3
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 
32 #include <array>
33 #include <cstddef>
34 #include <cstdint>
35 #include <pdcom5_export.h>
36 #include <string>
37 #include <type_traits>
38 #include <vector>
39 
40 namespace PdCom { namespace details {
41 
42 template <typename T>
44 {};
45 template <>
46 struct TypeInfoTraits<bool>
47 {
48  static constexpr TypeInfo type_info = {
49  TypeInfo::boolean_T, "bool", sizeof(bool)};
50 };
51 template <>
52 struct TypeInfoTraits<char>
53 {
54  static constexpr TypeInfo type_info = {
55  TypeInfo::char_T, "char", sizeof(char)};
56 };
57 template <>
58 struct TypeInfoTraits<uint8_t>
59 {
60  static constexpr TypeInfo type_info = {
61  TypeInfo::uint8_T, "uint8_t", sizeof(uint8_t)};
62 };
63 template <>
64 struct TypeInfoTraits<int8_t>
65 {
66  static constexpr TypeInfo type_info = {
67  TypeInfo::int8_T, "int8_t", sizeof(int8_t)};
68 };
69 template <>
70 struct TypeInfoTraits<uint16_t>
71 {
72  static constexpr TypeInfo type_info = {
73  TypeInfo::uint16_T, "uint16_t", sizeof(uint16_t)};
74 };
75 template <>
76 struct TypeInfoTraits<int16_t>
77 {
78  static constexpr TypeInfo type_info = {
79  TypeInfo::int16_T, "int16_t", sizeof(int16_t)};
80 };
81 template <>
82 struct TypeInfoTraits<uint32_t>
83 {
84  static constexpr TypeInfo type_info = {
85  TypeInfo::uint32_T, "uint32_t", sizeof(uint32_t)};
86 };
87 template <>
88 struct TypeInfoTraits<int32_t>
89 {
90  static constexpr TypeInfo type_info = {
91  TypeInfo::int32_T, "int32_t", sizeof(int32_t)};
92 };
93 template <>
94 struct TypeInfoTraits<uint64_t>
95 {
96  static constexpr TypeInfo type_info = {
97  TypeInfo::uint64_T, "uint64_t", sizeof(uint64_t)};
98 };
99 template <>
100 struct TypeInfoTraits<int64_t>
101 {
102  static constexpr TypeInfo type_info = {
103  TypeInfo::int64_T, "int64_t", sizeof(int64_t)};
104 };
105 template <>
106 struct TypeInfoTraits<double>
107 {
108  static constexpr TypeInfo type_info = {
109  TypeInfo::double_T, "double", sizeof(double)};
110 };
111 template <>
112 struct TypeInfoTraits<float>
113 {
114  static constexpr TypeInfo type_info = {
115  TypeInfo::single_T, "float", sizeof(float)};
116 };
117 
118 template <TypeInfo::DataType dtype>
120 {};
121 template <>
122 struct DataTypeTraits<TypeInfo::boolean_T>
123 {
124  using value_type = bool;
125 };
126 template <>
127 struct DataTypeTraits<TypeInfo::char_T>
128 {
129  using value_type = char;
130 };
131 template <>
132 struct DataTypeTraits<TypeInfo::uint8_T>
133 {
134  using value_type = uint8_t;
135 };
136 template <>
137 struct DataTypeTraits<TypeInfo::int8_T>
138 {
139  using value_type = int8_t;
140 };
141 template <>
142 struct DataTypeTraits<TypeInfo::uint16_T>
143 {
144  using value_type = uint16_t;
145 };
146 template <>
147 struct DataTypeTraits<TypeInfo::int16_T>
148 {
149  using value_type = int16_t;
150 };
151 template <>
152 struct DataTypeTraits<TypeInfo::uint32_T>
153 {
154  using value_type = uint32_t;
155 };
156 template <>
157 struct DataTypeTraits<TypeInfo::int32_T>
158 {
159  using value_type = int32_t;
160 };
161 template <>
162 struct DataTypeTraits<TypeInfo::uint64_T>
163 {
164  using value_type = uint64_t;
165 };
166 template <>
167 struct DataTypeTraits<TypeInfo::int64_T>
168 {
169  using value_type = int64_t;
170 };
171 template <>
172 struct DataTypeTraits<TypeInfo::double_T>
173 {
174  using value_type = double;
175 };
176 template <>
177 struct DataTypeTraits<TypeInfo::single_T>
178 {
179  using value_type = float;
180 };
181 
182 template <class T, class /* sfinae */ = void>
183 struct is_contiguous : std::false_type
184 {};
185 
186 template <class T>
187 struct is_contiguous<std::vector<T>> : std::true_type
188 {};
189 
190 template <>
191 struct is_contiguous<std::vector<bool>> : std::false_type
192 {};
193 
194 template <class T, size_t N>
195 struct is_contiguous<std::array<T, N>> : std::true_type
196 {};
197 
198 template <class Char, class Alloc, class Traits>
199 struct is_contiguous<std::basic_string<Char, Traits, Alloc>> : std::true_type
200 {};
201 
202 
220 void PDCOM5_PUBLIC copyData(
221  void *dst,
222  TypeInfo::DataType dst_type,
223  const void *src,
224  TypeInfo::DataType src_type,
225  size_t nelem,
226  size_t offset = 0);
227 
228 }} // namespace PdCom::details
229 
230 #endif // PDCOM5_DETAILS_H
Type of a Variable.
Definition: SizeTypeInfo.h:33
Definition: Future.h:128
Definition: details.h:43
Definition: details.h:183
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.
Definition: ClientStatistics.h:31
Definition: details.h:119