46 #ifndef AI_BYTESWAPPER_H_INC
47 #define AI_BYTESWAPPER_H_INC
50 # pragma GCC system_header
53 #include <assimp/ai_assert.h>
76 static inline void Swap2(
void* _szOut)
81 uint16_t*
const szOut =
reinterpret_cast<uint16_t*
>(_szOut);
82 *szOut = _byteswap_ushort(*szOut);
84 uint8_t*
const szOut =
reinterpret_cast<uint8_t*
>(_szOut);
85 std::swap(szOut[0],szOut[1]);
92 static inline void Swap4(
void* _szOut)
97 uint32_t*
const szOut =
reinterpret_cast<uint32_t*
>(_szOut);
98 *szOut = _byteswap_ulong(*szOut);
100 uint8_t*
const szOut =
reinterpret_cast<uint8_t*
>(_szOut);
101 std::swap(szOut[0],szOut[3]);
102 std::swap(szOut[1],szOut[2]);
109 static inline void Swap8(
void* _szOut)
114 uint64_t*
const szOut =
reinterpret_cast<uint64_t*
>(_szOut);
115 *szOut = _byteswap_uint64(*szOut);
117 uint8_t*
const szOut =
reinterpret_cast<uint8_t*
>(_szOut);
118 std::swap(szOut[0],szOut[7]);
119 std::swap(szOut[1],szOut[6]);
120 std::swap(szOut[2],szOut[5]);
121 std::swap(szOut[3],szOut[4]);
128 static inline void Swap(
float* fOut) {
135 static inline void Swap(
double* fOut) {
143 static inline void Swap(int16_t* fOut) {
147 static inline void Swap(uint16_t* fOut) {
154 static inline void Swap(int32_t* fOut){
158 static inline void Swap(uint32_t* fOut){
165 static inline void Swap(int64_t* fOut) {
169 static inline void Swap(uint64_t* fOut) {
176 template<
typename Type>
179 return _swapper<Type,sizeof(Type)>()(tOut);
184 template <
typename T,
size_t size>
struct _swapper;
187 template <
typename T>
struct ByteSwap::_swapper<T,2> {
188 T operator() (T tOut) {
194 template <
typename T>
struct ByteSwap::_swapper<T,4> {
195 T operator() (T tOut) {
201 template <
typename T>
struct ByteSwap::_swapper<T,8> {
202 T operator() (T tOut) {
212 #if (defined AI_BUILD_BIG_ENDIAN)
213 # define AI_LE(t) (t)
214 # define AI_BE(t) ByteSwap::Swapped(t)
215 # define AI_LSWAP2(p)
216 # define AI_LSWAP4(p)
217 # define AI_LSWAP8(p)
218 # define AI_LSWAP2P(p)
219 # define AI_LSWAP4P(p)
220 # define AI_LSWAP8P(p)
221 # define LE_NCONST const
222 # define AI_SWAP2(p) ByteSwap::Swap2(&(p))
223 # define AI_SWAP4(p) ByteSwap::Swap4(&(p))
224 # define AI_SWAP8(p) ByteSwap::Swap8(&(p))
225 # define AI_SWAP2P(p) ByteSwap::Swap2((p))
226 # define AI_SWAP4P(p) ByteSwap::Swap4((p))
227 # define AI_SWAP8P(p) ByteSwap::Swap8((p))
230 # define AI_BE(t) (t)
231 # define AI_LE(t) ByteSwap::Swapped(t)
235 # define AI_SWAP2P(p)
236 # define AI_SWAP4P(p)
237 # define AI_SWAP8P(p)
238 # define BE_NCONST const
239 # define AI_LSWAP2(p) ByteSwap::Swap2(&(p))
240 # define AI_LSWAP4(p) ByteSwap::Swap4(&(p))
241 # define AI_LSWAP8(p) ByteSwap::Swap8(&(p))
242 # define AI_LSWAP2P(p) ByteSwap::Swap2((p))
243 # define AI_LSWAP4P(p) ByteSwap::Swap4((p))
244 # define AI_LSWAP8P(p) ByteSwap::Swap8((p))
252 template <
typename T,
bool doit>
254 void operator() (T* inout) {
259 template <
typename T>
261 void operator() (T*) {
266 template <
bool SwapEndianess,
typename T,
bool RuntimeSwitch>
268 void operator() (T* inout,
bool le) {
269 #ifdef AI_BUILD_BIG_ENDIAN
275 ByteSwapper<T,(
sizeof(T)>1?
true:
false)> () (inout);
281 template <
bool SwapEndianess,
typename T>
284 void operator() (T* inout,
bool ) {
286 ByteSwapper<T,(SwapEndianess &&
sizeof(T)>1)> () (inout);