forked from boostorg/endian
Add convenience load functions
This commit is contained in:
@ -378,6 +378,162 @@ inline void conditional_reverse_inplace( EndianReversibleInplace& x,
|
||||
}
|
||||
}
|
||||
|
||||
// load/store convenience functions
|
||||
|
||||
// load 16
|
||||
|
||||
inline boost::int16_t load_little_s16( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::int16_t, 2, order::little>( p );
|
||||
}
|
||||
|
||||
inline boost::uint16_t load_little_u16( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::uint16_t, 2, order::little>( p );
|
||||
}
|
||||
|
||||
inline boost::int16_t load_big_s16( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::int16_t, 2, order::big>( p );
|
||||
}
|
||||
|
||||
inline boost::uint16_t load_big_u16( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::uint16_t, 2, order::big>( p );
|
||||
}
|
||||
|
||||
// load 24
|
||||
|
||||
inline boost::int32_t load_little_s24( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::int32_t, 3, order::little>( p );
|
||||
}
|
||||
|
||||
inline boost::uint32_t load_little_u24( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::uint32_t, 3, order::little>( p );
|
||||
}
|
||||
|
||||
inline boost::int32_t load_big_s24( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::int32_t, 3, order::big>( p );
|
||||
}
|
||||
|
||||
inline boost::uint32_t load_big_u24( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::uint32_t, 3, order::big>( p );
|
||||
}
|
||||
|
||||
// load 32
|
||||
|
||||
inline boost::int32_t load_little_s32( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::int32_t, 4, order::little>( p );
|
||||
}
|
||||
|
||||
inline boost::uint32_t load_little_u32( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::uint32_t, 4, order::little>( p );
|
||||
}
|
||||
|
||||
inline boost::int32_t load_big_s32( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::int32_t, 4, order::big>( p );
|
||||
}
|
||||
|
||||
inline boost::uint32_t load_big_u32( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::uint32_t, 4, order::big>( p );
|
||||
}
|
||||
|
||||
// load 40
|
||||
|
||||
inline boost::int64_t load_little_s40( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::int64_t, 5, order::little>( p );
|
||||
}
|
||||
|
||||
inline boost::uint64_t load_little_u40( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::uint64_t, 5, order::little>( p );
|
||||
}
|
||||
|
||||
inline boost::int64_t load_big_s40( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::int64_t, 5, order::big>( p );
|
||||
}
|
||||
|
||||
inline boost::uint64_t load_big_u40( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::uint64_t, 5, order::big>( p );
|
||||
}
|
||||
|
||||
// load 48
|
||||
|
||||
inline boost::int64_t load_little_s48( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::int64_t, 6, order::little>( p );
|
||||
}
|
||||
|
||||
inline boost::uint64_t load_little_u48( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::uint64_t, 6, order::little>( p );
|
||||
}
|
||||
|
||||
inline boost::int64_t load_big_s48( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::int64_t, 6, order::big>( p );
|
||||
}
|
||||
|
||||
inline boost::uint64_t load_big_u48( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::uint64_t, 6, order::big>( p );
|
||||
}
|
||||
|
||||
// load 56
|
||||
|
||||
inline boost::int64_t load_little_s56( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::int64_t, 7, order::little>( p );
|
||||
}
|
||||
|
||||
inline boost::uint64_t load_little_u56( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::uint64_t, 7, order::little>( p );
|
||||
}
|
||||
|
||||
inline boost::int64_t load_big_s56( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::int64_t, 7, order::big>( p );
|
||||
}
|
||||
|
||||
inline boost::uint64_t load_big_u56( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::uint64_t, 7, order::big>( p );
|
||||
}
|
||||
|
||||
// load 64
|
||||
|
||||
inline boost::int64_t load_little_s64( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::int64_t, 8, order::little>( p );
|
||||
}
|
||||
|
||||
inline boost::uint64_t load_little_u64( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::uint64_t, 8, order::little>( p );
|
||||
}
|
||||
|
||||
inline boost::int64_t load_big_s64( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::int64_t, 8, order::big>( p );
|
||||
}
|
||||
|
||||
inline boost::uint64_t load_big_u64( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::endian::endian_load<boost::uint64_t, 8, order::big>( p );
|
||||
}
|
||||
|
||||
} // namespace endian
|
||||
} // namespace boost
|
||||
|
||||
|
@ -73,3 +73,6 @@ run deprecated_test.cpp ;
|
||||
|
||||
compile endian_reverse_cx_test.cpp ;
|
||||
compile endian_reverse_cx_test.cpp : <define>BOOST_ENDIAN_NO_INTRINSICS : endian_reverse_cx_test_ni ;
|
||||
|
||||
run load_convenience_test.cpp ;
|
||||
run load_convenience_test.cpp : : : <define>BOOST_ENDIAN_NO_INTRINSICS : load_convenience_test_ni ;
|
||||
|
75
test/load_convenience_test.cpp
Normal file
75
test/load_convenience_test.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
// Copyright 2019 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/endian/conversion.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost::endian;
|
||||
|
||||
unsigned char v[] = { 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8 };
|
||||
|
||||
// 16
|
||||
|
||||
BOOST_TEST_EQ( load_little_s16( v ), -3343 );
|
||||
BOOST_TEST_EQ( load_little_u16( v ), 0xF2F1 );
|
||||
|
||||
BOOST_TEST_EQ( load_big_s16( v ), -3598 );
|
||||
BOOST_TEST_EQ( load_big_u16( v ), 0xF1F2 );
|
||||
|
||||
// 24
|
||||
|
||||
BOOST_TEST_EQ( load_little_s24( v ), -789775 );
|
||||
BOOST_TEST_EQ( load_little_u24( v ), 0xF3F2F1 );
|
||||
|
||||
BOOST_TEST_EQ( load_big_s24( v ), -920845 );
|
||||
BOOST_TEST_EQ( load_big_u24( v ), 0xF1F2F3 );
|
||||
|
||||
// 32
|
||||
|
||||
BOOST_TEST_EQ( load_little_s32( v ), 0xF4F3F2F1 );
|
||||
BOOST_TEST_EQ( load_little_u32( v ), 0xF4F3F2F1 );
|
||||
|
||||
BOOST_TEST_EQ( load_big_s32( v ), 0xF1F2F3F4 );
|
||||
BOOST_TEST_EQ( load_big_u32( v ), 0xF1F2F3F4 );
|
||||
|
||||
// 40
|
||||
|
||||
BOOST_TEST_EQ( load_little_s40( v ), -43135012111 );
|
||||
BOOST_TEST_EQ( load_little_u40( v ), 0xF5F4F3F2F1 );
|
||||
|
||||
BOOST_TEST_EQ( load_big_s40( v ), -60348435211 );
|
||||
BOOST_TEST_EQ( load_big_u40( v ), 0xF1F2F3F4F5 );
|
||||
|
||||
// 48
|
||||
|
||||
BOOST_TEST_EQ( load_little_s48( v ), -9938739662095 );
|
||||
BOOST_TEST_EQ( load_little_u48( v ), 0xF6F5F4F3F2F1 );
|
||||
|
||||
BOOST_TEST_EQ( load_big_s48( v ), -15449199413770 );
|
||||
BOOST_TEST_EQ( load_big_u48( v ), 0xF1F2F3F4F5F6 );
|
||||
|
||||
// 56
|
||||
|
||||
BOOST_TEST_EQ( load_little_s56( v ), -2261738553347343 );
|
||||
BOOST_TEST_EQ( load_little_u56( v ), 0xF7F6F5F4F3F2F1 );
|
||||
|
||||
BOOST_TEST_EQ( load_big_s56( v ), -3954995049924873 );
|
||||
BOOST_TEST_EQ( load_big_u56( v ), 0xF1F2F3F4F5F6F7 );
|
||||
|
||||
// 64
|
||||
|
||||
BOOST_TEST_EQ( load_little_s64( v ), 0xF8F7F6F5F4F3F2F1 );
|
||||
BOOST_TEST_EQ( load_little_u64( v ), 0xF8F7F6F5F4F3F2F1 );
|
||||
|
||||
BOOST_TEST_EQ( load_big_s64( v ), 0xF1F2F3F4F5F6F7F8 );
|
||||
BOOST_TEST_EQ( load_big_u64( v ), 0xF1F2F3F4F5F6F7F8 );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user