Core/Endianness: Add SwapBytes shortcut

Former-commit-id: c345121453f38c9eb8c05e224db91f068440f729
This commit is contained in:
Lynix
2016-04-21 13:20:46 +02:00
parent 0d75f8ab2e
commit 3caeb91a32
2 changed files with 12 additions and 6 deletions

View File

@@ -12,7 +12,6 @@ namespace Nz
* \brief Gets the platform endianness
* \return Type of the endianness
*/
inline constexpr Endianness GetPlatformEndianness()
{
#if defined(NAZARA_BIG_ENDIAN)
@@ -29,10 +28,9 @@ namespace Nz
* \param buffer Raw memory
* \param size Size to change endianness
*
* \remark If size is greather than the preallocated buffer, the behaviour is undefined
* \remark If size is greater than the preallocated buffer, the behavior is undefined
*/
inline void SwapBytes(void* buffer, unsigned int size)
inline void SwapBytes(void* buffer, std::size_t size)
{
UInt8* bytes = static_cast<UInt8*>(buffer);
unsigned int i = 0;
@@ -41,6 +39,13 @@ namespace Nz
while (i < j)
std::swap(bytes[i++], bytes[j--]);
}
template<typename T>
T SwapBytes(T value)
{
SwapBytes(&value, sizeof(T));
return value;
}
}
#include <Nazara/Core/DebugOff.hpp>