Lely core libraries  2.2.5
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 
27 #include <string>
28 #include <type_traits>
29 #include <vector>
30 
31 namespace lely {
32 
33 namespace canopen {
34 
35 namespace detail {
36 
41 template <class T>
42 struct is_canopen_basic : ::std::false_type {};
43 
48 template <class T>
49 struct is_canopen_array : ::std::false_type {};
50 
55 template <class T>
57  : ::std::integral_constant<bool, is_canopen_basic<T>::value ||
58  is_canopen_array<T>::value> {};
59 
64 template <>
65 struct is_canopen_basic<bool> : ::std::true_type {};
66 
71 template <>
72 struct is_canopen_basic<int8_t> : ::std::true_type {};
73 
78 template <>
79 struct is_canopen_basic<int16_t> : ::std::true_type {};
80 
85 template <>
86 struct is_canopen_basic<int32_t> : ::std::true_type {};
87 
92 template <>
93 struct is_canopen_basic<uint8_t> : ::std::true_type {};
94 
99 template <>
100 struct is_canopen_basic<uint16_t> : ::std::true_type {};
101 
106 template <>
107 struct is_canopen_basic<uint32_t> : ::std::true_type {};
108 
113 template <>
114 struct is_canopen_basic<float> : ::std::true_type {};
115 
120 template <>
121 struct is_canopen_array<::std::string> : ::std::true_type {};
122 
127 template <>
128 struct is_canopen_array<::std::vector<uint8_t>> : ::std::true_type {};
129 
134 template <>
135 struct is_canopen_array<::std::basic_string<char16_t>> : ::std::true_type {};
136 
137 // TIME_OF_DAY
138 // TIME_DIFFERENCE
139 // DOMAIN
140 // INTEGER24
141 
146 template <>
147 struct is_canopen_basic<double> : ::std::true_type {};
148 
149 // INTEGER40
150 // INTEGER48
151 // INTEGER56
152 
157 template <>
158 struct is_canopen_basic<int64_t> : ::std::true_type {};
159 
160 // UNSIGNED24
161 // UNSIGNED40
162 // UNSIGNED48
163 // UNSIGNED56
164 
169 template <>
170 struct is_canopen_basic<uint64_t> : ::std::true_type {};
171 
176 inline bool
177 is_canopen_same(uint16_t t1, uint16_t t2) {
178  if (t1 == t2) return true;
179 
180  // OCTET_STRING and DOMAIN are both byte arrays.
181  if ((t1 == CO_DEFTYPE_OCTET_STRING && t2 == CO_DEFTYPE_DOMAIN) ||
183  return true;
184 
185  return false;
186 }
187 
188 } // namespace detail
189 
190 } // namespace canopen
191 
192 } // namespace lely
193 
194 #endif // LELY_COAPP_DETAIL_TYPE_TRAITS_HPP_
#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
If T is one of the CANopen basic or array types, provides the member constant value equal to true...
Definition: type_traits.hpp:56
If T is one of the CANopen basic types, provides the member constant value equal to true...
Definition: type_traits.hpp:42
bool is_canopen_same(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...
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:49
This header file is part of the CANopen library; it contains the CANopen type definitions.