22 #ifndef LELY_COAPP_TYPE_TRAITS_HPP_
23 #define LELY_COAPP_TYPE_TRAITS_HPP_
28 #include <system_error>
29 #include <type_traits>
40 template <
class, u
int16_t,
bool = false>
43 template <
class T, u
int16_t N>
47 static constexpr uint16_t index = N;
49 static constexpr
bool is_basic =
false;
52 template <
class T, u
int16_t N>
58 static constexpr uint16_t index = N;
60 static constexpr
bool is_basic =
true;
62 static c_type construct(
const void* p, ::std::size_t n,
63 ::std::error_code& ec) noexcept;
66 destroy(c_type& ) noexcept {}
69 from_c_type(c_type val) noexcept {
73 static constexpr c_type
74 to_c_type(type value, ::std::error_code& ) noexcept {
78 static constexpr
void*
79 address(c_type& val) noexcept {
83 static constexpr
const void*
84 address(
const c_type& val) noexcept {
88 static constexpr ::std::size_t
89 size(
const c_type& ) noexcept {
90 return sizeof(c_type);
168 using c_type =
char*;
170 static char* construct(
const void* p, ::std::size_t n,
171 ::std::error_code& ec) noexcept;
173 static void destroy(
char*& val) noexcept;
176 from_c_type(
const char* val) {
177 return val ? ::std::string{val} : ::std::string{};
181 to_c_type(
const type& vs, ::std::error_code& ec) noexcept {
182 return to_c_type(vs.c_str(), ec);
185 static char* to_c_type(
const char* vs, ::std::error_code& ec) noexcept;
187 static constexpr
void*
188 address(
char* val) noexcept {
192 static constexpr
const void*
193 address(
const char* val) noexcept {
198 size(
const char* val) noexcept {
199 return val ? ::std::char_traits<char>::length(val) : 0;
210 using c_type = uint8_t*;
212 static uint8_t* construct(
const void* p, ::std::size_t n,
213 ::std::error_code& ec) noexcept;
215 static void destroy(uint8_t*& val) noexcept;
217 static ::std::vector<uint8_t>
218 from_c_type(
const uint8_t* val) {
219 return {val, val + size(val)};
223 to_c_type(const ::std::vector<uint8_t>& os, ::std::error_code& ec) noexcept {
224 return to_c_type(os.data(), os.size(), ec);
227 static uint8_t* to_c_type(
const uint8_t* os, ::std::size_t n,
228 ::std::error_code& ec) noexcept;
230 static constexpr
void*
231 address(uint8_t* val) noexcept {
235 static constexpr
const void*
236 address(
const uint8_t* val) noexcept {
240 static ::std::size_t size(
const uint8_t* val) noexcept;
250 using c_type = char16_t*;
252 static char16_t* construct(
const void* p, ::std::size_t n,
253 ::std::error_code& ec) noexcept;
255 static void destroy(char16_t*& val) noexcept;
257 static ::std::basic_string<char16_t>
258 from_c_type(
const char16_t* val) {
259 return val ? ::std::basic_string<char16_t>{val}
260 : ::std::basic_string<char16_t>{};
264 to_c_type(const ::std::basic_string<char16_t>& us,
265 ::std::error_code& ec) noexcept {
266 return to_c_type(us.c_str(), ec);
269 static char16_t* to_c_type(
const char16_t* us,
270 ::std::error_code& ec) noexcept;
272 static constexpr
void*
273 address(char16_t* val) noexcept {
277 static constexpr
const void*
278 address(
const char16_t* val) noexcept {
283 size(
const char16_t* val) noexcept {
284 return val ? ::std::char_traits<char16_t>::length(val) : 0;
329 template <
class T,
class = T>
339 template <
class T,
class = T>
344 : ::std::integral_constant<bool, canopen_traits<T>::is_basic> {};
350 inline constexpr
bool
353 return t1 == t2 || (t1 == 0x000a && t2 == 0x000f) ||
354 (t1 == 0x000f && t2 == 0x000a);
This header file is part of the Lely libraries; it contains the compiler feature definitions.
constexpr bool is_canopen_same(uint16_t t1, uint16_t t2) noexcept
Returns true if the CANopen data types t1 and t2 map to the same C++ type, and false if not.
A class template mapping CANopen types to C and C++ types.
If T is one of the CANopen basic types, provides the member constant value equal to true.
If T is one of the CANopen basic or array types, provides the member constant value equal to true.