Add template-based BE(T) endianness conversion helper types

Doesn't require modification at the call sites thanks to the implicit conversion operator.
This commit is contained in:
PJB3005
2026-02-24 16:29:00 +01:00
parent 1b6a118eae
commit 36895ee3b6
+37
View File
@@ -54,4 +54,41 @@ static inline s32 RES_S32(s32 v) {
#define RES_S32(x) (x)
#endif
#ifdef TARGET_PC
/*
* Declares a big-endian integer type.
*/
template<class T>
struct BE {
T inner;
operator T() const;
};
template<>
inline BE<u16>::operator u16() const {
return RES_U16(inner);
}
template<>
inline BE<s16>::operator s16() const {
return RES_S16(inner);
}
template<>
inline BE<u32>::operator u32() const {
return RES_U32(inner);
}
template<>
inline BE<s32>::operator s32() const {
return RES_S32(inner);
}
#define BE(T) BE<T>
#else
#define BE(T) T
#endif
#endif // DOLPHIN_ENDIAN_H