forked from boostorg/endian
Support any expanding loads in endian_load
This commit is contained in:
@ -79,6 +79,118 @@ template<class T, std::size_t N, BOOST_SCOPED_ENUM(order) O1, BOOST_SCOPED_ENUM(
|
||||
}
|
||||
};
|
||||
|
||||
// expanding load 1 -> 2
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_load_impl<T, 2, Order, 1, order::little>
|
||||
{
|
||||
inline T operator()( unsigned char const * p ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 2 ];
|
||||
|
||||
tmp[0] = p[0];
|
||||
tmp[1] = boost::is_signed<T>::value && ( p[0] & 0x80 )? 0xFF: 0x00;
|
||||
|
||||
return boost::endian::endian_load<T, 2, order::little>( tmp );
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_load_impl<T, 2, Order, 1, order::big>
|
||||
{
|
||||
inline T operator()( unsigned char const * p ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 2 ];
|
||||
|
||||
tmp[0] = boost::is_signed<T>::value && ( p[0] & 0x80 )? 0xFF: 0x00;
|
||||
tmp[1] = p[0];
|
||||
|
||||
return boost::endian::endian_load<T, 2, order::big>( tmp );
|
||||
}
|
||||
};
|
||||
|
||||
// expanding load 1 -> 4
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_load_impl<T, 4, Order, 1, order::little>
|
||||
{
|
||||
inline T operator()( unsigned char const * p ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 4 ];
|
||||
|
||||
unsigned char fill = boost::is_signed<T>::value && ( p[0] & 0x80 )? 0xFF: 0x00;
|
||||
|
||||
tmp[0] = p[0];
|
||||
tmp[1] = fill;
|
||||
tmp[2] = fill;
|
||||
tmp[3] = fill;
|
||||
|
||||
return boost::endian::endian_load<T, 4, order::little>( tmp );
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_load_impl<T, 4, Order, 1, order::big>
|
||||
{
|
||||
inline T operator()( unsigned char const * p ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 4 ];
|
||||
|
||||
unsigned char fill = boost::is_signed<T>::value && ( p[0] & 0x80 )? 0xFF: 0x00;
|
||||
|
||||
tmp[0] = fill;
|
||||
tmp[1] = fill;
|
||||
tmp[2] = fill;
|
||||
tmp[3] = p[0];
|
||||
|
||||
return boost::endian::endian_load<T, 4, order::big>( tmp );
|
||||
}
|
||||
};
|
||||
|
||||
// expanding load 2 -> 4
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_load_impl<T, 4, Order, 2, order::little>
|
||||
{
|
||||
inline T operator()( unsigned char const * p ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 4 ];
|
||||
|
||||
unsigned char fill = boost::is_signed<T>::value && ( p[1] & 0x80 )? 0xFF: 0x00;
|
||||
|
||||
tmp[0] = p[0];
|
||||
tmp[1] = p[1];
|
||||
tmp[2] = fill;
|
||||
tmp[3] = fill;
|
||||
|
||||
return boost::endian::endian_load<T, 4, order::little>( tmp );
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_load_impl<T, 4, Order, 2, order::big>
|
||||
{
|
||||
inline T operator()( unsigned char const * p ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 4 ];
|
||||
|
||||
unsigned char fill = boost::is_signed<T>::value && ( p[0] & 0x80 )? 0xFF: 0x00;
|
||||
|
||||
tmp[0] = fill;
|
||||
tmp[1] = fill;
|
||||
tmp[2] = p[0];
|
||||
tmp[3] = p[1];
|
||||
|
||||
return boost::endian::endian_load<T, 4, order::big>( tmp );
|
||||
}
|
||||
};
|
||||
|
||||
// expanding load 3 -> 4
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_load_impl<T, 4, Order, 3, order::little>
|
||||
@ -115,6 +227,206 @@ template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_load_impl<T, 4,
|
||||
}
|
||||
};
|
||||
|
||||
// expanding load 1 -> 8
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_load_impl<T, 8, Order, 1, order::little>
|
||||
{
|
||||
inline T operator()( unsigned char const * p ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
|
||||
unsigned char fill = boost::is_signed<T>::value && ( p[0] & 0x80 )? 0xFF: 0x00;
|
||||
|
||||
tmp[0] = p[0];
|
||||
|
||||
tmp[1] = fill;
|
||||
tmp[2] = fill;
|
||||
tmp[3] = fill;
|
||||
tmp[4] = fill;
|
||||
tmp[5] = fill;
|
||||
tmp[6] = fill;
|
||||
tmp[7] = fill;
|
||||
|
||||
return boost::endian::endian_load<T, 8, order::little>( tmp );
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_load_impl<T, 8, Order, 1, order::big>
|
||||
{
|
||||
inline T operator()( unsigned char const * p ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
|
||||
unsigned char fill = boost::is_signed<T>::value && ( p[0] & 0x80 )? 0xFF: 0x00;
|
||||
|
||||
tmp[0] = fill;
|
||||
tmp[1] = fill;
|
||||
tmp[2] = fill;
|
||||
tmp[3] = fill;
|
||||
tmp[4] = fill;
|
||||
tmp[5] = fill;
|
||||
tmp[6] = fill;
|
||||
|
||||
tmp[7] = p[0];
|
||||
|
||||
return boost::endian::endian_load<T, 8, order::big>( tmp );
|
||||
}
|
||||
};
|
||||
|
||||
// expanding load 2 -> 8
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_load_impl<T, 8, Order, 2, order::little>
|
||||
{
|
||||
inline T operator()( unsigned char const * p ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
|
||||
unsigned char fill = boost::is_signed<T>::value && ( p[1] & 0x80 )? 0xFF: 0x00;
|
||||
|
||||
tmp[0] = p[0];
|
||||
tmp[1] = p[1];
|
||||
|
||||
tmp[2] = fill;
|
||||
tmp[3] = fill;
|
||||
tmp[4] = fill;
|
||||
tmp[5] = fill;
|
||||
tmp[6] = fill;
|
||||
tmp[7] = fill;
|
||||
|
||||
return boost::endian::endian_load<T, 8, order::little>( tmp );
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_load_impl<T, 8, Order, 2, order::big>
|
||||
{
|
||||
inline T operator()( unsigned char const * p ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
|
||||
unsigned char fill = boost::is_signed<T>::value && ( p[0] & 0x80 )? 0xFF: 0x00;
|
||||
|
||||
tmp[0] = fill;
|
||||
tmp[1] = fill;
|
||||
tmp[2] = fill;
|
||||
tmp[3] = fill;
|
||||
tmp[4] = fill;
|
||||
tmp[5] = fill;
|
||||
|
||||
tmp[6] = p[0];
|
||||
tmp[7] = p[1];
|
||||
|
||||
return boost::endian::endian_load<T, 8, order::big>( tmp );
|
||||
}
|
||||
};
|
||||
|
||||
// expanding load 3 -> 8
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_load_impl<T, 8, Order, 3, order::little>
|
||||
{
|
||||
inline T operator()( unsigned char const * p ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
|
||||
unsigned char fill = boost::is_signed<T>::value && ( p[2] & 0x80 )? 0xFF: 0x00;
|
||||
|
||||
tmp[0] = p[0];
|
||||
tmp[1] = p[1];
|
||||
tmp[2] = p[2];
|
||||
|
||||
tmp[3] = fill;
|
||||
tmp[4] = fill;
|
||||
tmp[5] = fill;
|
||||
tmp[6] = fill;
|
||||
tmp[7] = fill;
|
||||
|
||||
return boost::endian::endian_load<T, 8, order::little>( tmp );
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_load_impl<T, 8, Order, 3, order::big>
|
||||
{
|
||||
inline T operator()( unsigned char const * p ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
|
||||
unsigned char fill = boost::is_signed<T>::value && ( p[0] & 0x80 )? 0xFF: 0x00;
|
||||
|
||||
tmp[0] = fill;
|
||||
tmp[1] = fill;
|
||||
tmp[2] = fill;
|
||||
tmp[3] = fill;
|
||||
tmp[4] = fill;
|
||||
|
||||
tmp[5] = p[0];
|
||||
tmp[6] = p[1];
|
||||
tmp[7] = p[2];
|
||||
|
||||
return boost::endian::endian_load<T, 8, order::big>( tmp );
|
||||
}
|
||||
};
|
||||
|
||||
// expanding load 4 -> 8
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_load_impl<T, 8, Order, 4, order::little>
|
||||
{
|
||||
inline T operator()( unsigned char const * p ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
|
||||
unsigned char fill = boost::is_signed<T>::value && ( p[3] & 0x80 )? 0xFF: 0x00;
|
||||
|
||||
tmp[0] = p[0];
|
||||
tmp[1] = p[1];
|
||||
tmp[2] = p[2];
|
||||
tmp[3] = p[3];
|
||||
|
||||
tmp[4] = fill;
|
||||
tmp[5] = fill;
|
||||
tmp[6] = fill;
|
||||
tmp[7] = fill;
|
||||
|
||||
return boost::endian::endian_load<T, 8, order::little>( tmp );
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_load_impl<T, 8, Order, 4, order::big>
|
||||
{
|
||||
inline T operator()( unsigned char const * p ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
|
||||
unsigned char fill = boost::is_signed<T>::value && ( p[0] & 0x80 )? 0xFF: 0x00;
|
||||
|
||||
tmp[0] = fill;
|
||||
tmp[1] = fill;
|
||||
tmp[2] = fill;
|
||||
tmp[3] = fill;
|
||||
|
||||
tmp[4] = p[0];
|
||||
tmp[5] = p[1];
|
||||
tmp[6] = p[2];
|
||||
tmp[7] = p[3];
|
||||
|
||||
return boost::endian::endian_load<T, 8, order::big>( tmp );
|
||||
}
|
||||
};
|
||||
|
||||
// expanding load 5 -> 8
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_load_impl<T, 8, Order, 5, order::little>
|
||||
|
@ -3,7 +3,7 @@
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/endian/detail/endian_load.hpp>
|
||||
#include <boost/endian/conversion.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
@ -14,48 +14,120 @@ int main()
|
||||
{
|
||||
unsigned char v[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
|
||||
|
||||
// 1 -> 1
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int8_t, 1, boost::endian::order::little>( v )), 0x01 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint8_t, 1, boost::endian::order::little>( v )), 0x01 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int8_t, 1, boost::endian::order::big>( v )), 0x01 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint8_t, 1, boost::endian::order::big>( v )), 0x01 );
|
||||
|
||||
// 1 -> 2
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int16_t, 1, boost::endian::order::little>( v )), 0x01 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint16_t, 1, boost::endian::order::little>( v )), 0x01 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int16_t, 1, boost::endian::order::big>( v )), 0x01 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint16_t, 1, boost::endian::order::big>( v )), 0x01 );
|
||||
|
||||
// 2 -> 2
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int16_t, 2, boost::endian::order::little>( v )), 0x0201 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint16_t, 2, boost::endian::order::little>( v )), 0x0201 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int16_t, 2, boost::endian::order::big>( v )), 0x0102 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint16_t, 2, boost::endian::order::big>( v )), 0x0102 );
|
||||
|
||||
// 1 -> 4
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int32_t, 1, boost::endian::order::little>( v )), 0x01 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint32_t, 1, boost::endian::order::little>( v )), 0x01 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int32_t, 1, boost::endian::order::big>( v )), 0x01 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint32_t, 1, boost::endian::order::big>( v )), 0x01 );
|
||||
|
||||
// 2 -> 4
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int32_t, 2, boost::endian::order::little>( v )), 0x0201 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint32_t, 2, boost::endian::order::little>( v )), 0x0201 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int32_t, 2, boost::endian::order::big>( v )), 0x0102 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint32_t, 2, boost::endian::order::big>( v )), 0x0102 );
|
||||
|
||||
// 3 -> 4
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int32_t, 3, boost::endian::order::little>( v )), 0x030201 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint32_t, 3, boost::endian::order::little>( v )), 0x030201 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int32_t, 3, boost::endian::order::big>( v )), 0x010203 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint32_t, 3, boost::endian::order::big>( v )), 0x010203 );
|
||||
|
||||
// 4 -> 4
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int32_t, 4, boost::endian::order::little>( v )), 0x04030201 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint32_t, 4, boost::endian::order::little>( v )), 0x04030201 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int32_t, 4, boost::endian::order::big>( v )), 0x01020304 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint32_t, 4, boost::endian::order::big>( v )), 0x01020304 );
|
||||
|
||||
// 1 -> 8
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 1, boost::endian::order::little>( v )), 0x01 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 1, boost::endian::order::little>( v )), 0x01 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 1, boost::endian::order::big>( v )), 0x01 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 1, boost::endian::order::big>( v )), 0x01 );
|
||||
|
||||
// 2 -> 8
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 2, boost::endian::order::little>( v )), 0x0201 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 2, boost::endian::order::little>( v )), 0x0201 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 2, boost::endian::order::big>( v )), 0x0102 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 2, boost::endian::order::big>( v )), 0x0102 );
|
||||
|
||||
// 3 -> 8
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 3, boost::endian::order::little>( v )), 0x030201 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 3, boost::endian::order::little>( v )), 0x030201 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 3, boost::endian::order::big>( v )), 0x010203 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 3, boost::endian::order::big>( v )), 0x010203 );
|
||||
|
||||
// 4 -> 8
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 4, boost::endian::order::little>( v )), 0x04030201 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 4, boost::endian::order::little>( v )), 0x04030201 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 4, boost::endian::order::big>( v )), 0x01020304 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 4, boost::endian::order::big>( v )), 0x01020304 );
|
||||
|
||||
// 5 -> 8
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 5, boost::endian::order::little>( v )), 0x0504030201 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 5, boost::endian::order::little>( v )), 0x0504030201 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 5, boost::endian::order::big>( v )), 0x0102030405 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 5, boost::endian::order::big>( v )), 0x0102030405 );
|
||||
|
||||
// 6 -> 8
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 6, boost::endian::order::little>( v )), 0x060504030201 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 6, boost::endian::order::little>( v )), 0x060504030201 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 6, boost::endian::order::big>( v )), 0x010203040506 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 6, boost::endian::order::big>( v )), 0x010203040506 );
|
||||
|
||||
// 7 -> 8
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 7, boost::endian::order::little>( v )), 0x07060504030201 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 7, boost::endian::order::little>( v )), 0x07060504030201 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 7, boost::endian::order::big>( v )), 0x01020304050607 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 7, boost::endian::order::big>( v )), 0x01020304050607 );
|
||||
|
||||
// 8 -> 8
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 8, boost::endian::order::little>( v )), 0x0807060504030201 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 8, boost::endian::order::little>( v )), 0x0807060504030201 );
|
||||
|
||||
@ -66,48 +138,120 @@ int main()
|
||||
{
|
||||
unsigned char v[] = { 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8 };
|
||||
|
||||
// 1 -> 1
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int8_t, 1, boost::endian::order::little>( v )), -15 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint8_t, 1, boost::endian::order::little>( v )), 0xF1 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int8_t, 1, boost::endian::order::big>( v )), -15 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint8_t, 1, boost::endian::order::big>( v )), 0xF1 );
|
||||
|
||||
// 1 -> 2
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int16_t, 1, boost::endian::order::little>( v )), -15 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint16_t, 1, boost::endian::order::little>( v )), 0xF1 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int16_t, 1, boost::endian::order::big>( v )), -15 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint16_t, 1, boost::endian::order::big>( v )), 0xF1 );
|
||||
|
||||
// 2 -> 2
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int16_t, 2, boost::endian::order::little>( v )), -3343 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint16_t, 2, boost::endian::order::little>( v )), 0xF2F1 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int16_t, 2, boost::endian::order::big>( v )), -3598 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint16_t, 2, boost::endian::order::big>( v )), 0xF1F2 );
|
||||
|
||||
// 1 -> 4
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int32_t, 1, boost::endian::order::little>( v )), -15 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint32_t, 1, boost::endian::order::little>( v )), 0xF1 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int32_t, 1, boost::endian::order::big>( v )), -15 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint32_t, 1, boost::endian::order::big>( v )), 0xF1 );
|
||||
|
||||
// 2 -> 4
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int32_t, 2, boost::endian::order::little>( v )), -3343 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint32_t, 2, boost::endian::order::little>( v )), 0xF2F1 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int32_t, 2, boost::endian::order::big>( v )), -3598 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint32_t, 2, boost::endian::order::big>( v )), 0xF1F2 );
|
||||
|
||||
// 3 -> 4
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int32_t, 3, boost::endian::order::little>( v )), -789775 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint32_t, 3, boost::endian::order::little>( v )), 0xF3F2F1 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int32_t, 3, boost::endian::order::big>( v )), -920845 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint32_t, 3, boost::endian::order::big>( v )), 0xF1F2F3 );
|
||||
|
||||
// 4 -> 4
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int32_t, 4, boost::endian::order::little>( v )), 0xF4F3F2F1 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint32_t, 4, boost::endian::order::little>( v )), 0xF4F3F2F1 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int32_t, 4, boost::endian::order::big>( v )), 0xF1F2F3F4 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint32_t, 4, boost::endian::order::big>( v )), 0xF1F2F3F4 );
|
||||
|
||||
// 1 -> 8
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 1, boost::endian::order::little>( v )), -15 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 1, boost::endian::order::little>( v )), 0xF1 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 1, boost::endian::order::big>( v )), -15 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 1, boost::endian::order::big>( v )), 0xF1 );
|
||||
|
||||
// 2 -> 8
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 2, boost::endian::order::little>( v )), -3343 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 2, boost::endian::order::little>( v )), 0xF2F1 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 2, boost::endian::order::big>( v )), -3598 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 2, boost::endian::order::big>( v )), 0xF1F2 );
|
||||
|
||||
// 3 -> 8
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 3, boost::endian::order::little>( v )), -789775 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 3, boost::endian::order::little>( v )), 0xF3F2F1 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 3, boost::endian::order::big>( v )), -920845 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 3, boost::endian::order::big>( v )), 0xF1F2F3 );
|
||||
|
||||
// 4 -> 8
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 4, boost::endian::order::little>( v )), -185339151 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 4, boost::endian::order::little>( v )), 0xF4F3F2F1 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 4, boost::endian::order::big>( v )), -235736076 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 4, boost::endian::order::big>( v )), 0xF1F2F3F4 );
|
||||
|
||||
// 5 -> 8
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 5, boost::endian::order::little>( v )), -43135012111 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 5, boost::endian::order::little>( v )), 0xF5F4F3F2F1 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 5, boost::endian::order::big>( v )), -60348435211 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 5, boost::endian::order::big>( v )), 0xF1F2F3F4F5 );
|
||||
|
||||
// 6 -> 8
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 6, boost::endian::order::little>( v )), -9938739662095 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 6, boost::endian::order::little>( v )), 0xF6F5F4F3F2F1 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 6, boost::endian::order::big>( v )), -15449199413770 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 6, boost::endian::order::big>( v )), 0xF1F2F3F4F5F6 );
|
||||
|
||||
// 7 -> 8
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 7, boost::endian::order::little>( v )), -2261738553347343 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 7, boost::endian::order::little>( v )), 0xF7F6F5F4F3F2F1 );
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 7, boost::endian::order::big>( v )), -3954995049924873 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 7, boost::endian::order::big>( v )), 0xF1F2F3F4F5F6F7 );
|
||||
|
||||
// 8 -> 8
|
||||
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::int64_t, 8, boost::endian::order::little>( v )), 0xF8F7F6F5F4F3F2F1 );
|
||||
BOOST_TEST_EQ( (boost::endian::endian_load<boost::uint64_t, 8, boost::endian::order::little>( v )), 0xF8F7F6F5F4F3F2F1 );
|
||||
|
||||
|
Reference in New Issue
Block a user