From b459e02eedf358ef564020d698a9d96b711bf14e Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Mon, 14 Jan 2019 13:49:05 -0800 Subject: endianness: Replace Boost macros with custom ones Boost changed the macros for endianness identification in 1.69, and the deprecation warning is a pretty noisy one during compilation. This abstracts away the Boost macro, so we have two UHD macros, UHD_BIG_ENDIAN and UHD_LITTLE_ENDIAN. They indicate big and little endian byte order. --- host/include/uhd/types/endianness.hpp | 32 ++++++++++++++++++++++++++++++++ host/include/uhd/utils/byteswap.hpp | 1 + host/include/uhd/utils/byteswap.ipp | 10 ++++------ 3 files changed, 37 insertions(+), 6 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/types/endianness.hpp b/host/include/uhd/types/endianness.hpp index a14bfcd23..b74564415 100644 --- a/host/include/uhd/types/endianness.hpp +++ b/host/include/uhd/types/endianness.hpp @@ -10,6 +10,38 @@ #include +/****************************************************************************** + * Detect host endianness + *****************************************************************************/ +#if BOOST_VERSION >= 105500 + +# include + +// In Boost 1.55, the meaning of the macros changed. They are now always +// defined, but don't always have the same value. +# if BOOST_ENDIAN_BIG_BYTE +# define UHD_BIG_ENDIAN +# elif BOOST_ENDIAN_LITTLE_BYTE +# define UHD_LITTLE_ENDIAN +# else +# error "Unsupported endianness!" +# endif + +#else + +# include + +# if defined(BOOST_BIG_ENDIAN) +# define UHD_BIG_ENDIAN +# elif defined(BOOST_LITTLE_ENDIAN) +# define UHD_LITTLE_ENDIAN +# else +# error "Unsupported endianness!" +# endif + +#endif + + namespace uhd { enum endianness_t { ENDIANNESS_BIG, ENDIANNESS_LITTLE }; diff --git a/host/include/uhd/utils/byteswap.hpp b/host/include/uhd/utils/byteswap.hpp index e05a6cced..07b25b4e9 100644 --- a/host/include/uhd/utils/byteswap.hpp +++ b/host/include/uhd/utils/byteswap.hpp @@ -9,6 +9,7 @@ #define INCLUDED_UHD_UTILS_BYTESWAP_HPP #include +#include #include /*! \file byteswap.hpp diff --git a/host/include/uhd/utils/byteswap.ipp b/host/include/uhd/utils/byteswap.ipp index 06d12c746..7e13d6260 100644 --- a/host/include/uhd/utils/byteswap.ipp +++ b/host/include/uhd/utils/byteswap.ipp @@ -107,13 +107,11 @@ UHD_INLINE uint64_t uhd::byteswap(uint64_t x) /*********************************************************************** * Define the templated network to/from host conversions **********************************************************************/ -#include - namespace uhd { template UHD_INLINE T ntohx(T num) { -#ifdef BOOST_BIG_ENDIAN +#ifdef UHD_BIG_ENDIAN return num; #else return uhd::byteswap(num); @@ -122,7 +120,7 @@ template UHD_INLINE T ntohx(T num) template UHD_INLINE T htonx(T num) { -#ifdef BOOST_BIG_ENDIAN +#ifdef UHD_BIG_ENDIAN return num; #else return uhd::byteswap(num); @@ -131,7 +129,7 @@ template UHD_INLINE T htonx(T num) template UHD_INLINE T wtohx(T num) { -#ifdef BOOST_BIG_ENDIAN +#ifdef UHD_BIG_ENDIAN return uhd::byteswap(num); #else return num; @@ -140,7 +138,7 @@ template UHD_INLINE T wtohx(T num) template UHD_INLINE T htowx(T num) { -#ifdef BOOST_BIG_ENDIAN +#ifdef UHD_BIG_ENDIAN return uhd::byteswap(num); #else return num; -- cgit v1.2.3