40 constexpr static int16 swap (
int16 value)
noexcept;
55 static float swap (
float value)
noexcept;
58 static double swap (
double value)
noexcept;
62 template <
typename Type>
65 #if JUCE_LITTLE_ENDIAN
73 template <
typename Type>
76 #if JUCE_LITTLE_ENDIAN
85 constexpr static uint32 littleEndianInt (
const void* bytes)
noexcept;
88 constexpr static uint64 littleEndianInt64 (
const void* bytes)
noexcept;
91 constexpr static uint16 littleEndianShort (
const void* bytes)
noexcept;
94 constexpr static int littleEndian24Bit (
const void* bytes)
noexcept;
97 static void littleEndian24BitToChars (
int32 value,
void* destBytes)
noexcept;
101 constexpr static uint32 bigEndianInt (
const void* bytes)
noexcept;
104 constexpr static uint64 bigEndianInt64 (
const void* bytes)
noexcept;
107 constexpr static uint16 bigEndianShort (
const void* bytes)
noexcept;
110 constexpr static int bigEndian24Bit (
const void* bytes)
noexcept;
113 static void bigEndian24BitToChars (
int32 value,
void* destBytes)
noexcept;
130 #if JUCE_LITTLE_ENDIAN
147inline float ByteOrder::swap (
float v)
noexcept {
union {
uint32 asUInt;
float asFloat; } n; n.asFloat = v; n.asUInt = swap (n.asUInt);
return n.asFloat; }
148inline double ByteOrder::swap (
double v)
noexcept {
union {
uint64 asUInt;
double asFloat; } n; n.asFloat = v; n.asUInt = swap (n.asUInt);
return n.asFloat; }
150#if JUCE_MSVC && ! defined (__INTEL_COMPILER)
151 #pragma intrinsic (_byteswap_ulong)
156 #if JUCE_MAC || JUCE_IOS
157 return OSSwapInt32 (n);
158 #elif (JUCE_GCC || JUCE_CLANG) && JUCE_INTEL && ! JUCE_NO_INLINE_ASM
159 asm(
"bswap %%eax" :
"=a"(n) :
"a"(n));
162 return _byteswap_ulong (n);
166 return (n << 24) | (n >> 24) | ((n & 0xff00) << 8) | ((n & 0xff0000) >> 8);
172 #if JUCE_MAC || JUCE_IOS
173 return OSSwapInt64 (value);
175 return _byteswap_uint64 (value);
183 return static_cast<uint16> (
static_cast<uint16> (b0) | (
static_cast<uint16> (b1) << 8));
188 return static_cast<uint32> (b0) | (
static_cast<uint32> (b1) << 8)
189 | (
static_cast<uint32> (b2) << 16) | (
static_cast<uint32> (b3) << 24);
194 return static_cast<uint64> (b0) | (
static_cast<uint64> (b1) << 8) | (
static_cast<uint64> (b2) << 16) | (
static_cast<uint64> (b3) << 24)
195 | (
static_cast<uint64> (b4) << 32) | (
static_cast<uint64> (b5) << 40) | (
static_cast<uint64> (b6) << 48) | (
static_cast<uint64> (b7) << 56);
200 static_cast<const uint8*
> (bytes)[2],
static_cast<const uint8*
> (bytes)[3]); }
202 static_cast<const uint8*
> (bytes)[2],
static_cast<const uint8*
> (bytes)[3],
203 static_cast<const uint8*
> (bytes)[4],
static_cast<const uint8*
> (bytes)[5],
204 static_cast<const uint8*
> (bytes)[6],
static_cast<const uint8*
> (bytes)[7]); }
208 static_cast<const uint8*
> (bytes)[1],
static_cast<const uint8*
> (bytes)[0]); }
210 static_cast<const uint8*
> (bytes)[5],
static_cast<const uint8*
> (bytes)[4],
211 static_cast<const uint8*
> (bytes)[3],
static_cast<const uint8*
> (bytes)[2],
212 static_cast<const uint8*
> (bytes)[1],
static_cast<const uint8*
> (bytes)[0]); }
Contains static methods for converting the byte order between different endiannesses.
static constexpr uint64 bigEndianInt64(const void *bytes) noexcept
Turns 8 bytes into a big-endian integer.
static constexpr uint32 bigEndianInt(const void *bytes) noexcept
Turns 4 bytes into a big-endian integer.
static constexpr uint32 littleEndianInt(const void *bytes) noexcept
Turns 4 bytes into a little-endian integer.
static Type swapIfLittleEndian(Type value) noexcept
Swaps the byte order of a signed or unsigned integer if the CPU is little-endian.
static void littleEndian24BitToChars(int32 value, void *destBytes) noexcept
Copies a 24-bit number to 3 little-endian bytes.
static constexpr uint16 bigEndianShort(const void *bytes) noexcept
Turns 2 bytes into a big-endian integer.
static constexpr uint16 littleEndianShort(const void *bytes) noexcept
Turns 2 bytes into a little-endian integer.
static constexpr uint16 makeInt(uint8 leastSig, uint8 mostSig) noexcept
Constructs a 16-bit integer from its constituent bytes, in order of significance.
static constexpr uint16 swap(uint16 value) noexcept
Swaps the upper and lower bytes of a 16-bit integer.
static constexpr uint64 littleEndianInt64(const void *bytes) noexcept
Turns 8 bytes into a little-endian integer.
static void bigEndian24BitToChars(int32 value, void *destBytes) noexcept
Copies a 24-bit number to 3 big-endian bytes.
static constexpr int littleEndian24Bit(const void *bytes) noexcept
Converts 3 little-endian bytes into a signed 24-bit value (which is sign-extended to 32 bits).
static Type swapIfBigEndian(Type value) noexcept
Swaps the byte order of a signed or unsigned integer if the CPU is big-endian.
static constexpr bool isBigEndian() noexcept
Returns true if the current CPU is big-endian.
static constexpr int bigEndian24Bit(const void *bytes) noexcept
Converts 3 big-endian bytes into a signed 24-bit value (which is sign-extended to 32 bits).
unsigned short uint16
A platform-independent 16-bit unsigned integer type.
signed short int16
A platform-independent 16-bit signed integer type.
signed int int32
A platform-independent 32-bit signed integer type.
signed char int8
A platform-independent 8-bit signed integer type.
unsigned long long uint64
A platform-independent 64-bit unsigned integer type.
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
unsigned char uint8
A platform-independent 8-bit unsigned integer type.
long long int64
A platform-independent 64-bit integer type.