4#define _USE_BUILTIN_BSWAPS
10#include <boost/type_traits.hpp>
11#include <boost/static_assert.hpp>
12#include <boost/version.hpp>
13#if BOOST_VERSION >= 106500
14#include <boost/predef/other/endian.h>
16#include <boost/detail/endian.hpp>
17#if defined(BOOST_LITTLE_ENDIAN)
18#define BOOST_ENDIAN_LITTLE_BYTE
19#elif defined(BOOST_BIG_ENDIAN)
20#define BOOST_ENDIAN_BIG_BYTE
22#error "unable to determine system endianness"
51#if defined(BOOST_ENDIAN_LITTLE_BYTE)
53#elif defined(BOOST_ENDIAN_BIG_BYTE)
56#error "unable to determine system endianness"
62template<
typename T,
size_t sz>
67 throw std::out_of_range(
"data size");
79 inline T
operator()(T val) {
return ((((val) >> 8) & 0xff) | (((val)&0xff) << 8)); }
87#if defined(_USE_BUILTIN_BSWAPS) && defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4)
88 return __builtin_bswap32(val);
90 return ((((val)&0xff000000) >> 24) | (((val)&0x00ff0000) >> 8) | (((val)&0x0000ff00) << 8) |
91 (((val)&0x000000ff) << 24));
101 return *(
float *)&mem;
110#if defined(_USE_BUILTIN_BSWAPS) && defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4)
111 return __builtin_bswap64(val);
113 return ((((val)&0xff00000000000000ull) >> 56) | (((val)&0x00ff000000000000ull) >> 40) |
114 (((val)&0x0000ff0000000000ull) >> 24) | (((val)&0x000000ff00000000ull) >> 8) |
115 (((val)&0x00000000ff000000ull) << 8) | (((val)&0x0000000000ff0000ull) << 24) |
116 (((val)&0x000000000000ff00ull) << 40) | (((val)&0x00000000000000ffull) << 56));
126 return *(
double *)&mem;
130template<endianness from, endianness to,
class T>
146template<endianness from, endianness to,
class T>
150 BOOST_STATIC_ASSERT(
sizeof(T) == 1 ||
sizeof(T) == 2 ||
sizeof(T) == 4 ||
sizeof(T) == 8);
152 BOOST_STATIC_ASSERT(boost::is_arithmetic<T>::value);
Definition: allobjects.cpp:30
T byte_swap(T value)
Definition: byteswap.h:147
endianness
Definition: byteswap.h:46
@ network_endian
Definition: byteswap.h:49
@ little_endian
Definition: byteswap.h:47
@ big_endian
Definition: byteswap.h:48
T operator()(T value)
Definition: byteswap.h:141
T operator()(T value)
Definition: byteswap.h:137
Definition: byteswap.h:131
T operator()(T value)
Definition: byteswap.h:132
T operator()(T val)
Definition: byteswap.h:73
T operator()(T val)
Definition: byteswap.h:79
T operator()(T val)
Definition: byteswap.h:85
T operator()(T val)
Definition: byteswap.h:108
double operator()(double val)
Definition: byteswap.h:123
float operator()(float val)
Definition: byteswap.h:98
Definition: byteswap.h:63
T operator()(T val)
Definition: byteswap.h:64