tlx
Loading...
Searching...
No Matches
bswap_le.hpp
Go to the documentation of this file.
1/*******************************************************************************
2 * tlx/math/bswap_le.hpp
3 *
4 * bswap16_le(), bswap32_le() and bswap64_le() to swap bytes to little-endian:
5 * no-operations on little-endian systems, bswaps on big-endian systems.
6 *
7 * Part of tlx - http://panthema.net/tlx
8 *
9 * Copyright (C) 2018 Timo Bingmann <tb@panthema.net>
10 *
11 * All rights reserved. Published under the Boost Software License, Version 1.0
12 ******************************************************************************/
13
14#ifndef TLX_MATH_BSWAP_LE_HEADER
15#define TLX_MATH_BSWAP_LE_HEADER
16
17#include <cstdint>
18#include <tlx/define/endian.hpp>
19#include <tlx/math/bswap.hpp>
20
21namespace tlx {
22
23//! \addtogroup tlx_math
24//! \{
25
26/******************************************************************************/
27// bswap16_le() - swap 16-bit integers to little-endian
28
29#if TLX_LITTLE_ENDIAN
30static inline std::uint16_t bswap16_le(const std::uint16_t& v) {
31 return v;
32}
33#elif TLX_BIG_ENDIAN
34static inline std::uint16_t bswap16_le(const std::uint16_t& v) {
35 return bswap16(v);
36}
37#endif
38
39/******************************************************************************/
40// bswap32_le() - swap 32-bit integers to little-endian
41
42#if TLX_LITTLE_ENDIAN
43static inline std::uint32_t bswap32_le(const std::uint32_t& v) {
44 return v;
45}
46#elif TLX_BIG_ENDIAN
47static inline std::uint32_t bswap32_le(const std::uint32_t& v) {
48 return bswap32(v);
49}
50#endif
51
52/******************************************************************************/
53// bswap64_le() - swap 64-bit integers to little-endian
54
55#if TLX_LITTLE_ENDIAN
56static inline std::uint64_t bswap64_le(const std::uint64_t& v) {
57 return v;
58}
59#elif TLX_BIG_ENDIAN
60static inline std::uint64_t bswap64_le(const std::uint64_t& v) {
61 return bswap64(v);
62}
63#endif
64
65/******************************************************************************/
66
67//! \}
68
69} // namespace tlx
70
71#endif // !TLX_MATH_BSWAP_LE_HEADER
72
73/******************************************************************************/
static std::uint16_t bswap16(const std::uint16_t &v)
bswap16 - generic
Definition bswap.hpp:52
static std::uint64_t bswap64(const std::uint64_t &v)
bswap64 - generic
Definition bswap.hpp:122
static std::uint32_t bswap32(const std::uint32_t &v)
bswap32 - generic
Definition bswap.hpp:84