Outline
Purpose
Provide implementation of byte-order manipulation functions.
Classes
Macros
- BSLS_BYTEORDERUTIL_IMPL_CUSTOMSWAP_16(x) return
x
with bytes swapped
- BSLS_BYTEORDERUTIL_IMPL_CUSTOMSWAP_32(x) return
x
with bytes swapped
- BSLS_BYTEORDERUTIL_IMPL_CUSTOMSWAP_64(x) return
x
with bytes swapped
- BSLS_BYTEORDERUTIL_IMPL_CUSTOMSWAP_P16(&x) return
x
with bytes swapped
- BSLS_BYTEORDERUTIL_IMPL_CUSTOMSWAP_P32(&x) return
x
with bytes swapped
- BSLS_BYTEORDERUTIL_IMPL_CUSTOMSWAP_P64(&x) return
x
with bytes swapped
- BSLS_BYTEORDERUTIL_IMPL_GENERICSWAP_16(x) return
x
with bytes swapped
- BSLS_BYTEORDERUTIL_IMPL_GENERICSWAP_32(x) return
x
with bytes swapped
- BSLS_BYTEORDERUTIL_IMPL_GENERICSWAP_64(x) return
x
with bytes swapped
- See also
- bsls_byteorderutil, bsls_byteorder
Description
This component provides a template class ByteOrderUtil_Impl
and a set of macros suitable for swapping byte orders of all integral types. The *_CUSTOMSWAP_*
macros use assembly language or compiler primitives, whereas the *_GENERICSWAP_*
macros use C bitwise operations to perform the swap. The *_CUSTOMSWAP_*
macros are not defined on all platforms; callers must perform an #ifdef
to see if they are defined before calling them. At most one of *_CUSTOMSWAP_NN
and *_CUSTOMSWAP_PNN
are defined on any one platform for any value of NN
, while *_GENERICSWAP_NN
macros are defined on all platforms and are meant to be called when the other macros are not available, and are also used for benchmarking.
◆ BSLS_BYTEORDERUTIL_IMPL_COMPILE_TIME_ASSERT
#define BSLS_BYTEORDERUTIL_IMPL_COMPILE_TIME_ASSERT |
( |
|
expr | ) |
|
◆ BSLS_BYTEORDERUTIL_IMPL_DISABLE_COUNTERPRODUCTIVE_MACROS
#define BSLS_BYTEORDERUTIL_IMPL_DISABLE_COUNTERPRODUCTIVE_MACROS 1 |
◆ BSLS_BYTEORDERUTIL_IMPL_GENERICSWAP_16
#define BSLS_BYTEORDERUTIL_IMPL_GENERICSWAP_16 |
( |
|
dstType, |
|
|
|
x |
|
) |
| |
Value: { \
BSLS_BYTEORDERUTIL_IMPL_COMPILE_TIME_ASSERT(2 == sizeof x); \
BSLS_BYTEORDERUTIL_IMPL_COMPILE_TIME_ASSERT(2 == sizeof(dstType)); \
\
return static_cast<dstType>((((x) & 0xff00u) >> 8) | \
(((x) & 0x00ffu) << 8)); \
}
◆ BSLS_BYTEORDERUTIL_IMPL_GENERICSWAP_32
#define BSLS_BYTEORDERUTIL_IMPL_GENERICSWAP_32 |
( |
|
dstType, |
|
|
|
x |
|
) |
| |
Value: { \
BSLS_BYTEORDERUTIL_IMPL_COMPILE_TIME_ASSERT(4 == sizeof x); \
BSLS_BYTEORDERUTIL_IMPL_COMPILE_TIME_ASSERT(4 == sizeof(dstType)); \
\
return static_cast<dstType>((((x) & 0x000000ffU) << 24) \
| (((x) & 0x0000ff00U) << 8) \
| (((x) & 0x00ff0000U) >> 8) \
| (((x) & 0xff000000U) >> 24)); \
}
◆ BSLS_BYTEORDERUTIL_IMPL_GENERICSWAP_64
#define BSLS_BYTEORDERUTIL_IMPL_GENERICSWAP_64 |
( |
|
dstType, |
|
|
|
x |
|
) |
| |
Value: { \
BSLS_BYTEORDERUTIL_IMPL_COMPILE_TIME_ASSERT(8 == sizeof x); \
BSLS_BYTEORDERUTIL_IMPL_COMPILE_TIME_ASSERT(8 == sizeof(dstType)); \
\
return static_cast<dstType>((((x) & 0x00000000000000ffULL) << 56) \
| (((x) & 0x000000000000ff00ULL) << 40) \
| (((x) & 0x0000000000ff0000ULL) << 24) \
| (((x) & 0x00000000ff000000ULL) << 8) \
| (((x) & 0x000000ff00000000ULL) >> 8) \
| (((x) & 0x0000ff0000000000ULL) >> 24) \
| (((x) & 0x00ff000000000000ULL) >> 40) \
| (((x) & 0xff00000000000000ULL) >> 56)); \
}