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 
32 namespace lely {
33 
34 namespace canopen {
35 
36 namespace detail {
37 
42 template <class T>
43 struct IsCanopenBasic : ::std::false_type {};
44 
49 template <class T>
50 struct IsCanopenArray : ::std::false_type {};
51 
56 template <class T>
58  : ::std::integral_constant<bool, IsCanopenBasic<T>::value ||
59  IsCanopenArray<T>::value> {};
60 
65 template <>
66 struct IsCanopenBasic<bool> : ::std::true_type {};
67 
72 template <>
73 struct IsCanopenBasic<int8_t> : ::std::true_type {};
74 
79 template <>
80 struct IsCanopenBasic<int16_t> : ::std::true_type {};
81 
86 template <>
87 struct IsCanopenBasic<int32_t> : ::std::true_type {};
88 
93 template <>
94 struct IsCanopenBasic<uint8_t> : ::std::true_type {};
95 
100 template <>
101 struct IsCanopenBasic<uint16_t> : ::std::true_type {};
102 
107 template <>
108 struct IsCanopenBasic<uint32_t> : ::std::true_type {};
109 
114 template <>
115 struct IsCanopenBasic<float> : ::std::true_type {};
116 
121 template <>
122 struct IsCanopenArray<::std::string> : ::std::true_type {};
123 
128 template <>
129 struct IsCanopenArray<::std::vector<uint8_t>> : ::std::true_type {};
130 
135 template <>
136 struct IsCanopenArray<::std::basic_string<char16_t>> : ::std::true_type {};
137 
138 // TIME_OF_DAY
139 // TIME_DIFFERENCE
140 // DOMAIN
141 // INTEGER24
142 
147 template <>
148 struct IsCanopenBasic<double> : ::std::true_type {};
149 
150 // INTEGER40
151 // INTEGER48
152 // INTEGER56
153 
158 template <>
159 struct IsCanopenBasic<int64_t> : ::std::true_type {};
160 
161 // UNSIGNED24
162 // UNSIGNED40
163 // UNSIGNED48
164 // UNSIGNED56
165 
170 template <>
171 struct IsCanopenBasic<uint64_t> : ::std::true_type {};
172 
177 inline bool
178 IsCanopenSame(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.
#define CO_DEFTYPE_DOMAIN
The data type (and object index) of an arbitrary large block of data.
Definition: type.h:77
If T is one of the CANopen basic or array types, provides the member constant value equal to true...
Definition: type_traits.hpp:57
If T is one of the CANopen basic types, provides the member constant value equal to true...
Definition: type_traits.hpp:43
#define CO_DEFTYPE_OCTET_STRING
The data type (and object index) of an array of octets.
Definition: type.h:59
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
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...
This header file is part of the CANopen library; it contains the CANopen type definitions.