75 #ifndef MUI_ENDIAN_TRAITS_H_
76 #define MUI_ENDIAN_TRAITS_H_
82 # include <machine/endian.h>
83 # include <libkern/OSByteOrder.h>
85 # define htobe16(x) OSSwapHostToBigInt16(x)
86 # define htole16(x) OSSwapHostToLittleInt16(x)
87 # define be16toh(x) OSSwapBigToHostInt16(x)
88 # define le16toh(x) OSSwapLittleToHostInt16(x)
90 # define htobe32(x) OSSwapHostToBigInt32(x)
91 # define htole32(x) OSSwapHostToLittleInt32(x)
92 # define be32toh(x) OSSwapBigToHostInt32(x)
93 # define le32toh(x) OSSwapLittleToHostInt32(x)
95 # define htobe64(x) OSSwapHostToBigInt64(x)
96 # define htole64(x) OSSwapHostToLittleInt64(x)
97 # define be64toh(x) OSSwapBigToHostInt64(x)
98 # define le64toh(x) OSSwapLittleToHostInt64(x)
103 # define MUI_POSITIVE true
104 # define MUI_NEGATIVE false
109 #ifdef MUI_IGNORE_ENDIAN
111 # if defined(MUI_INT_BIG_ENDIAN) || defined(MUI_INT_LITTLE_ENDIAN) || defined(MUI_FLOAT_BIG_ENDIAN) || defined(MUI_FLOAT_LITTLE_ENDIAN)
112 # error "MUI Error [endian_traits.h]: Must set no other MUI endian options with MUI_IGNORE_ENDIAN"
116 # define MUI_CONVERT_INT false
117 # define MUI_CONVERT_FLOAT false
122 # ifdef MUI_INT_BIG_ENDIAN
123 # ifdef MUI_INT_LITTLE_ENDIAN
124 # error "MUI Error [endian_traits.h]: Both MUI_INT_BIG_ENDIAN and MUI_INT_LITTLE_ENDIAN defined"
126 # define MUI_INT_DEFINED MUI_POSITIVE
127 # define MUI_CONVERT_INT false
130 # ifdef MUI_INT_LITTLE_ENDIAN
131 # define MUI_INT_DEFINED MUI_POSITIVE
132 # define MUI_CONVERT_INT true
135 # if defined(__BYTE_ORDER__)
136 # define MUI_INT_DEFINED MUI_POSITIVE
137 # define MUI_CONVERT_INT (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__)
139 # define MUI_INT_DEFINED MUI_NEGATIVE
140 # error "MUI Error [endian_traits.h]: Cannot auto-detect integer endianness of platform - please set at compilation (-DMUI_INT_LITTLE_ENDIAN or -DMUI_INT_BIG_ENDIAN) or set to ignore (-DMUI_IGNORE_ENDIAN)"
146 # ifdef MUI_FLOAT_BIG_ENDIAN
147 # ifdef MUI_FLOAT_LITTLE_ENDIAN
148 # error "MUI Error [endian_traits.h]: Both MUI_FLOAT_BIG_ENDIAN and MUI_FLOAT_LITTLE_ENDIAN defined"
150 # define MUI_CONVERT_FLOAT false
153 # ifdef MUI_FLOAT_LITTLE_ENDIAN
154 # define MUI_CONVERT_FLOAT true
157 # if defined(__FLOAT_WORD_ORDER__)
158 # define MUI_CONVERT_FLOAT (__FLOAT_WORD_ORDER__ != __ORDER_BIG_ENDIAN__)
160 # if MUI_INT_DEFINED == MUI_POSITIVE
161 # define MUI_CONVERT_FLOAT MUI_CONVERT_INT
162 # warning "MUI Warning [endian_traits.h]: Cannot auto-detect float endianness of platform - please set at compilation (-DMUI_FLOAT_LITTLE_ENDIAN or -DMUI_FLOAT_BIG_ENDIAN) or set to ignore (-DMUI_IGNORE_ENDIAN), integer endianness will be followed by default"
164 # error "MUI Error [endian_traits.h]: Cannot auto-detect float endianness of platform - please set at compilation (-DMUI_FLOAT_LITTLE_ENDIAN or -DMUI_FLOAT_BIG_ENDIAN) or set to ignore (-DMUI_IGNORE_ENDIAN)"
177 template<
size_t size_
bytes>
199 template<
size_t size_
bytes>
212 data.val = htobe16(data.val);
216 data.val = be16toh(data.val);
220 data.val = htobe32(data.val);
224 data.val = be32toh(data.val);
228 data.val = htobe64(data.val);
232 data.val = be64toh(data.val);
246 template<
typename T,
typename enable =
void>
251 struct endian_traits<
T, typename std::enable_if<std::is_integral<T>::value>::type>
253 static constexpr
bool convert = (
sizeof(
T) > 1) && MUI_CONVERT_INT;
258 struct endian_traits<
T, typename std::enable_if<std::is_floating_point<T>::value>::type>
#define MUI_CONVERT_FLOAT
Definition: endian_traits.h:161
Definition: endian_traits.h:200
data_t data
Definition: endian_traits.h:205
uint8_t type
Definition: endian_traits.h:182
uint16_t type
Definition: endian_traits.h:186
uint32_t type
Definition: endian_traits.h:190
uint64_t type
Definition: endian_traits.h:194
Definition: endian_traits.h:178
Definition: endian_traits.h:247
Definition: endian_traits.h:201
char buf[size_bytes]
Definition: endian_traits.h:202
uint< size_bytes >::type val
Definition: endian_traits.h:203