Lely core libraries 1.9.2
type_traits.hpp
Go to the documentation of this file.
1
22#ifndef LELY_COAPP_DETAIL_TYPE_TRAITS_HPP_
23#define LELY_COAPP_DETAIL_TYPE_TRAITS_HPP_
24
25#include <lely/co/type.h>
26#include <lely/coapp/coapp.hpp>
27
28#include <string>
29#include <type_traits>
30#include <vector>
31
32namespace lely {
33
34namespace canopen {
35
36namespace detail {
37
42template <class T>
43struct IsCanopenBasic : ::std::false_type {};
44
49template <class T>
50struct IsCanopenArray : ::std::false_type {};
51
56template <class T>
58 : ::std::integral_constant<bool, IsCanopenBasic<T>::value ||
59 IsCanopenArray<T>::value> {};
60
65template <>
66struct IsCanopenBasic<bool> : ::std::true_type {};
67
72template <>
73struct IsCanopenBasic<int8_t> : ::std::true_type {};
74
79template <>
80struct IsCanopenBasic<int16_t> : ::std::true_type {};
81
86template <>
87struct IsCanopenBasic<int32_t> : ::std::true_type {};
88
93template <>
94struct IsCanopenBasic<uint8_t> : ::std::true_type {};
95
100template <>
101struct IsCanopenBasic<uint16_t> : ::std::true_type {};
102
107template <>
108struct IsCanopenBasic<uint32_t> : ::std::true_type {};
109
114template <>
115struct IsCanopenBasic<float> : ::std::true_type {};
116
121template <>
122struct IsCanopenArray<::std::string> : ::std::true_type {};
123
128template <>
129struct IsCanopenArray<::std::vector<uint8_t>> : ::std::true_type {};
130
135template <>
136struct IsCanopenArray<::std::basic_string<char16_t>> : ::std::true_type {};
137
138// TIME_OF_DAY
139// TIME_DIFFERENCE
140// DOMAIN
141// INTEGER24
142
147template <>
148struct IsCanopenBasic<double> : ::std::true_type {};
149
150// INTEGER40
151// INTEGER48
152// INTEGER56
153
158template <>
159struct IsCanopenBasic<int64_t> : ::std::true_type {};
160
161// UNSIGNED24
162// UNSIGNED40
163// UNSIGNED48
164// UNSIGNED56
165
170template <>
171struct IsCanopenBasic<uint64_t> : ::std::true_type {};
172
177inline bool
178IsCanopenSame(uint16_t t1, uint16_t t2) {
179 if (t1 == t2) return true;
180
181 // OCTET_STRING and DOMAIN are both byte arrays.
182 if ((t1 == CO_DEFTYPE_OCTET_STRING && t2 == CO_DEFTYPE_DOMAIN) ||
184 return true;
185
186 return false;
187}
188
189} // namespace detail
190
191} // namespace canopen
192
193} // namespace lely
194
195#endif // LELY_COAPP_DETAIL_TYPE_TRAITS_HPP_
This is the public header file of the C++ CANopen application library.
bool IsCanopenSame(uint16_t t1, uint16_t t2)
Returns true if the CANopen data types t1 and t2 map to the same C++ type, and false if not.
Global namespace for the Lely Industries N.V. libraries.
Definition: buf.hpp:32
If T is one of the CANopen array types, provides the member constant value equal to true.
Definition: type_traits.hpp:50
If T is one of the CANopen basic types, provides the member constant value equal to true.
Definition: type_traits.hpp:43
If T is one of the CANopen basic or array types, provides the member constant value equal to true.
Definition: type_traits.hpp:59
This header file is part of the CANopen library; it contains the CANopen type definitions.
#define CO_DEFTYPE_DOMAIN
The data type (and object index) of an arbitrary large block of data.
Definition: type.h:77
#define CO_DEFTYPE_OCTET_STRING
The data type (and object index) of an array of octets.
Definition: type.h:59