Documentation for Endiannes
Former-commit-id: e45c5026b84aa8b354e29d760eff56d13f2dc745
This commit is contained in:
parent
0a4381a95b
commit
61542b59d6
|
|
@ -11,12 +11,12 @@
|
||||||
#include <Nazara/Core/Enums.hpp>
|
#include <Nazara/Core/Enums.hpp>
|
||||||
|
|
||||||
#if !defined(NAZARA_BIG_ENDIAN) && !defined(NAZARA_LITTLE_ENDIAN)
|
#if !defined(NAZARA_BIG_ENDIAN) && !defined(NAZARA_LITTLE_ENDIAN)
|
||||||
// Détection automatique selon les macros du compilateur
|
// Automatic detection following macroes of compiler
|
||||||
#if defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || (defined(__MIPS__) && defined(__MISPEB__)) || \
|
#if defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || (defined(__MIPS__) && defined(__MISPEB__)) || \
|
||||||
defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || defined(__sparc__) || defined(__hppa__)
|
defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || defined(__sparc__) || defined(__hppa__)
|
||||||
#define NAZARA_BIG_ENDIAN
|
#define NAZARA_BIG_ENDIAN
|
||||||
#elif defined(__i386__) || defined(__i386) || defined(__X86__) || defined (__x86_64) || defined(_M_I86) || \
|
#elif defined(__i386__) || defined(__i386) || defined(__X86__) || defined (__x86_64) || defined(_M_I86) || \
|
||||||
defined(_M_IX86) || defined(_M_X64)
|
defined(_M_IX86) || defined(_M_X64)
|
||||||
#define NAZARA_LITTLE_ENDIAN
|
#define NAZARA_LITTLE_ENDIAN
|
||||||
#else
|
#else
|
||||||
#error Failed to identify endianness, you must define either NAZARA_BIG_ENDIAN or NAZARA_LITTLE_ENDIAN
|
#error Failed to identify endianness, you must define either NAZARA_BIG_ENDIAN or NAZARA_LITTLE_ENDIAN
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,11 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
/*!
|
||||||
|
* \brief Gets the platform endianness
|
||||||
|
* \return Type of the endianness
|
||||||
|
*/
|
||||||
|
|
||||||
inline constexpr Endianness GetPlatformEndianness()
|
inline constexpr Endianness GetPlatformEndianness()
|
||||||
{
|
{
|
||||||
#if defined(NAZARA_BIG_ENDIAN)
|
#if defined(NAZARA_BIG_ENDIAN)
|
||||||
|
|
@ -16,11 +21,20 @@ namespace Nz
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Swaps the byte for endianness operations
|
||||||
|
*
|
||||||
|
* \param buffer Raw memory
|
||||||
|
* \param size Size to change endianness
|
||||||
|
*
|
||||||
|
* \remark If size is greather than the preallocated buffer, the behaviour is undefined
|
||||||
|
*/
|
||||||
|
|
||||||
inline void SwapBytes(void* buffer, unsigned int size)
|
inline void SwapBytes(void* buffer, unsigned int size)
|
||||||
{
|
{
|
||||||
UInt8* bytes = reinterpret_cast<UInt8*>(buffer);
|
UInt8* bytes = reinterpret_cast<UInt8*>(buffer);
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
unsigned int j = size-1;
|
unsigned int j = size - 1;
|
||||||
|
|
||||||
while (i < j)
|
while (i < j)
|
||||||
std::swap(bytes[i++], bytes[j--]);
|
std::swap(bytes[i++], bytes[j--]);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue