Provide implementation of byte-order manipulation functions.
More...
Detailed Description
- Outline
-
-
- Purpose:
- Provide implementation of byte-order manipulation functions.
-
- Classes:
bsls::ByteOrderUtil_Impl | namespace for swapping functions |
-
- 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:
- Component bsls_byteorderutil, Component 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.
Define Documentation
#define BSLS_BYTEORDERUTIL_IMPL_COMPILE_TIME_ASSERT |
( |
|
expr |
) |
|
#define BSLS_BYTEORDERUTIL_IMPL_DISABLE_COUNTERPRODUCTIVE_MACROS 1 |
#define BSLS_BYTEORDERUTIL_IMPL_GENERICSWAP_16 |
( |
|
dstType, |
|
|
|
x | |
|
) |
| | |
#define BSLS_BYTEORDERUTIL_IMPL_GENERICSWAP_32 |
( |
|
dstType, |
|
|
|
x | |
|
) |
| | |
#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)); \
}