SDL_endian.h: Documented SDL_Swap* macros.

main
Ryan C. Gordon 2024-04-09 09:58:01 -04:00
parent e044318a8e
commit 79dc6af98f
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
1 changed files with 91 additions and 23 deletions

View File

@ -323,52 +323,121 @@ SDL_SwapFloat(float x)
#undef HAS_BUILTIN_BSWAP32 #undef HAS_BUILTIN_BSWAP32
#undef HAS_BUILTIN_BSWAP64 #undef HAS_BUILTIN_BSWAP64
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/** /**
* \name Swap to native * Swap a 16-bit value from littleendian to native format.
* Byteswap item from the specified endianness to the native endianness. *
* If this is running on a littleendian system, `X` is returned unchanged.
*
* This macro never references `X` more than once, avoiding side effects.
*
* \param X the value to swap.
* \returns the byte-swapped value.
*
* \since This macro is available since SDL 3.0.0.
*/ */
#define SDL_SwapLE16(X) SwapOnlyIfNecessary(X)
/** /**
* \def SDL_SwapLE16 * Swap a 32-bit value from littleendian to native format.
* Swap 16-bit little endian integer to 16-bit native endian integer. *
* If this is running on a littleendian system, `X` is returned unchanged.
*
* This macro never references `X` more than once, avoiding side effects.
*
* \param X the value to swap.
* \returns the byte-swapped value.
*
* \since This macro is available since SDL 3.0.0.
*/ */
#define SDL_SwapLE32(X) SwapOnlyIfNecessary(X)
/** /**
* \def SDL_SwapLE32 * Swap a 64-bit value from littleendian to native format.
* Swap 32-bit little endian integer to 32-bit native endian integer. *
* If this is running on a littleendian system, `X` is returned unchanged.
*
* This macro never references `X` more than once, avoiding side effects.
*
* \param X the value to swap.
* \returns the byte-swapped value.
*
* \since This macro is available since SDL 3.0.0.
*/ */
#define SDL_SwapLE64(X) SwapOnlyIfNecessary(X)
/** /**
* \def SDL_SwapLE64 * Swap a floating point value from littleendian to native format.
* Swap 64-bit little endian integer to 64-bit native endian integer. *
* If this is running on a littleendian system, `X` is returned unchanged.
*
* This macro never references `X` more than once, avoiding side effects.
*
* \param X the value to swap.
* \returns the byte-swapped value.
*
* \since This macro is available since SDL 3.0.0.
*/ */
#define SDL_SwapFloatLE(X) SwapOnlyIfNecessary(X)
/** /**
* \def SDL_SwapFloatLE * Swap a 16-bit value from bigendian to native format.
* Swap little endian float to native endian float. *
*/ * If this is running on a bigendian system, `X` is returned unchanged.
/** *
* \def SDL_SwapBE16 * This macro never references `X` more than once, avoiding side effects.
* Swap 16-bit big endian integer to 16-bit native endian integer. *
* \param X the value to swap.
* \returns the byte-swapped value.
*
* \since This macro is available since SDL 3.0.0.
*/ */
#define SDL_SwapBE16(X) SwapOnlyIfNecessary(X)
/** /**
* \def SDL_SwapBE32 * Swap a 32-bit value from bigendian to native format.
* Swap 32-bit big endian integer to 32-bit native endian integer. *
* If this is running on a bigendian system, `X` is returned unchanged.
*
* This macro never references `X` more than once, avoiding side effects.
*
* \param X the value to swap.
* \returns the byte-swapped value.
*
* \since This macro is available since SDL 3.0.0.
*/ */
#define SDL_SwapBE32(X) SwapOnlyIfNecessary(X)
/** /**
* \def SDL_SwapBE64 * Swap a 64-bit value from bigendian to native format.
* Swap 64-bit big endian integer to 64-bit native endian integer. *
* If this is running on a bigendian system, `X` is returned unchanged.
*
* This macro never references `X` more than once, avoiding side effects.
*
* \param X the value to swap.
* \returns the byte-swapped value.
*
* \since This macro is available since SDL 3.0.0.
*/ */
#define SDL_SwapBE64(X) SwapOnlyIfNecessary(X)
/** /**
* \def SDL_SwapFloatBE * Swap a floating point value from bigendian to native format.
* Swap endian float to native endian float. *
* If this is running on a bigendian system, `X` is returned unchanged.
*
* This macro never references `X` more than once, avoiding side effects.
*
* \param X the value to swap.
* \returns the byte-swapped value.
*
* \since This macro is available since SDL 3.0.0.
*/ */
#define SDL_SwapFloatBE(X) SwapOnlyIfNecessary(X)
/* @{ */ #elif SDL_BYTEORDER == SDL_LIL_ENDIAN
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
#define SDL_SwapLE16(X) (X) #define SDL_SwapLE16(X) (X)
#define SDL_SwapLE32(X) (X) #define SDL_SwapLE32(X) (X)
#define SDL_SwapLE64(X) (X) #define SDL_SwapLE64(X) (X)
@ -387,7 +456,6 @@ SDL_SwapFloat(float x)
#define SDL_SwapBE64(X) (X) #define SDL_SwapBE64(X) (X)
#define SDL_SwapFloatBE(X) (X) #define SDL_SwapFloatBE(X) (X)
#endif #endif
/* @} *//* Swap to native */
/* Ends C function definitions when using C++ */ /* Ends C function definitions when using C++ */
#ifdef __cplusplus #ifdef __cplusplus