feat():initial version
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
// disable_warnings.hpp --------------------------------------------------------------//
|
||||
|
||||
// Copyright Beman Dawes 2011
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#ifndef _SCL_SECURE_NO_WARNINGS
|
||||
# define _SCL_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#ifndef _CRT_SECURE_NO_WARNINGS
|
||||
# define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
# pragma warning(push)
|
||||
|
||||
// triggered by boost/detail/lightweight_test.hpp
|
||||
# pragma warning( disable : 4640 ) // ... construction of local static object is not thread-safe
|
||||
|
||||
// triggered by Microsoft's own headers, so disable
|
||||
# pragma warning( disable : 4820 ) // padding added after data member
|
||||
# pragma warning( disable : 4548 ) // expression before comma has no effect
|
||||
# pragma warning( disable : 4668 ) // ... is not defined as a preprocessor macro
|
||||
# pragma warning( disable : 4514 ) // ... unreferenced inline function has been removed
|
||||
# pragma warning( disable : 4710 ) // ... function not inlined
|
||||
# pragma warning( disable : 4986 ) // ... exception specification does not match previous declaration
|
||||
# pragma warning( disable : 4711 ) // ... selected for automatic inline expansion
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
// disable_warnings_pop.hpp ----------------------------------------------------------//
|
||||
|
||||
// Copyright Beman Dawes 2011
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
589
install/boost_1_75_0/include/boost/endian/detail/endian_load.hpp
Normal file
589
install/boost_1_75_0/include/boost/endian/detail/endian_load.hpp
Normal file
@@ -0,0 +1,589 @@
|
||||
#ifndef BOOST_ENDIAN_DETAIL_ENDIAN_LOAD_HPP_INCLUDED
|
||||
#define BOOST_ENDIAN_DETAIL_ENDIAN_LOAD_HPP_INCLUDED
|
||||
|
||||
// Copyright 2019 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/endian/detail/endian_reverse.hpp>
|
||||
#include <boost/endian/detail/order.hpp>
|
||||
#include <boost/endian/detail/integral_by_size.hpp>
|
||||
#include <boost/endian/detail/is_trivially_copyable.hpp>
|
||||
#include <boost/type_traits/is_signed.hpp>
|
||||
#include <boost/type_traits/is_integral.hpp>
|
||||
#include <boost/type_traits/is_enum.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace endian
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class T, std::size_t N1, BOOST_SCOPED_ENUM(order) O1, std::size_t N2, BOOST_SCOPED_ENUM(order) O2> struct endian_load_impl
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
// Requires:
|
||||
//
|
||||
// sizeof(T) must be 1, 2, 4, or 8
|
||||
// 1 <= N <= sizeof(T)
|
||||
// T is TriviallyCopyable
|
||||
// if N < sizeof(T), T is integral or enum
|
||||
|
||||
template<class T, std::size_t N, BOOST_SCOPED_ENUM(order) Order>
|
||||
inline T endian_load( unsigned char const * p ) BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( sizeof(T) == 1 || sizeof(T) == 2 || sizeof(T) == 4 || sizeof(T) == 8 );
|
||||
BOOST_STATIC_ASSERT( N >= 1 && N <= sizeof(T) );
|
||||
|
||||
return detail::endian_load_impl<T, sizeof(T), order::native, N, Order>()( p );
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// same endianness, same size
|
||||
|
||||
template<class T, std::size_t N, BOOST_SCOPED_ENUM(order) O> struct endian_load_impl<T, N, O, N, O>
|
||||
{
|
||||
inline T operator()( unsigned char const * p ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_trivially_copyable<T>::value );
|
||||
|
||||
T t;
|
||||
std::memcpy( &t, p, N );
|
||||
return t;
|
||||
}
|
||||
};
|
||||
|
||||
// same size, reverse endianness
|
||||
|
||||
template<class T, std::size_t N, BOOST_SCOPED_ENUM(order) O1, BOOST_SCOPED_ENUM(order) O2> struct endian_load_impl<T, N, O1, N, O2>
|
||||
{
|
||||
inline T operator()( unsigned char const * p ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_trivially_copyable<T>::value );
|
||||
|
||||
typename integral_by_size<N>::type tmp;
|
||||
std::memcpy( &tmp, p, N );
|
||||
|
||||
endian_reverse_inplace( tmp );
|
||||
|
||||
T t;
|
||||
std::memcpy( &t, &tmp, N );
|
||||
return t;
|
||||
}
|
||||
};
|
||||
|
||||
// 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>
|
||||
{
|
||||
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 ];
|
||||
|
||||
tmp[0] = p[0];
|
||||
tmp[1] = p[1];
|
||||
tmp[2] = p[2];
|
||||
tmp[3] = boost::is_signed<T>::value && ( p[2] & 0x80 )? 0xFF: 0x00;
|
||||
|
||||
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, 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[ 4 ];
|
||||
|
||||
tmp[0] = boost::is_signed<T>::value && ( p[0] & 0x80 )? 0xFF: 0x00;
|
||||
tmp[1] = p[0];
|
||||
tmp[2] = p[1];
|
||||
tmp[3] = p[2];
|
||||
|
||||
return boost::endian::endian_load<T, 4, order::big>( tmp );
|
||||
}
|
||||
};
|
||||
|
||||
// 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>
|
||||
{
|
||||
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[4] & 0x80 )? 0xFF: 0x00;
|
||||
|
||||
tmp[0] = p[0];
|
||||
tmp[1] = p[1];
|
||||
tmp[2] = p[2];
|
||||
tmp[3] = p[3];
|
||||
tmp[4] = p[4];
|
||||
|
||||
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, 5, 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] = p[0];
|
||||
tmp[4] = p[1];
|
||||
tmp[5] = p[2];
|
||||
tmp[6] = p[3];
|
||||
tmp[7] = p[4];
|
||||
|
||||
return boost::endian::endian_load<T, 8, order::big>( tmp );
|
||||
}
|
||||
};
|
||||
|
||||
// expanding load 6 -> 8
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_load_impl<T, 8, Order, 6, 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[5] & 0x80 )? 0xFF: 0x00;
|
||||
|
||||
tmp[0] = p[0];
|
||||
tmp[1] = p[1];
|
||||
tmp[2] = p[2];
|
||||
tmp[3] = p[3];
|
||||
tmp[4] = p[4];
|
||||
tmp[5] = p[5];
|
||||
|
||||
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, 6, 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] = p[0];
|
||||
tmp[3] = p[1];
|
||||
tmp[4] = p[2];
|
||||
tmp[5] = p[3];
|
||||
tmp[6] = p[4];
|
||||
tmp[7] = p[5];
|
||||
|
||||
return boost::endian::endian_load<T, 8, order::big>( tmp );
|
||||
}
|
||||
};
|
||||
|
||||
// expanding load 7 -> 8
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_load_impl<T, 8, Order, 7, 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[6] & 0x80 )? 0xFF: 0x00;
|
||||
|
||||
tmp[0] = p[0];
|
||||
tmp[1] = p[1];
|
||||
tmp[2] = p[2];
|
||||
tmp[3] = p[3];
|
||||
tmp[4] = p[4];
|
||||
tmp[5] = p[5];
|
||||
tmp[6] = p[6];
|
||||
|
||||
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, 7, 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] = p[0];
|
||||
tmp[2] = p[1];
|
||||
tmp[3] = p[2];
|
||||
tmp[4] = p[3];
|
||||
tmp[5] = p[4];
|
||||
tmp[6] = p[5];
|
||||
tmp[7] = p[6];
|
||||
|
||||
return boost::endian::endian_load<T, 8, order::big>( tmp );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace endian
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_ENDIAN_DETAIL_ENDIAN_LOAD_HPP_INCLUDED
|
||||
@@ -0,0 +1,178 @@
|
||||
#ifndef BOOST_ENDIAN_DETAIL_ENDIAN_REVERSE_HPP_INCLUDED
|
||||
#define BOOST_ENDIAN_DETAIL_ENDIAN_REVERSE_HPP_INCLUDED
|
||||
|
||||
// Copyright 2019, 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/endian/detail/integral_by_size.hpp>
|
||||
#include <boost/endian/detail/intrinsic.hpp>
|
||||
#include <boost/endian/detail/is_scoped_enum.hpp>
|
||||
#include <boost/type_traits/is_integral.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/type_traits/enable_if.hpp>
|
||||
#include <boost/type_traits/is_class.hpp>
|
||||
#include <boost/type_traits/integral_constant.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
|
||||
#if defined(BOOST_ENDIAN_NO_INTRINSICS)
|
||||
# if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
# define BOOST_ENDIAN_CONSTEXPR
|
||||
# else
|
||||
# define BOOST_ENDIAN_CONSTEXPR constexpr
|
||||
# endif
|
||||
#else
|
||||
# if defined(BOOST_ENDIAN_CONSTEXPR_INTRINSICS)
|
||||
# define BOOST_ENDIAN_CONSTEXPR BOOST_CONSTEXPR
|
||||
# else
|
||||
# define BOOST_ENDIAN_CONSTEXPR
|
||||
# endif
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace endian
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// -- portable approach suggested by tymofey, with avoidance of undefined behavior
|
||||
// as suggested by Giovanni Piero Deretta, with a further refinement suggested
|
||||
// by Pyry Jahkola.
|
||||
// -- intrinsic approach suggested by reviewers, and by David Stone, who provided
|
||||
// his Boost licensed macro implementation (detail/intrinsic.hpp)
|
||||
|
||||
inline uint8_t BOOST_CONSTEXPR endian_reverse_impl( uint8_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
inline uint16_t BOOST_ENDIAN_CONSTEXPR endian_reverse_impl( uint16_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
#ifdef BOOST_ENDIAN_NO_INTRINSICS
|
||||
|
||||
return (x << 8) | (x >> 8);
|
||||
|
||||
#else
|
||||
|
||||
return BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_2(x);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
inline uint32_t BOOST_ENDIAN_CONSTEXPR endian_reverse_impl( uint32_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
#ifdef BOOST_ENDIAN_NO_INTRINSICS
|
||||
|
||||
uint32_t step16 = x << 16 | x >> 16;
|
||||
return ((step16 << 8) & 0xff00ff00) | ((step16 >> 8) & 0x00ff00ff);
|
||||
|
||||
#else
|
||||
|
||||
return BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_4(x);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
inline uint64_t BOOST_ENDIAN_CONSTEXPR endian_reverse_impl( uint64_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
#ifdef BOOST_ENDIAN_NO_INTRINSICS
|
||||
|
||||
uint64_t step32 = x << 32 | x >> 32;
|
||||
uint64_t step16 = (step32 & 0x0000FFFF0000FFFFULL) << 16 | (step32 & 0xFFFF0000FFFF0000ULL) >> 16;
|
||||
return (step16 & 0x00FF00FF00FF00FFULL) << 8 | (step16 & 0xFF00FF00FF00FF00ULL) >> 8;
|
||||
|
||||
#else
|
||||
|
||||
return BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_8(x);
|
||||
|
||||
# endif
|
||||
}
|
||||
|
||||
#if defined(BOOST_HAS_INT128)
|
||||
|
||||
inline uint128_type BOOST_ENDIAN_CONSTEXPR endian_reverse_impl( uint128_type x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return endian_reverse_impl( static_cast<uint64_t>( x >> 64 ) ) |
|
||||
static_cast<uint128_type>( endian_reverse_impl( static_cast<uint64_t>( x ) ) ) << 64;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// is_endian_reversible
|
||||
|
||||
template<class T> struct is_endian_reversible: boost::integral_constant<bool,
|
||||
(boost::is_integral<T>::value && !boost::is_same<T, bool>::value) || is_scoped_enum<T>::value>
|
||||
{
|
||||
};
|
||||
|
||||
// is_endian_reversible_inplace
|
||||
|
||||
template<class T> struct is_endian_reversible_inplace: boost::integral_constant<bool,
|
||||
boost::is_integral<T>::value || boost::is_enum<T>::value || boost::is_same<T, float>::value || boost::is_same<T, double>::value>
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
// Requires:
|
||||
// T is non-bool integral or scoped enumeration type
|
||||
|
||||
template<class T> inline BOOST_CONSTEXPR
|
||||
typename enable_if_< !is_class<T>::value, T >::type
|
||||
endian_reverse( T x ) BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( detail::is_endian_reversible<T>::value );
|
||||
|
||||
typedef typename detail::integral_by_size< sizeof(T) >::type uintN_t;
|
||||
|
||||
return static_cast<T>( detail::endian_reverse_impl( static_cast<uintN_t>( x ) ) );
|
||||
}
|
||||
|
||||
// Requires:
|
||||
// T is integral, enumeration, float or double
|
||||
|
||||
template<class T> inline
|
||||
typename enable_if_< !is_class<T>::value >::type
|
||||
endian_reverse_inplace( T & x ) BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( detail::is_endian_reversible_inplace<T>::value );
|
||||
|
||||
typename detail::integral_by_size< sizeof(T) >::type x2;
|
||||
|
||||
std::memcpy( &x2, &x, sizeof(T) );
|
||||
|
||||
x2 = detail::endian_reverse_impl( x2 );
|
||||
|
||||
std::memcpy( &x, &x2, sizeof(T) );
|
||||
}
|
||||
|
||||
// Default implementation for user-defined types
|
||||
|
||||
template<class T> inline
|
||||
typename enable_if_< is_class<T>::value >::type
|
||||
endian_reverse_inplace( T & x ) BOOST_NOEXCEPT
|
||||
{
|
||||
x = endian_reverse( x );
|
||||
}
|
||||
|
||||
// endian_reverse_inplace for arrays
|
||||
|
||||
template<class T, std::size_t N>
|
||||
inline void endian_reverse_inplace( T (&x)[ N ] ) BOOST_NOEXCEPT
|
||||
{
|
||||
for( std::size_t i = 0; i < N; ++i )
|
||||
{
|
||||
endian_reverse_inplace( x[i] );
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace endian
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_ENDIAN_DETAIL_ENDIAN_REVERSE_HPP_INCLUDED
|
||||
@@ -0,0 +1,442 @@
|
||||
#ifndef BOOST_ENDIAN_DETAIL_ENDIAN_STORE_HPP_INCLUDED
|
||||
#define BOOST_ENDIAN_DETAIL_ENDIAN_STORE_HPP_INCLUDED
|
||||
|
||||
// Copyright 2019 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/endian/detail/endian_reverse.hpp>
|
||||
#include <boost/endian/detail/order.hpp>
|
||||
#include <boost/endian/detail/integral_by_size.hpp>
|
||||
#include <boost/endian/detail/is_trivially_copyable.hpp>
|
||||
#include <boost/type_traits/is_integral.hpp>
|
||||
#include <boost/type_traits/is_enum.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace endian
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class T, std::size_t N1, BOOST_SCOPED_ENUM(order) O1, std::size_t N2, BOOST_SCOPED_ENUM(order) O2> struct endian_store_impl
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
// Requires:
|
||||
//
|
||||
// sizeof(T) must be 1, 2, 4, or 8
|
||||
// 1 <= N <= sizeof(T)
|
||||
// T is TriviallyCopyable
|
||||
// if N < sizeof(T), T is integral or enum
|
||||
|
||||
template<class T, std::size_t N, BOOST_SCOPED_ENUM(order) Order>
|
||||
inline void endian_store( unsigned char * p, T const & v ) BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( sizeof(T) == 1 || sizeof(T) == 2 || sizeof(T) == 4 || sizeof(T) == 8 );
|
||||
BOOST_STATIC_ASSERT( N >= 1 && N <= sizeof(T) );
|
||||
|
||||
return detail::endian_store_impl<T, sizeof(T), order::native, N, Order>()( p, v );
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// same endianness, same size
|
||||
|
||||
template<class T, std::size_t N, BOOST_SCOPED_ENUM(order) O> struct endian_store_impl<T, N, O, N, O>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_trivially_copyable<T>::value );
|
||||
|
||||
std::memcpy( p, &v, N );
|
||||
}
|
||||
};
|
||||
|
||||
// same size, reverse endianness
|
||||
|
||||
template<class T, std::size_t N, BOOST_SCOPED_ENUM(order) O1, BOOST_SCOPED_ENUM(order) O2> struct endian_store_impl<T, N, O1, N, O2>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_trivially_copyable<T>::value );
|
||||
|
||||
typename integral_by_size<N>::type tmp;
|
||||
std::memcpy( &tmp, &v, N );
|
||||
|
||||
endian_reverse_inplace( tmp );
|
||||
|
||||
std::memcpy( p, &tmp, N );
|
||||
}
|
||||
};
|
||||
|
||||
// truncating store 2 -> 1
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 2, Order, 1, order::little>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 2 ];
|
||||
boost::endian::endian_store<T, 2, order::little>( tmp, v );
|
||||
|
||||
p[0] = tmp[0];
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 2, Order, 1, order::big>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 2 ];
|
||||
boost::endian::endian_store<T, 2, order::big>( tmp, v );
|
||||
|
||||
p[0] = tmp[1];
|
||||
}
|
||||
};
|
||||
|
||||
// truncating store 4 -> 1
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 4, Order, 1, order::little>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 4 ];
|
||||
boost::endian::endian_store<T, 4, order::little>( tmp, v );
|
||||
|
||||
p[0] = tmp[0];
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 4, Order, 1, order::big>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 4 ];
|
||||
boost::endian::endian_store<T, 4, order::big>( tmp, v );
|
||||
|
||||
p[0] = tmp[3];
|
||||
}
|
||||
};
|
||||
|
||||
// truncating store 4 -> 2
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 4, Order, 2, order::little>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 4 ];
|
||||
boost::endian::endian_store<T, 4, order::little>( tmp, v );
|
||||
|
||||
p[0] = tmp[0];
|
||||
p[1] = tmp[1];
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 4, Order, 2, order::big>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 4 ];
|
||||
boost::endian::endian_store<T, 4, order::big>( tmp, v );
|
||||
|
||||
p[0] = tmp[2];
|
||||
p[1] = tmp[3];
|
||||
}
|
||||
};
|
||||
|
||||
// truncating store 4 -> 3
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 4, Order, 3, order::little>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 4 ];
|
||||
boost::endian::endian_store<T, 4, order::little>( tmp, v );
|
||||
|
||||
p[0] = tmp[0];
|
||||
p[1] = tmp[1];
|
||||
p[2] = tmp[2];
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 4, Order, 3, order::big>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 4 ];
|
||||
boost::endian::endian_store<T, 4, order::big>( tmp, v );
|
||||
|
||||
p[0] = tmp[1];
|
||||
p[1] = tmp[2];
|
||||
p[2] = tmp[3];
|
||||
}
|
||||
};
|
||||
|
||||
// truncating store 8 -> 1
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 1, order::little>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
boost::endian::endian_store<T, 8, order::little>( tmp, v );
|
||||
|
||||
p[0] = tmp[0];
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 1, order::big>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
boost::endian::endian_store<T, 8, order::big>( tmp, v );
|
||||
|
||||
p[0] = tmp[7];
|
||||
}
|
||||
};
|
||||
|
||||
// truncating store 8 -> 2
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 2, order::little>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
boost::endian::endian_store<T, 8, order::little>( tmp, v );
|
||||
|
||||
p[0] = tmp[0];
|
||||
p[1] = tmp[1];
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 2, order::big>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
boost::endian::endian_store<T, 8, order::big>( tmp, v );
|
||||
|
||||
p[0] = tmp[6];
|
||||
p[1] = tmp[7];
|
||||
}
|
||||
};
|
||||
|
||||
// truncating store 8 -> 3
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 3, order::little>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
boost::endian::endian_store<T, 8, order::little>( tmp, v );
|
||||
|
||||
p[0] = tmp[0];
|
||||
p[1] = tmp[1];
|
||||
p[2] = tmp[2];
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 3, order::big>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
boost::endian::endian_store<T, 8, order::big>( tmp, v );
|
||||
|
||||
p[0] = tmp[5];
|
||||
p[1] = tmp[6];
|
||||
p[2] = tmp[7];
|
||||
}
|
||||
};
|
||||
|
||||
// truncating store 8 -> 4
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 4, order::little>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
boost::endian::endian_store<T, 8, order::little>( tmp, v );
|
||||
|
||||
p[0] = tmp[0];
|
||||
p[1] = tmp[1];
|
||||
p[2] = tmp[2];
|
||||
p[3] = tmp[3];
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 4, order::big>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
boost::endian::endian_store<T, 8, order::big>( tmp, v );
|
||||
|
||||
p[0] = tmp[4];
|
||||
p[1] = tmp[5];
|
||||
p[2] = tmp[6];
|
||||
p[3] = tmp[7];
|
||||
}
|
||||
};
|
||||
|
||||
// truncating store 8 -> 5
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 5, order::little>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
boost::endian::endian_store<T, 8, order::little>( tmp, v );
|
||||
|
||||
p[0] = tmp[0];
|
||||
p[1] = tmp[1];
|
||||
p[2] = tmp[2];
|
||||
p[3] = tmp[3];
|
||||
p[4] = tmp[4];
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 5, order::big>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
boost::endian::endian_store<T, 8, order::big>( tmp, v );
|
||||
|
||||
p[0] = tmp[3];
|
||||
p[1] = tmp[4];
|
||||
p[2] = tmp[5];
|
||||
p[3] = tmp[6];
|
||||
p[4] = tmp[7];
|
||||
}
|
||||
};
|
||||
|
||||
// truncating store 8 -> 6
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 6, order::little>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
boost::endian::endian_store<T, 8, order::little>( tmp, v );
|
||||
|
||||
p[0] = tmp[0];
|
||||
p[1] = tmp[1];
|
||||
p[2] = tmp[2];
|
||||
p[3] = tmp[3];
|
||||
p[4] = tmp[4];
|
||||
p[5] = tmp[5];
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 6, order::big>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
boost::endian::endian_store<T, 8, order::big>( tmp, v );
|
||||
|
||||
p[0] = tmp[2];
|
||||
p[1] = tmp[3];
|
||||
p[2] = tmp[4];
|
||||
p[3] = tmp[5];
|
||||
p[4] = tmp[6];
|
||||
p[5] = tmp[7];
|
||||
}
|
||||
};
|
||||
|
||||
// truncating store 8 -> 7
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 7, order::little>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
boost::endian::endian_store<T, 8, order::little>( tmp, v );
|
||||
|
||||
p[0] = tmp[0];
|
||||
p[1] = tmp[1];
|
||||
p[2] = tmp[2];
|
||||
p[3] = tmp[3];
|
||||
p[4] = tmp[4];
|
||||
p[5] = tmp[5];
|
||||
p[6] = tmp[6];
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 7, order::big>
|
||||
{
|
||||
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
|
||||
|
||||
unsigned char tmp[ 8 ];
|
||||
boost::endian::endian_store<T, 8, order::big>( tmp, v );
|
||||
|
||||
p[0] = tmp[1];
|
||||
p[1] = tmp[2];
|
||||
p[2] = tmp[3];
|
||||
p[3] = tmp[4];
|
||||
p[4] = tmp[5];
|
||||
p[5] = tmp[6];
|
||||
p[6] = tmp[7];
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace endian
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_ENDIAN_DETAIL_ENDIAN_STORE_HPP_INCLUDED
|
||||
@@ -0,0 +1,57 @@
|
||||
#ifndef BOOST_ENDIAN_DETAIL_INTEGRAL_BY_SIZE_HPP_INCLUDED
|
||||
#define BOOST_ENDIAN_DETAIL_INTEGRAL_BY_SIZE_HPP_INCLUDED
|
||||
|
||||
// Copyright 2019 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace endian
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<std::size_t N> struct integral_by_size
|
||||
{
|
||||
};
|
||||
|
||||
template<> struct integral_by_size<1>
|
||||
{
|
||||
typedef uint8_t type;
|
||||
};
|
||||
|
||||
template<> struct integral_by_size<2>
|
||||
{
|
||||
typedef uint16_t type;
|
||||
};
|
||||
|
||||
template<> struct integral_by_size<4>
|
||||
{
|
||||
typedef uint32_t type;
|
||||
};
|
||||
|
||||
template<> struct integral_by_size<8>
|
||||
{
|
||||
typedef uint64_t type;
|
||||
};
|
||||
|
||||
#if defined(BOOST_HAS_INT128)
|
||||
|
||||
template<> struct integral_by_size<16>
|
||||
{
|
||||
typedef uint128_type type;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
} // namespace endian
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_ENDIAN_DETAIL_INTEGRAL_BY_SIZE_HPP_INCLUDED
|
||||
@@ -0,0 +1,69 @@
|
||||
// endian/detail/intrinsic.hpp -------------------------------------------------------//
|
||||
|
||||
// Copyright (C) 2012 David Stone
|
||||
// Copyright Beman Dawes 2013
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#ifndef BOOST_ENDIAN_INTRINSIC_HPP
|
||||
#define BOOST_ENDIAN_INTRINSIC_HPP
|
||||
|
||||
// Allow user to force BOOST_ENDIAN_NO_INTRINSICS in case they aren't available for a
|
||||
// particular platform/compiler combination. Please report such platform/compiler
|
||||
// combinations to the Boost mailing list.
|
||||
#ifndef BOOST_ENDIAN_NO_INTRINSICS
|
||||
|
||||
#ifndef __has_builtin // Optional of course
|
||||
#define __has_builtin(x) 0 // Compatibility with non-clang compilers
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && ( !defined(__clang__) || defined(__c2__) )
|
||||
// Microsoft documents these as being compatible since Windows 95 and specifically
|
||||
// lists runtime library support since Visual Studio 2003 (aka 7.1).
|
||||
// Clang/c2 uses the Microsoft rather than GCC intrinsics, so we check for
|
||||
// defined(_MSC_VER) before defined(__clang__)
|
||||
# define BOOST_ENDIAN_INTRINSIC_MSG "cstdlib _byteswap_ushort, etc."
|
||||
# include <cstdlib>
|
||||
# define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_2(x) _byteswap_ushort(x)
|
||||
# define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_4(x) _byteswap_ulong(x)
|
||||
# define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_8(x) _byteswap_uint64(x)
|
||||
|
||||
// GCC and Clang recent versions provide intrinsic byte swaps via builtins
|
||||
#elif (defined(__clang__) && __has_builtin(__builtin_bswap32) && __has_builtin(__builtin_bswap64)) \
|
||||
|| (defined(__GNUC__ ) && \
|
||||
(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
|
||||
# define BOOST_ENDIAN_INTRINSIC_MSG "__builtin_bswap16, etc."
|
||||
// prior to 4.8, gcc did not provide __builtin_bswap16 on some platforms so we emulate it
|
||||
// see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52624
|
||||
// Clang has a similar problem, but their feature test macros make it easier to detect
|
||||
# if (defined(__clang__) && __has_builtin(__builtin_bswap16)) \
|
||||
|| (defined(__GNUC__) &&(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))
|
||||
# define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_2(x) __builtin_bswap16(x)
|
||||
# else
|
||||
# define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_2(x) __builtin_bswap32((x) << 16)
|
||||
# endif
|
||||
# define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_4(x) __builtin_bswap32(x)
|
||||
# define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_8(x) __builtin_bswap64(x)
|
||||
|
||||
# define BOOST_ENDIAN_CONSTEXPR_INTRINSICS
|
||||
|
||||
// Linux systems provide the byteswap.h header, with
|
||||
#elif defined(__linux__)
|
||||
// don't check for obsolete forms defined(linux) and defined(__linux) on the theory that
|
||||
// compilers that predefine only these are so old that byteswap.h probably isn't present.
|
||||
# define BOOST_ENDIAN_INTRINSIC_MSG "byteswap.h bswap_16, etc."
|
||||
# include <byteswap.h>
|
||||
# define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_2(x) bswap_16(x)
|
||||
# define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_4(x) bswap_32(x)
|
||||
# define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_8(x) bswap_64(x)
|
||||
|
||||
#else
|
||||
# define BOOST_ENDIAN_NO_INTRINSICS
|
||||
# define BOOST_ENDIAN_INTRINSIC_MSG "no byte swap intrinsics"
|
||||
#endif
|
||||
|
||||
#elif !defined(BOOST_ENDIAN_INTRINSIC_MSG)
|
||||
# define BOOST_ENDIAN_INTRINSIC_MSG "no byte swap intrinsics"
|
||||
#endif // BOOST_ENDIAN_NO_INTRINSICS
|
||||
#endif // BOOST_ENDIAN_INTRINSIC_HPP
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef BOOST_ENDIAN_DETAIL_IS_SCOPED_ENUM_HPP_INCLUDED
|
||||
#define BOOST_ENDIAN_DETAIL_IS_SCOPED_ENUM_HPP_INCLUDED
|
||||
|
||||
// Copyright 2020 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/type_traits/conditional.hpp>
|
||||
#include <boost/type_traits/is_enum.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace endian
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class T> struct negation: boost::integral_constant<bool, !T::value> {};
|
||||
|
||||
template<class T> struct is_scoped_enum:
|
||||
boost::conditional<
|
||||
boost::is_enum<T>::value,
|
||||
negation< boost::is_convertible<T, int> >,
|
||||
boost::false_type
|
||||
>::type
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace endian
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_ENDIAN_DETAIL_IS_SCOPED_ENUM_HPP_INCLUDED
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef BOOST_ENDIAN_DETAIL_IS_TRIVIALLY_COPYABLE_HPP_INCLUDED
|
||||
#define BOOST_ENDIAN_DETAIL_IS_TRIVIALLY_COPYABLE_HPP_INCLUDED
|
||||
|
||||
// Copyright 2019 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/type_traits/has_trivial_copy.hpp>
|
||||
#include <boost/type_traits/has_trivial_assign.hpp>
|
||||
#include <boost/type_traits/has_trivial_destructor.hpp>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
|
||||
# include <type_traits>
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace endian
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
|
||||
|
||||
using std::is_trivially_copyable;
|
||||
|
||||
#else
|
||||
|
||||
template<class T> struct is_trivially_copyable: boost::integral_constant<bool,
|
||||
boost::has_trivial_copy<T>::value && boost::has_trivial_assign<T>::value && boost::has_trivial_destructor<T>::value> {};
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
} // namespace endian
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_ENDIAN_DETAIL_IS_TRIVIALLY_COPYABLE_HPP_INCLUDED
|
||||
59
install/boost_1_75_0/include/boost/endian/detail/order.hpp
Normal file
59
install/boost_1_75_0/include/boost/endian/detail/order.hpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef BOOST_ENDIAN_DETAIL_ORDER_HPP_INCLUDED
|
||||
#define BOOST_ENDIAN_DETAIL_ORDER_HPP_INCLUDED
|
||||
|
||||
// Copyright 2019 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/core/scoped_enum.hpp>
|
||||
|
||||
#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
|
||||
# define BOOST_ENDIAN_NATIVE_ORDER_INITIALIZER little
|
||||
|
||||
#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
|
||||
# define BOOST_ENDIAN_NATIVE_ORDER_INITIALIZER big
|
||||
|
||||
#elif defined(__BYTE_ORDER__) && defined(__ORDER_PDP_ENDIAN__) && __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__
|
||||
|
||||
# error The Boost.Endian library does not support platforms with PDP endianness.
|
||||
|
||||
#elif defined(__LITTLE_ENDIAN__)
|
||||
|
||||
# define BOOST_ENDIAN_NATIVE_ORDER_INITIALIZER little
|
||||
|
||||
#elif defined(__BIG_ENDIAN__)
|
||||
|
||||
# define BOOST_ENDIAN_NATIVE_ORDER_INITIALIZER big
|
||||
|
||||
#elif defined(_MSC_VER) || defined(__i386__) || defined(__x86_64__)
|
||||
|
||||
# define BOOST_ENDIAN_NATIVE_ORDER_INITIALIZER little
|
||||
|
||||
#else
|
||||
|
||||
# error The Boost.Endian library could not determine the endianness of this platform.
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace endian
|
||||
{
|
||||
|
||||
BOOST_SCOPED_ENUM_START(order)
|
||||
{
|
||||
big,
|
||||
little,
|
||||
native = BOOST_ENDIAN_NATIVE_ORDER_INITIALIZER
|
||||
|
||||
}; BOOST_SCOPED_ENUM_END
|
||||
|
||||
} // namespace endian
|
||||
} // namespace boost
|
||||
|
||||
#undef BOOST_ENDIAN_NATIVE_ORDER_INITIALIZER
|
||||
|
||||
#endif // BOOST_ENDIAN_DETAIL_ORDER_HPP_INCLUDED
|
||||
Reference in New Issue
Block a user