mirror of
https://github.com/boostorg/endian.git
synced 2025-08-01 05:24:39 +02:00
Change names to make room for modify-in-place names.
This commit is contained in:
@@ -26,42 +26,53 @@ namespace endian
|
||||
BOOST_SCOPED_ENUM_START(order) { big, little, native }; BOOST_SCOPED_ENUM_END
|
||||
# define BOOST_ENDIAN_ORDER_ENUM_DEFINED
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
// value returning interface //
|
||||
// suggested by Phil Endecott //
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
// reverse byte order (i.e. endianness)
|
||||
// value returning interface approach suggested by Phil Endecott.
|
||||
inline int16_t reverse_bytes(int16_t x) BOOST_NOEXCEPT;
|
||||
inline int32_t reverse_bytes(int32_t x) BOOST_NOEXCEPT;
|
||||
inline int64_t reverse_bytes(int64_t x) BOOST_NOEXCEPT;
|
||||
inline uint16_t reverse_bytes(uint16_t x) BOOST_NOEXCEPT;
|
||||
inline uint32_t reverse_bytes(uint32_t x) BOOST_NOEXCEPT;
|
||||
inline uint64_t reverse_bytes(uint64_t x) BOOST_NOEXCEPT;
|
||||
//
|
||||
inline int16_t reverse_value(int16_t x) BOOST_NOEXCEPT;
|
||||
inline int32_t reverse_value(int32_t x) BOOST_NOEXCEPT;
|
||||
inline int64_t reverse_value(int64_t x) BOOST_NOEXCEPT;
|
||||
inline uint16_t reverse_value(uint16_t x) BOOST_NOEXCEPT;
|
||||
inline uint32_t reverse_value(uint32_t x) BOOST_NOEXCEPT;
|
||||
inline uint64_t reverse_value(uint64_t x) BOOST_NOEXCEPT;
|
||||
|
||||
// reverse_bytes overloads for floating point types as requested by Vicente
|
||||
// reverse_value overloads for floating point types as requested by Vicente
|
||||
// Botet and others.
|
||||
// TODO: Track progress of Floating-Point Typedefs Having Specified Widths proposal (N3626)
|
||||
inline float reverse_bytes(float x) BOOST_NOEXCEPT;
|
||||
inline double reverse_bytes(double x) BOOST_NOEXCEPT;
|
||||
inline float reverse_value(float x) BOOST_NOEXCEPT;
|
||||
inline double reverse_value(double x) BOOST_NOEXCEPT;
|
||||
|
||||
// general reverse_bytes function template to meet requests for UDT support by Vicente
|
||||
// Botet and others.
|
||||
template <class T>
|
||||
inline T reverse_bytes(T x) BOOST_NOEXCEPT; // convert little to big or visa versa
|
||||
namespace detail
|
||||
// This function is unsafe for general use, so is placed in namespace detail.
|
||||
// Think of what happens if you reverse_value a std::pair<int16_t, int_16_t>; the bytes
|
||||
// from first end up in second and the bytes from second end up in first. Not good!
|
||||
{
|
||||
// general reverse_value function template to meet requests for UDT support by Vicente
|
||||
// Botet and others.
|
||||
template <class T>
|
||||
inline T reverse_value(T x) BOOST_NOEXCEPT; // convert little to big or visa versa
|
||||
}
|
||||
|
||||
// reverse bytes unless native endianness is big
|
||||
// possible names: reverse_unless_native_big, reverse_bytes_unless_big, reverse_unless_big
|
||||
// possible names: reverse_unless_native_big, reverse_value_unless_big, reverse_unless_big
|
||||
template <class T>
|
||||
inline T big_endian(T x) BOOST_NOEXCEPT;
|
||||
// Return: x if native endian order is big, otherwise reverse_bytes(x)
|
||||
inline T big_endian_value(T x) BOOST_NOEXCEPT;
|
||||
// Return: x if native endian order is big, otherwise reverse_value(x)
|
||||
|
||||
// reverse bytes unless native endianness is little
|
||||
// possible names: reverse_unless_native_little, reverse_bytes_unless_little, reverse_unless_little
|
||||
// possible names: reverse_unless_native_little, reverse_value_unless_little, reverse_unless_little
|
||||
template <class T>
|
||||
inline T little_endian(T x) BOOST_NOEXCEPT;
|
||||
// Return: x if native endian order is little, otherwise reverse_bytes(x);
|
||||
inline T little_endian_value(T x) BOOST_NOEXCEPT;
|
||||
// Return: x if native endian order is little, otherwise reverse_value(x);
|
||||
|
||||
// compile-time generic byte order conversion
|
||||
template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To, class T>
|
||||
T convert(T from) BOOST_NOEXCEPT;
|
||||
T convert_value(T from) BOOST_NOEXCEPT;
|
||||
|
||||
// runtime actual byte-order determination
|
||||
inline BOOST_SCOPED_ENUM(order) actual_order(BOOST_SCOPED_ENUM(order) o) BOOST_NOEXCEPT;
|
||||
@@ -69,17 +80,25 @@ namespace endian
|
||||
|
||||
// runtime byte-order conversion
|
||||
template <class T>
|
||||
T convert(T from, BOOST_SCOPED_ENUM(order) from_order,
|
||||
T convert_value(T from, BOOST_SCOPED_ENUM(order) from_order,
|
||||
BOOST_SCOPED_ENUM(order) to_order) BOOST_NOEXCEPT;
|
||||
|
||||
//----------------------------------- implementation -----------------------------------//
|
||||
// -- reverse_bytes portable approach suggested by tymofey, with avoidance of
|
||||
// undefined behavior as suggested by Giovanni Piero Deretta, and a further
|
||||
// refinement suggested by Pyry Jahkola.
|
||||
// -- reverse_bytes intrinsic approach suggested by David Stone, who privided his
|
||||
// Boost licensed macro implementation.
|
||||
|
||||
//----------------------------------- end synopsis -------------------------------------//
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
// //
|
||||
// implementation //
|
||||
// //
|
||||
// -- reverse_value portable approach suggested by tymofey, with avoidance of //
|
||||
// undefined behavior as suggested by Giovanni Piero Deretta, and a further //
|
||||
// refinement suggested by Pyry Jahkola. //
|
||||
// -- reverse_value intrinsic approach suggested by reviewers, and by David Stone, //
|
||||
// who provided his Boost licensed macro implementation (see detail/intrinsic.hpp //
|
||||
// //
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
inline int16_t reverse_bytes(int16_t x) BOOST_NOEXCEPT
|
||||
inline int16_t reverse_value(int16_t x) BOOST_NOEXCEPT
|
||||
{
|
||||
# ifdef BOOST_ENDIAN_NO_INTRINSICS
|
||||
return (static_cast<uint16_t>(x) << 8)
|
||||
@@ -89,7 +108,7 @@ namespace endian
|
||||
# endif
|
||||
}
|
||||
|
||||
inline int32_t reverse_bytes(int32_t x) BOOST_NOEXCEPT
|
||||
inline int32_t reverse_value(int32_t x) BOOST_NOEXCEPT
|
||||
{
|
||||
# ifdef BOOST_ENDIAN_NO_INTRINSICS
|
||||
uint32_t step16;
|
||||
@@ -102,7 +121,7 @@ namespace endian
|
||||
# endif
|
||||
}
|
||||
|
||||
inline int64_t reverse_bytes(int64_t x) BOOST_NOEXCEPT
|
||||
inline int64_t reverse_value(int64_t x) BOOST_NOEXCEPT
|
||||
{
|
||||
# ifdef BOOST_ENDIAN_NO_INTRINSICS
|
||||
uint64_t step32, step16;
|
||||
@@ -116,7 +135,7 @@ namespace endian
|
||||
# endif
|
||||
}
|
||||
|
||||
inline uint16_t reverse_bytes(uint16_t x) BOOST_NOEXCEPT
|
||||
inline uint16_t reverse_value(uint16_t x) BOOST_NOEXCEPT
|
||||
{
|
||||
# ifdef BOOST_ENDIAN_NO_INTRINSICS
|
||||
return (x << 8)
|
||||
@@ -126,7 +145,7 @@ namespace endian
|
||||
# endif
|
||||
}
|
||||
|
||||
inline uint32_t reverse_bytes(uint32_t x) BOOST_NOEXCEPT
|
||||
inline uint32_t reverse_value(uint32_t x) BOOST_NOEXCEPT
|
||||
{
|
||||
# ifdef BOOST_ENDIAN_NO_INTRINSICS
|
||||
uint32_t step16;
|
||||
@@ -139,7 +158,7 @@ namespace endian
|
||||
# endif
|
||||
}
|
||||
|
||||
inline uint64_t reverse_bytes(uint64_t x) BOOST_NOEXCEPT
|
||||
inline uint64_t reverse_value(uint64_t x) BOOST_NOEXCEPT
|
||||
{
|
||||
# ifdef BOOST_ENDIAN_NO_INTRINSICS
|
||||
uint64_t step32, step16;
|
||||
@@ -153,141 +172,144 @@ namespace endian
|
||||
# endif
|
||||
}
|
||||
|
||||
inline float reverse_bytes(float x) BOOST_NOEXCEPT
|
||||
inline float reverse_value(float x) BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT_MSG(sizeof(float) == sizeof(uint32_t),
|
||||
"boost::endian only supprts sizeof(float) == 4; please report error to boost mailing list");
|
||||
uint32_t tmp = reverse_bytes(*(const uint32_t*)&x);
|
||||
uint32_t tmp = reverse_value(*(const uint32_t*)&x);
|
||||
return *(const float*)&tmp;
|
||||
}
|
||||
|
||||
inline double reverse_bytes(double x) BOOST_NOEXCEPT
|
||||
inline double reverse_value(double x) BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT_MSG(sizeof(double) == sizeof(uint64_t),
|
||||
"boost::endian only supprts sizeof(double) == 8; please report error to boost mailing list");
|
||||
uint64_t tmp = reverse_bytes(*(const uint64_t*)&x);
|
||||
uint64_t tmp = reverse_value(*(const uint64_t*)&x);
|
||||
return *(const double*)&tmp;
|
||||
}
|
||||
|
||||
// general reverse_bytes function template implementation approach using std::reverse
|
||||
// suggested by Mathias Gaunard
|
||||
template <class T>
|
||||
inline T reverse_bytes(T x) BOOST_NOEXCEPT
|
||||
namespace detail // this function is unsafe for general use, so placed in namespace detail
|
||||
{
|
||||
T tmp(x);
|
||||
std::reverse(
|
||||
reinterpret_cast<char*>(&tmp),
|
||||
reinterpret_cast<char*>(&tmp) + sizeof(T));
|
||||
return tmp;
|
||||
// general reverse_value function template implementation approach using std::reverse
|
||||
// suggested by Mathias Gaunard
|
||||
template <class T>
|
||||
inline T reverse_value(T x) BOOST_NOEXCEPT
|
||||
{
|
||||
T tmp(x);
|
||||
std::reverse(
|
||||
reinterpret_cast<char*>(&tmp),
|
||||
reinterpret_cast<char*>(&tmp) + sizeof(T));
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T big_endian(T x) BOOST_NOEXCEPT
|
||||
inline T big_endian_value(T x) BOOST_NOEXCEPT
|
||||
{
|
||||
# ifdef BOOST_BIG_ENDIAN
|
||||
return x;
|
||||
# else
|
||||
return reverse_bytes(x);
|
||||
return reverse_value(x);
|
||||
# endif
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T little_endian(T x) BOOST_NOEXCEPT
|
||||
inline T little_endian_value(T x) BOOST_NOEXCEPT
|
||||
{
|
||||
# ifdef BOOST_LITTLE_ENDIAN
|
||||
return x;
|
||||
# else
|
||||
return reverse_bytes(x);
|
||||
return reverse_value(x);
|
||||
# endif
|
||||
}
|
||||
|
||||
template<> inline int16_t convert<order::big, order::big>(int16_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline int16_t convert<order::little, order::little>(int16_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline int16_t convert<order::native, order::native>(int16_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline int16_t convert_value<order::big, order::big>(int16_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline int16_t convert_value<order::little, order::little>(int16_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline int16_t convert_value<order::native, order::native>(int16_t x) BOOST_NOEXCEPT {return x;}
|
||||
|
||||
template<> inline uint16_t convert<order::big, order::big>(uint16_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline uint16_t convert<order::little, order::little>(uint16_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline uint16_t convert<order::native, order::native>(uint16_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline uint16_t convert_value<order::big, order::big>(uint16_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline uint16_t convert_value<order::little, order::little>(uint16_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline uint16_t convert_value<order::native, order::native>(uint16_t x) BOOST_NOEXCEPT {return x;}
|
||||
|
||||
template<> inline int32_t convert<order::big, order::big>(int32_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline int32_t convert<order::little, order::little>(int32_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline int32_t convert<order::native, order::native>(int32_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline int32_t convert_value<order::big, order::big>(int32_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline int32_t convert_value<order::little, order::little>(int32_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline int32_t convert_value<order::native, order::native>(int32_t x) BOOST_NOEXCEPT {return x;}
|
||||
|
||||
template<> inline uint32_t convert<order::big, order::big>(uint32_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline uint32_t convert<order::little, order::little>(uint32_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline uint32_t convert<order::native, order::native>(uint32_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline uint32_t convert_value<order::big, order::big>(uint32_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline uint32_t convert_value<order::little, order::little>(uint32_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline uint32_t convert_value<order::native, order::native>(uint32_t x) BOOST_NOEXCEPT {return x;}
|
||||
|
||||
template<> inline int64_t convert<order::big, order::big>(int64_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline int64_t convert<order::little, order::little>(int64_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline int64_t convert<order::native, order::native>(int64_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline int64_t convert_value<order::big, order::big>(int64_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline int64_t convert_value<order::little, order::little>(int64_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline int64_t convert_value<order::native, order::native>(int64_t x) BOOST_NOEXCEPT {return x;}
|
||||
|
||||
template<> inline uint64_t convert<order::big, order::big>(uint64_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline uint64_t convert<order::little, order::little>(uint64_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline uint64_t convert<order::native, order::native>(uint64_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline uint64_t convert_value<order::big, order::big>(uint64_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline uint64_t convert_value<order::little, order::little>(uint64_t x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline uint64_t convert_value<order::native, order::native>(uint64_t x) BOOST_NOEXCEPT {return x;}
|
||||
|
||||
template<> inline float convert<order::big, order::big>(float x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline float convert<order::little, order::little>(float x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline float convert<order::native, order::native>(float x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline float convert_value<order::big, order::big>(float x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline float convert_value<order::little, order::little>(float x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline float convert_value<order::native, order::native>(float x) BOOST_NOEXCEPT {return x;}
|
||||
|
||||
template<> inline double convert<order::big, order::big>(double x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline double convert<order::little, order::little>(double x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline double convert<order::native, order::native>(double x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline double convert_value<order::big, order::big>(double x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline double convert_value<order::little, order::little>(double x) BOOST_NOEXCEPT {return x;}
|
||||
template<> inline double convert_value<order::native, order::native>(double x) BOOST_NOEXCEPT {return x;}
|
||||
|
||||
template<> inline int16_t convert<order::big, order::little>(int16_t x) BOOST_NOEXCEPT {return reverse_bytes(x);}
|
||||
template<> inline int16_t convert<order::big, order::native>(int16_t x) BOOST_NOEXCEPT {return big_endian(x);}
|
||||
template<> inline int16_t convert<order::little, order::big>(int16_t x) BOOST_NOEXCEPT {return reverse_bytes(x);}
|
||||
template<> inline int16_t convert<order::little, order::native>(int16_t x) BOOST_NOEXCEPT {return little_endian(x);}
|
||||
template<> inline int16_t convert<order::native, order::big>(int16_t x) BOOST_NOEXCEPT {return big_endian(x);}
|
||||
template<> inline int16_t convert<order::native, order::little>(int16_t x) BOOST_NOEXCEPT {return little_endian(x);}
|
||||
template<> inline int16_t convert_value<order::big, order::little>(int16_t x) BOOST_NOEXCEPT {return reverse_value(x);}
|
||||
template<> inline int16_t convert_value<order::big, order::native>(int16_t x) BOOST_NOEXCEPT {return big_endian_value(x);}
|
||||
template<> inline int16_t convert_value<order::little, order::big>(int16_t x) BOOST_NOEXCEPT {return reverse_value(x);}
|
||||
template<> inline int16_t convert_value<order::little, order::native>(int16_t x) BOOST_NOEXCEPT {return little_endian_value(x);}
|
||||
template<> inline int16_t convert_value<order::native, order::big>(int16_t x) BOOST_NOEXCEPT {return big_endian_value(x);}
|
||||
template<> inline int16_t convert_value<order::native, order::little>(int16_t x) BOOST_NOEXCEPT {return little_endian_value(x);}
|
||||
|
||||
template<> inline uint16_t convert<order::big, order::little>(uint16_t x) BOOST_NOEXCEPT {return reverse_bytes(x);}
|
||||
template<> inline uint16_t convert<order::big, order::native>(uint16_t x) BOOST_NOEXCEPT {return big_endian(x);}
|
||||
template<> inline uint16_t convert<order::little, order::big>(uint16_t x) BOOST_NOEXCEPT {return reverse_bytes(x);}
|
||||
template<> inline uint16_t convert<order::little, order::native>(uint16_t x) BOOST_NOEXCEPT {return little_endian(x);}
|
||||
template<> inline uint16_t convert<order::native, order::big>(uint16_t x) BOOST_NOEXCEPT {return big_endian(x);}
|
||||
template<> inline uint16_t convert<order::native, order::little>(uint16_t x) BOOST_NOEXCEPT {return little_endian(x);}
|
||||
template<> inline uint16_t convert_value<order::big, order::little>(uint16_t x) BOOST_NOEXCEPT {return reverse_value(x);}
|
||||
template<> inline uint16_t convert_value<order::big, order::native>(uint16_t x) BOOST_NOEXCEPT {return big_endian_value(x);}
|
||||
template<> inline uint16_t convert_value<order::little, order::big>(uint16_t x) BOOST_NOEXCEPT {return reverse_value(x);}
|
||||
template<> inline uint16_t convert_value<order::little, order::native>(uint16_t x) BOOST_NOEXCEPT {return little_endian_value(x);}
|
||||
template<> inline uint16_t convert_value<order::native, order::big>(uint16_t x) BOOST_NOEXCEPT {return big_endian_value(x);}
|
||||
template<> inline uint16_t convert_value<order::native, order::little>(uint16_t x) BOOST_NOEXCEPT {return little_endian_value(x);}
|
||||
|
||||
template<> inline int32_t convert<order::big, order::little>(int32_t x) BOOST_NOEXCEPT {return reverse_bytes(x);}
|
||||
template<> inline int32_t convert<order::big, order::native>(int32_t x) BOOST_NOEXCEPT {return big_endian(x);}
|
||||
template<> inline int32_t convert<order::little, order::big>(int32_t x) BOOST_NOEXCEPT {return reverse_bytes(x);}
|
||||
template<> inline int32_t convert<order::little, order::native>(int32_t x) BOOST_NOEXCEPT {return little_endian(x);}
|
||||
template<> inline int32_t convert<order::native, order::big>(int32_t x) BOOST_NOEXCEPT {return big_endian(x);}
|
||||
template<> inline int32_t convert<order::native, order::little>(int32_t x) BOOST_NOEXCEPT {return little_endian(x);}
|
||||
template<> inline int32_t convert_value<order::big, order::little>(int32_t x) BOOST_NOEXCEPT {return reverse_value(x);}
|
||||
template<> inline int32_t convert_value<order::big, order::native>(int32_t x) BOOST_NOEXCEPT {return big_endian_value(x);}
|
||||
template<> inline int32_t convert_value<order::little, order::big>(int32_t x) BOOST_NOEXCEPT {return reverse_value(x);}
|
||||
template<> inline int32_t convert_value<order::little, order::native>(int32_t x) BOOST_NOEXCEPT {return little_endian_value(x);}
|
||||
template<> inline int32_t convert_value<order::native, order::big>(int32_t x) BOOST_NOEXCEPT {return big_endian_value(x);}
|
||||
template<> inline int32_t convert_value<order::native, order::little>(int32_t x) BOOST_NOEXCEPT {return little_endian_value(x);}
|
||||
|
||||
template<> inline uint32_t convert<order::big, order::little>(uint32_t x) BOOST_NOEXCEPT {return reverse_bytes(x);}
|
||||
template<> inline uint32_t convert<order::big, order::native>(uint32_t x) BOOST_NOEXCEPT {return big_endian(x);}
|
||||
template<> inline uint32_t convert<order::little, order::big>(uint32_t x) BOOST_NOEXCEPT {return reverse_bytes(x);}
|
||||
template<> inline uint32_t convert<order::little, order::native>(uint32_t x) BOOST_NOEXCEPT {return little_endian(x);}
|
||||
template<> inline uint32_t convert<order::native, order::big>(uint32_t x) BOOST_NOEXCEPT {return big_endian(x);}
|
||||
template<> inline uint32_t convert<order::native, order::little>(uint32_t x) BOOST_NOEXCEPT {return little_endian(x);}
|
||||
template<> inline uint32_t convert_value<order::big, order::little>(uint32_t x) BOOST_NOEXCEPT {return reverse_value(x);}
|
||||
template<> inline uint32_t convert_value<order::big, order::native>(uint32_t x) BOOST_NOEXCEPT {return big_endian_value(x);}
|
||||
template<> inline uint32_t convert_value<order::little, order::big>(uint32_t x) BOOST_NOEXCEPT {return reverse_value(x);}
|
||||
template<> inline uint32_t convert_value<order::little, order::native>(uint32_t x) BOOST_NOEXCEPT {return little_endian_value(x);}
|
||||
template<> inline uint32_t convert_value<order::native, order::big>(uint32_t x) BOOST_NOEXCEPT {return big_endian_value(x);}
|
||||
template<> inline uint32_t convert_value<order::native, order::little>(uint32_t x) BOOST_NOEXCEPT {return little_endian_value(x);}
|
||||
|
||||
template<> inline int64_t convert<order::big, order::little>(int64_t x) BOOST_NOEXCEPT {return reverse_bytes(x);}
|
||||
template<> inline int64_t convert<order::big, order::native>(int64_t x) BOOST_NOEXCEPT {return big_endian(x);}
|
||||
template<> inline int64_t convert<order::little, order::big>(int64_t x) BOOST_NOEXCEPT {return reverse_bytes(x);}
|
||||
template<> inline int64_t convert<order::little, order::native>(int64_t x) BOOST_NOEXCEPT {return little_endian(x);}
|
||||
template<> inline int64_t convert<order::native, order::big>(int64_t x) BOOST_NOEXCEPT {return big_endian(x);}
|
||||
template<> inline int64_t convert<order::native, order::little>(int64_t x) BOOST_NOEXCEPT {return little_endian(x);}
|
||||
template<> inline int64_t convert_value<order::big, order::little>(int64_t x) BOOST_NOEXCEPT {return reverse_value(x);}
|
||||
template<> inline int64_t convert_value<order::big, order::native>(int64_t x) BOOST_NOEXCEPT {return big_endian_value(x);}
|
||||
template<> inline int64_t convert_value<order::little, order::big>(int64_t x) BOOST_NOEXCEPT {return reverse_value(x);}
|
||||
template<> inline int64_t convert_value<order::little, order::native>(int64_t x) BOOST_NOEXCEPT {return little_endian_value(x);}
|
||||
template<> inline int64_t convert_value<order::native, order::big>(int64_t x) BOOST_NOEXCEPT {return big_endian_value(x);}
|
||||
template<> inline int64_t convert_value<order::native, order::little>(int64_t x) BOOST_NOEXCEPT {return little_endian_value(x);}
|
||||
|
||||
template<> inline uint64_t convert<order::big, order::little>(uint64_t x) BOOST_NOEXCEPT {return reverse_bytes(x);}
|
||||
template<> inline uint64_t convert<order::big, order::native>(uint64_t x) BOOST_NOEXCEPT {return big_endian(x);}
|
||||
template<> inline uint64_t convert<order::little, order::big>(uint64_t x) BOOST_NOEXCEPT {return reverse_bytes(x);}
|
||||
template<> inline uint64_t convert<order::little, order::native>(uint64_t x) BOOST_NOEXCEPT {return little_endian(x);}
|
||||
template<> inline uint64_t convert<order::native, order::big>(uint64_t x) BOOST_NOEXCEPT {return big_endian(x);}
|
||||
template<> inline uint64_t convert<order::native, order::little>(uint64_t x) BOOST_NOEXCEPT {return little_endian(x);}
|
||||
template<> inline uint64_t convert_value<order::big, order::little>(uint64_t x) BOOST_NOEXCEPT {return reverse_value(x);}
|
||||
template<> inline uint64_t convert_value<order::big, order::native>(uint64_t x) BOOST_NOEXCEPT {return big_endian_value(x);}
|
||||
template<> inline uint64_t convert_value<order::little, order::big>(uint64_t x) BOOST_NOEXCEPT {return reverse_value(x);}
|
||||
template<> inline uint64_t convert_value<order::little, order::native>(uint64_t x) BOOST_NOEXCEPT {return little_endian_value(x);}
|
||||
template<> inline uint64_t convert_value<order::native, order::big>(uint64_t x) BOOST_NOEXCEPT {return big_endian_value(x);}
|
||||
template<> inline uint64_t convert_value<order::native, order::little>(uint64_t x) BOOST_NOEXCEPT {return little_endian_value(x);}
|
||||
|
||||
template<> inline float convert<order::big, order::little>(float x) BOOST_NOEXCEPT {return reverse_bytes(x);}
|
||||
template<> inline float convert<order::big, order::native>(float x) BOOST_NOEXCEPT {return big_endian(x);}
|
||||
template<> inline float convert<order::little, order::big>(float x) BOOST_NOEXCEPT {return reverse_bytes(x);}
|
||||
template<> inline float convert<order::little, order::native>(float x) BOOST_NOEXCEPT {return little_endian(x);}
|
||||
template<> inline float convert<order::native, order::big>(float x) BOOST_NOEXCEPT {return big_endian(x);}
|
||||
template<> inline float convert<order::native, order::little>(float x) BOOST_NOEXCEPT {return little_endian(x);}
|
||||
template<> inline float convert_value<order::big, order::little>(float x) BOOST_NOEXCEPT {return reverse_value(x);}
|
||||
template<> inline float convert_value<order::big, order::native>(float x) BOOST_NOEXCEPT {return big_endian_value(x);}
|
||||
template<> inline float convert_value<order::little, order::big>(float x) BOOST_NOEXCEPT {return reverse_value(x);}
|
||||
template<> inline float convert_value<order::little, order::native>(float x) BOOST_NOEXCEPT {return little_endian_value(x);}
|
||||
template<> inline float convert_value<order::native, order::big>(float x) BOOST_NOEXCEPT {return big_endian_value(x);}
|
||||
template<> inline float convert_value<order::native, order::little>(float x) BOOST_NOEXCEPT {return little_endian_value(x);}
|
||||
|
||||
template<> inline double convert<order::big, order::little>(double x) BOOST_NOEXCEPT {return reverse_bytes(x);}
|
||||
template<> inline double convert<order::big, order::native>(double x) BOOST_NOEXCEPT {return big_endian(x);}
|
||||
template<> inline double convert<order::little, order::big>(double x) BOOST_NOEXCEPT {return reverse_bytes(x);}
|
||||
template<> inline double convert<order::little, order::native>(double x) BOOST_NOEXCEPT {return little_endian(x);}
|
||||
template<> inline double convert<order::native, order::big>(double x) BOOST_NOEXCEPT {return big_endian(x);}
|
||||
template<> inline double convert<order::native, order::little>(double x) BOOST_NOEXCEPT {return little_endian(x);}
|
||||
template<> inline double convert_value<order::big, order::little>(double x) BOOST_NOEXCEPT {return reverse_value(x);}
|
||||
template<> inline double convert_value<order::big, order::native>(double x) BOOST_NOEXCEPT {return big_endian_value(x);}
|
||||
template<> inline double convert_value<order::little, order::big>(double x) BOOST_NOEXCEPT {return reverse_value(x);}
|
||||
template<> inline double convert_value<order::little, order::native>(double x) BOOST_NOEXCEPT {return little_endian_value(x);}
|
||||
template<> inline double convert_value<order::native, order::big>(double x) BOOST_NOEXCEPT {return big_endian_value(x);}
|
||||
template<> inline double convert_value<order::native, order::little>(double x) BOOST_NOEXCEPT {return little_endian_value(x);}
|
||||
|
||||
inline BOOST_SCOPED_ENUM(order) actual_order(BOOST_SCOPED_ENUM(order) o) BOOST_NOEXCEPT
|
||||
{
|
||||
@@ -301,13 +323,13 @@ namespace endian
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T convert(T from, BOOST_SCOPED_ENUM(order) from_order,
|
||||
T convert_value(T from, BOOST_SCOPED_ENUM(order) from_order,
|
||||
BOOST_SCOPED_ENUM(order) to_order) BOOST_NOEXCEPT
|
||||
{
|
||||
if (actual_order(from_order) == order::big)
|
||||
return actual_order(to_order) == order::big ? from : reverse_bytes(from);
|
||||
return actual_order(to_order) == order::big ? from : reverse_value(from);
|
||||
// actual from_order is little
|
||||
return actual_order(to_order) == order::little ? from : reverse_bytes(from);
|
||||
return actual_order(to_order) == order::little ? from : reverse_value(from);
|
||||
}
|
||||
|
||||
} // namespace endian
|
||||
|
@@ -175,65 +175,65 @@ namespace
|
||||
big_value(big);
|
||||
little_value(little);
|
||||
|
||||
BOOST_TEST_EQ(be::reverse_bytes(big), little);
|
||||
BOOST_TEST_EQ(be::reverse_bytes(little), big);
|
||||
BOOST_TEST_EQ(be::reverse_bytes<T>(big), little);
|
||||
BOOST_TEST_EQ(be::reverse_bytes<T>(little), big);
|
||||
BOOST_TEST_EQ(be::reverse_value(big), little);
|
||||
BOOST_TEST_EQ(be::reverse_value(little), big);
|
||||
BOOST_TEST_EQ(be::detail::reverse_value<T>(big), little);
|
||||
BOOST_TEST_EQ(be::detail::reverse_value<T>(little), big);
|
||||
|
||||
BOOST_TEST_EQ(be::big_endian(native), big);
|
||||
BOOST_TEST_EQ(be::little_endian(native), little);
|
||||
BOOST_TEST_EQ(be::big_endian(be::big_endian(native)), native);
|
||||
BOOST_TEST_EQ(be::big_endian(be::big_endian(big)), big);
|
||||
BOOST_TEST_EQ(be::big_endian(be::big_endian(little)), little);
|
||||
BOOST_TEST_EQ(be::little_endian(be::little_endian(native)), native);
|
||||
BOOST_TEST_EQ(be::little_endian(be::little_endian(big)), big);
|
||||
BOOST_TEST_EQ(be::little_endian(be::little_endian(little)), little);
|
||||
BOOST_TEST_EQ(be::big_endian_value(native), big);
|
||||
BOOST_TEST_EQ(be::little_endian_value(native), little);
|
||||
BOOST_TEST_EQ(be::big_endian_value(be::big_endian_value(native)), native);
|
||||
BOOST_TEST_EQ(be::big_endian_value(be::big_endian_value(big)), big);
|
||||
BOOST_TEST_EQ(be::big_endian_value(be::big_endian_value(little)), little);
|
||||
BOOST_TEST_EQ(be::little_endian_value(be::little_endian_value(native)), native);
|
||||
BOOST_TEST_EQ(be::little_endian_value(be::little_endian_value(big)), big);
|
||||
BOOST_TEST_EQ(be::little_endian_value(be::little_endian_value(little)), little);
|
||||
|
||||
# ifdef BOOST_BIG_ENDIAN
|
||||
BOOST_TEST_EQ(be::reverse_bytes(native), little);
|
||||
BOOST_TEST_EQ(be::reverse_bytes<T>(native), little);
|
||||
BOOST_TEST_EQ(be::big_endian(big), big);
|
||||
BOOST_TEST_EQ(be::big_endian<T>(big), big);
|
||||
BOOST_TEST_EQ(be::big_endian(little), little);
|
||||
BOOST_TEST_EQ(be::big_endian<T>(little), little);
|
||||
BOOST_TEST_EQ(be::big_endian(native), little);
|
||||
BOOST_TEST_EQ(be::big_endian<T>(native), little);
|
||||
BOOST_TEST_EQ(be::reverse_value(native), little);
|
||||
BOOST_TEST_EQ(be::detail::reverse_value<T>(native), little);
|
||||
BOOST_TEST_EQ(be::big_endian_value(big), big);
|
||||
BOOST_TEST_EQ(be::big_endian_value<T>(big), big);
|
||||
BOOST_TEST_EQ(be::big_endian_value(little), little);
|
||||
BOOST_TEST_EQ(be::big_endian_value<T>(little), little);
|
||||
BOOST_TEST_EQ(be::big_endian_value(native), little);
|
||||
BOOST_TEST_EQ(be::big_endian_value<T>(native), little);
|
||||
# else
|
||||
BOOST_TEST_EQ(be::reverse_bytes(native), big);
|
||||
BOOST_TEST_EQ(be::reverse_bytes<T>(native), big);
|
||||
BOOST_TEST_EQ(be::big_endian(big), little);
|
||||
BOOST_TEST_EQ(be::big_endian<T>(big), little);
|
||||
BOOST_TEST_EQ(be::big_endian(little), big);
|
||||
BOOST_TEST_EQ(be::big_endian<T>(little), big);
|
||||
BOOST_TEST_EQ(be::big_endian(native), big);
|
||||
BOOST_TEST_EQ(be::big_endian<T>(native), big);
|
||||
BOOST_TEST_EQ(be::reverse_value(native), big);
|
||||
BOOST_TEST_EQ(be::detail::reverse_value<T>(native), big);
|
||||
BOOST_TEST_EQ(be::big_endian_value(big), little);
|
||||
BOOST_TEST_EQ(be::big_endian_value<T>(big), little);
|
||||
BOOST_TEST_EQ(be::big_endian_value(little), big);
|
||||
BOOST_TEST_EQ(be::big_endian_value<T>(little), big);
|
||||
BOOST_TEST_EQ(be::big_endian_value(native), big);
|
||||
BOOST_TEST_EQ(be::big_endian_value<T>(native), big);
|
||||
# endif
|
||||
|
||||
// compile time order determination
|
||||
|
||||
BOOST_TEST_EQ((be::convert<be::order::big, be::order::big>(big)), big);
|
||||
BOOST_TEST_EQ((be::convert<be::order::little, be::order::little>(little)), little);
|
||||
BOOST_TEST_EQ((be::convert<be::order::native, be::order::native>(native)), native);
|
||||
BOOST_TEST_EQ((be::convert_value<be::order::big, be::order::big>(big)), big);
|
||||
BOOST_TEST_EQ((be::convert_value<be::order::little, be::order::little>(little)), little);
|
||||
BOOST_TEST_EQ((be::convert_value<be::order::native, be::order::native>(native)), native);
|
||||
|
||||
BOOST_TEST_EQ((be::convert<be::order::big, be::order::little>(big)), little);
|
||||
BOOST_TEST_EQ((be::convert<be::order::big, be::order::native>(big)), native);
|
||||
BOOST_TEST_EQ((be::convert<be::order::little, be::order::big>(little)), big);
|
||||
BOOST_TEST_EQ((be::convert<be::order::little, be::order::native>(little)), native);
|
||||
BOOST_TEST_EQ((be::convert<be::order::native, be::order::big>(native)), big);
|
||||
BOOST_TEST_EQ((be::convert<be::order::native, be::order::little>(native)), native);
|
||||
BOOST_TEST_EQ((be::convert_value<be::order::big, be::order::little>(big)), little);
|
||||
BOOST_TEST_EQ((be::convert_value<be::order::big, be::order::native>(big)), native);
|
||||
BOOST_TEST_EQ((be::convert_value<be::order::little, be::order::big>(little)), big);
|
||||
BOOST_TEST_EQ((be::convert_value<be::order::little, be::order::native>(little)), native);
|
||||
BOOST_TEST_EQ((be::convert_value<be::order::native, be::order::big>(native)), big);
|
||||
BOOST_TEST_EQ((be::convert_value<be::order::native, be::order::little>(native)), native);
|
||||
|
||||
// runtime order determination
|
||||
|
||||
BOOST_TEST_EQ((be::convert(big, be::order::big, be::order::big)), big);
|
||||
BOOST_TEST_EQ((be::convert(little, be::order::little, be::order::little)), little);
|
||||
BOOST_TEST_EQ((be::convert(native, be::order::native, be::order::native)), native);
|
||||
BOOST_TEST_EQ((be::convert_value(big, be::order::big, be::order::big)), big);
|
||||
BOOST_TEST_EQ((be::convert_value(little, be::order::little, be::order::little)), little);
|
||||
BOOST_TEST_EQ((be::convert_value(native, be::order::native, be::order::native)), native);
|
||||
|
||||
BOOST_TEST_EQ((be::convert(big, be::order::big, be::order::little)), little);
|
||||
BOOST_TEST_EQ((be::convert(big, be::order::big, be::order::native)), native);
|
||||
BOOST_TEST_EQ((be::convert(little, be::order::little, be::order::big)), big);
|
||||
BOOST_TEST_EQ((be::convert(little, be::order::little, be::order::native)), native);
|
||||
BOOST_TEST_EQ((be::convert(native, be::order::native, be::order::big)), big);
|
||||
BOOST_TEST_EQ((be::convert(native, be::order::native, be::order::little)), native);
|
||||
BOOST_TEST_EQ((be::convert_value(big, be::order::big, be::order::little)), little);
|
||||
BOOST_TEST_EQ((be::convert_value(big, be::order::big, be::order::native)), native);
|
||||
BOOST_TEST_EQ((be::convert_value(little, be::order::little, be::order::big)), big);
|
||||
BOOST_TEST_EQ((be::convert_value(little, be::order::little, be::order::native)), native);
|
||||
BOOST_TEST_EQ((be::convert_value(native, be::order::native, be::order::big)), big);
|
||||
BOOST_TEST_EQ((be::convert_value(native, be::order::native, be::order::little)), native);
|
||||
}
|
||||
} // unnamed namespace
|
||||
|
||||
|
Reference in New Issue
Block a user