diff --git a/include/Nazara/Core/Endianness.hpp b/include/Nazara/Core/Endianness.hpp index 44a4e9f26..8bd1d61b4 100644 --- a/include/Nazara/Core/Endianness.hpp +++ b/include/Nazara/Core/Endianness.hpp @@ -11,7 +11,7 @@ #include #if !defined(NAZARA_BIG_ENDIAN) && !defined(NAZARA_LITTLE_ENDIAN) - // Automatic detection following macroes of compiler + // Automatic detection following macros of compiler #if defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || (defined(__MIPS__) && defined(__MISPEB__)) || \ defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || defined(__sparc__) || defined(__hppa__) #define NAZARA_BIG_ENDIAN @@ -28,7 +28,8 @@ namespace Nz { inline constexpr Endianness GetPlatformEndianness(); - inline void SwapBytes(void* buffer, unsigned int size); + inline void SwapBytes(void* buffer, std::size_t size); + template T SwapBytes(T value); } #include diff --git a/include/Nazara/Core/Endianness.inl b/include/Nazara/Core/Endianness.inl index 2949e3f19..ee0d094ca 100644 --- a/include/Nazara/Core/Endianness.inl +++ b/include/Nazara/Core/Endianness.inl @@ -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(buffer); unsigned int i = 0; @@ -41,6 +39,13 @@ namespace Nz while (i < j) std::swap(bytes[i++], bytes[j--]); } + + template + T SwapBytes(T value) + { + SwapBytes(&value, sizeof(T)); + return value; + } } #include