15 return (*(
char*)&i) == 0;
24 static inline void SwitchWords(plUInt16* pWords, plUInt32 uiCount)
26 for (plUInt32 i = 0; i < uiCount; i++)
27 pWords[i] = Switch(pWords[i]);
31 static inline void SwitchDWords(plUInt32* pDWords, plUInt32 uiCount)
33 for (plUInt32 i = 0; i < uiCount; i++)
34 pDWords[i] = Switch(pDWords[i]);
38 static inline void SwitchQWords(plUInt64* pQWords, plUInt32 uiCount)
40 for (plUInt32 i = 0; i < uiCount; i++)
41 pQWords[i] = Switch(pQWords[i]);
45 static PL_ALWAYS_INLINE plUInt16
Switch(plUInt16 uiWord)
47 return (((uiWord & 0xFF) << 8) | ((uiWord >> 8) & 0xFF));
51 static PL_ALWAYS_INLINE plUInt32
Switch(plUInt32 uiDWord)
53 return (((uiDWord & 0xFF) << 24) | (((uiDWord >> 8) & 0xFF) << 16) | (((uiDWord >> 16) & 0xFF) << 8) | ((uiDWord >> 24) & 0xFF));
57 static PL_ALWAYS_INLINE plUInt64
Switch(plUInt64 uiQWord)
59 return (((uiQWord & 0xFF) << 56) | ((uiQWord & 0xFF00) << 40) | ((uiQWord & 0xFF0000) << 24) | ((uiQWord & 0xFF000000) << 8) |
60 ((uiQWord & 0xFF00000000) >> 8) | ((uiQWord & 0xFF0000000000) >> 24) | ((uiQWord & 0xFF000000000000) >> 40) |
61 ((uiQWord & 0xFF00000000000000) >> 56));
69 (
sizeof(T) == 2 ||
sizeof(T) == 4 ||
sizeof(T) == 8),
"Switch in place only works for type equivalents of plUInt16, plUInt32, plUInt64!");
83 Temp.TValue = *pValue;
84 Temp.BitValue = Switch(Temp.BitValue);
86 *pValue = Temp.TValue;
88 else if (
sizeof(T) == 4)
100 Temp.TValue = *pValue;
101 Temp.BitValue = Switch(Temp.BitValue);
103 *pValue = Temp.TValue;
105 else if (
sizeof(T) == 8)
107 struct TAnd64BitUnion
117 Temp.TValue = *pValue;
118 Temp.BitValue = Switch(Temp.BitValue);
120 *pValue = Temp.TValue;
124#if PL_ENABLED(PL_PLATFORM_LITTLE_ENDIAN)
126 static PL_ALWAYS_INLINE
void LittleEndianToNative(plUInt16* , plUInt32 )
130 static PL_ALWAYS_INLINE
void NativeToLittleEndian(plUInt16* , plUInt32 ) {}
132 static PL_ALWAYS_INLINE
void LittleEndianToNative(plUInt32* , plUInt32 ) {}
134 static PL_ALWAYS_INLINE
void NativeToLittleEndian(plUInt32* , plUInt32 ) {}
136 static PL_ALWAYS_INLINE
void LittleEndianToNative(plUInt64* , plUInt32 ) {}
138 static PL_ALWAYS_INLINE
void NativeToLittleEndian(plUInt64* , plUInt32 ) {}
140 static PL_ALWAYS_INLINE
void BigEndianToNative(plUInt16* pWords, plUInt32 uiCount) { SwitchWords(pWords, uiCount); }
142 static PL_ALWAYS_INLINE
void NativeToBigEndian(plUInt16* pWords, plUInt32 uiCount) { SwitchWords(pWords, uiCount); }
144 static PL_ALWAYS_INLINE
void BigEndianToNative(plUInt32* pDWords, plUInt32 uiCount) { SwitchDWords(pDWords, uiCount); }
146 static PL_ALWAYS_INLINE
void NativeToBigEndian(plUInt32* pDWords, plUInt32 uiCount) { SwitchDWords(pDWords, uiCount); }
148 static PL_ALWAYS_INLINE
void BigEndianToNative(plUInt64* pQWords, plUInt32 uiCount) { SwitchQWords(pQWords, uiCount); }
150 static PL_ALWAYS_INLINE
void NativeToBigEndian(plUInt64* pQWords, plUInt32 uiCount) { SwitchQWords(pQWords, uiCount); }
152#elif PL_ENABLED(PL_PLATFORM_BIG_ENDIAN)
154 static PL_ALWAYS_INLINE
void LittleEndianToNative(plUInt16* pWords, plUInt32 uiCount)
156 SwitchWords(pWords, uiCount);
159 static PL_ALWAYS_INLINE
void NativeToLittleEndian(plUInt16* pWords, plUInt32 uiCount) { SwitchWords(pWords, uiCount); }
161 static PL_ALWAYS_INLINE
void LittleEndianToNative(plUInt32* pDWords, plUInt32 uiCount) { SwitchDWords(pDWords, uiCount); }
163 static PL_ALWAYS_INLINE
void NativeToLittleEndian(plUInt32* pDWords, plUInt32 uiCount) { SwitchDWords(pDWords, uiCount); }
165 static PL_ALWAYS_INLINE
void LittleEndianToNative(plUInt64* pQWords, plUInt32 uiCount) { SwitchQWords(pQWords, uiCount); }
167 static PL_ALWAYS_INLINE
void NativeToLittleEndian(plUInt64* pQWords, plUInt32 uiCount) { SwitchQWords(pQWords, uiCount); }
169 static PL_ALWAYS_INLINE
void BigEndianToNative(plUInt16* , plUInt32 ) {}
171 static PL_ALWAYS_INLINE
void NativeToBigEndian(plUInt16* , plUInt32 ) {}
173 static PL_ALWAYS_INLINE
void BigEndianToNative(plUInt32* , plUInt32 ) {}
175 static PL_ALWAYS_INLINE
void NativeToBigEndian(plUInt32* , plUInt32 ) {}
177 static PL_ALWAYS_INLINE
void BigEndianToNative(plUInt64* , plUInt32 ) {}
179 static PL_ALWAYS_INLINE
void NativeToBigEndian(plUInt64* , plUInt32 ) {}
191 static void SwitchStruct(
void* pDataPointer,
const char* szFormat);
194 template <
typename T>
197 SwitchStruct(
static_cast<void*
>(pDataPointer), szFormat);
207 static void SwitchStructs(
void* pDataPointer,
const char* szFormat, plUInt32 uiStride, plUInt32 uiCount);
210 template <
typename T>
211 static void SwitchStructs(T* pDataPointer,
const char* szFormat, plUInt32 uiCount)
213 SwitchStructs(
static_cast<void*
>(pDataPointer), szFormat,
sizeof(T), uiCount);
static void SwitchDWords(plUInt32 *pDWords, plUInt32 uiCount)
Switches endianess of the given array of double words (32 bit values).
Definition EndianHelper.h:31
static void SwitchQWords(plUInt64 *pQWords, plUInt32 uiCount)
Switches endianess of the given array of quad words (64 bit values).
Definition EndianHelper.h:38
static void SwitchStructs(T *pDataPointer, const char *szFormat, plUInt32 uiCount)
Templated helper method for SwitchStructs.
Definition EndianHelper.h:211
static void SwitchWords(plUInt16 *pWords, plUInt32 uiCount)
Switches endianess of the given array of words (16 bit values).
Definition EndianHelper.h:24