diff options
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/types/endianness.hpp | 32 | ||||
-rw-r--r-- | host/include/uhd/utils/byteswap.hpp | 1 | ||||
-rw-r--r-- | host/include/uhd/utils/byteswap.ipp | 10 |
3 files changed, 37 insertions, 6 deletions
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 <uhd/config.hpp> +/****************************************************************************** + * Detect host endianness + *****************************************************************************/ +#if BOOST_VERSION >= 105500 + +# include <boost/predef/other/endian.h> + +// 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 <boost/detail/endian.hpp> + +# 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 <uhd/config.hpp> +#include <uhd/types/endianness.hpp> #include <stdint.h> /*! \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 <boost/detail/endian.hpp> - namespace uhd { template <typename T> 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 <typename T> UHD_INLINE T ntohx(T num) template <typename T> 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 <typename T> UHD_INLINE T htonx(T num) template <typename T> 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 <typename T> UHD_INLINE T wtohx(T num) template <typename T> UHD_INLINE T htowx(T num) { -#ifdef BOOST_BIG_ENDIAN +#ifdef UHD_BIG_ENDIAN return uhd::byteswap(num); #else return num; |