1
0
mirror of https://git.suyu.dev/suyu/suyu synced 2025-09-11 00:36:35 -05:00

Initial commit

This commit is contained in:
Crimson-Hawk
2024-03-05 16:42:40 +08:00
commit f1e4595ebf
39576 changed files with 7006612 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
#ifndef BOOST_ENDIAN_HPP_INCLUDED
#define BOOST_ENDIAN_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/conversion.hpp>
#include <boost/endian/buffers.hpp>
#include <boost/endian/arithmetic.hpp>
#endif // #ifndef BOOST_ENDIAN_HPP_INCLUDED

View File

@@ -0,0 +1,370 @@
// boost/endian/arithmetic.hpp -------------------------------------------------------//
// (C) Copyright Darin Adler 2000
// (C) Copyright Beman Dawes 2006, 2009, 2014
// (C) Copyright Peter Dimov 2019
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// See library home page at http://www.boost.org/libs/endian
//--------------------------------------------------------------------------------------//
// Original design developed by Darin Adler based on classes developed by Mark
// Borgerding. Four original class templates were combined into a single endian
// class template by Beman Dawes, who also added the unrolled_byte_loops sign
// partial specialization to correctly extend the sign when cover integer size
// differs from endian representation size.
// TODO: When a compiler supporting constexpr becomes available, try possible uses.
#ifndef BOOST_ENDIAN_ARITHMETIC_HPP
#define BOOST_ENDIAN_ARITHMETIC_HPP
#if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable:4365) // conversion ... signed/unsigned mismatch
#endif
#include <boost/endian/buffers.hpp>
#include <boost/core/scoped_enum.hpp>
#include <boost/static_assert.hpp>
#include <boost/cstdint.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#include <iosfwd>
#include <climits>
#if defined(BOOST_BORLANDC) || defined(BOOST_CODEGEARC)
# pragma pack(push, 1)
#endif
# if CHAR_BIT != 8
# error Platforms with CHAR_BIT != 8 are not supported
# endif
# ifdef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
# define BOOST_ENDIAN_DEFAULT_CONSTRUCT {} // C++03
# else
# define BOOST_ENDIAN_DEFAULT_CONSTRUCT = default; // C++0x
# endif
// g++ pre-4.6 does not support unrestricted unions, but we have no Config macro for that
# if (defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) || BOOST_WORKAROUND(BOOST_GCC, < 40600)) && defined(BOOST_ENDIAN_FORCE_PODNESS)
# define BOOST_ENDIAN_NO_CTORS
# endif
# ifndef BOOST_ENDIAN_EXPLICIT_CTORS
# define BOOST_ENDIAN_EXPLICIT_OPT
# else
# define BOOST_ENDIAN_EXPLICIT_OPT explicit
# endif
//---------------------------------- synopsis ----------------------------------------//
namespace boost
{
namespace endian
{
template <BOOST_SCOPED_ENUM(order) Order, class T, std::size_t n_bits,
BOOST_SCOPED_ENUM(align) Align = align::no>
class endian_arithmetic;
// big endian signed integer aligned types
typedef endian_arithmetic<order::big, int8_t, 8, align::yes> big_int8_at;
typedef endian_arithmetic<order::big, int16_t, 16, align::yes> big_int16_at;
typedef endian_arithmetic<order::big, int32_t, 32, align::yes> big_int32_at;
typedef endian_arithmetic<order::big, int64_t, 64, align::yes> big_int64_at;
// big endian unsigned integer aligned types
typedef endian_arithmetic<order::big, uint8_t, 8, align::yes> big_uint8_at;
typedef endian_arithmetic<order::big, uint16_t, 16, align::yes> big_uint16_at;
typedef endian_arithmetic<order::big, uint32_t, 32, align::yes> big_uint32_at;
typedef endian_arithmetic<order::big, uint64_t, 64, align::yes> big_uint64_at;
// little endian signed integer aligned types
typedef endian_arithmetic<order::little, int8_t, 8, align::yes> little_int8_at;
typedef endian_arithmetic<order::little, int16_t, 16, align::yes> little_int16_at;
typedef endian_arithmetic<order::little, int32_t, 32, align::yes> little_int32_at;
typedef endian_arithmetic<order::little, int64_t, 64, align::yes> little_int64_at;
// little endian unsigned integer aligned types
typedef endian_arithmetic<order::little, uint8_t, 8, align::yes> little_uint8_at;
typedef endian_arithmetic<order::little, uint16_t, 16, align::yes> little_uint16_at;
typedef endian_arithmetic<order::little, uint32_t, 32, align::yes> little_uint32_at;
typedef endian_arithmetic<order::little, uint64_t, 64, align::yes> little_uint64_at;
// aligned floating point types
typedef endian_arithmetic<order::big, float, 32, align::yes> big_float32_at;
typedef endian_arithmetic<order::big, double, 64, align::yes> big_float64_at;
typedef endian_arithmetic<order::little, float, 32, align::yes> little_float32_at;
typedef endian_arithmetic<order::little, double, 64, align::yes> little_float64_at;
// aligned native endian typedefs are not provided because
// <cstdint> types are superior for this use case
// big endian signed integer unaligned types
typedef endian_arithmetic<order::big, int_least8_t, 8> big_int8_t;
typedef endian_arithmetic<order::big, int_least16_t, 16> big_int16_t;
typedef endian_arithmetic<order::big, int_least32_t, 24> big_int24_t;
typedef endian_arithmetic<order::big, int_least32_t, 32> big_int32_t;
typedef endian_arithmetic<order::big, int_least64_t, 40> big_int40_t;
typedef endian_arithmetic<order::big, int_least64_t, 48> big_int48_t;
typedef endian_arithmetic<order::big, int_least64_t, 56> big_int56_t;
typedef endian_arithmetic<order::big, int_least64_t, 64> big_int64_t;
// big endian unsigned integer unaligned types
typedef endian_arithmetic<order::big, uint_least8_t, 8> big_uint8_t;
typedef endian_arithmetic<order::big, uint_least16_t, 16> big_uint16_t;
typedef endian_arithmetic<order::big, uint_least32_t, 24> big_uint24_t;
typedef endian_arithmetic<order::big, uint_least32_t, 32> big_uint32_t;
typedef endian_arithmetic<order::big, uint_least64_t, 40> big_uint40_t;
typedef endian_arithmetic<order::big, uint_least64_t, 48> big_uint48_t;
typedef endian_arithmetic<order::big, uint_least64_t, 56> big_uint56_t;
typedef endian_arithmetic<order::big, uint_least64_t, 64> big_uint64_t;
// little endian signed integer unaligned types
typedef endian_arithmetic<order::little, int_least8_t, 8> little_int8_t;
typedef endian_arithmetic<order::little, int_least16_t, 16> little_int16_t;
typedef endian_arithmetic<order::little, int_least32_t, 24> little_int24_t;
typedef endian_arithmetic<order::little, int_least32_t, 32> little_int32_t;
typedef endian_arithmetic<order::little, int_least64_t, 40> little_int40_t;
typedef endian_arithmetic<order::little, int_least64_t, 48> little_int48_t;
typedef endian_arithmetic<order::little, int_least64_t, 56> little_int56_t;
typedef endian_arithmetic<order::little, int_least64_t, 64> little_int64_t;
// little endian unsigned integer unaligned types
typedef endian_arithmetic<order::little, uint_least8_t, 8> little_uint8_t;
typedef endian_arithmetic<order::little, uint_least16_t, 16> little_uint16_t;
typedef endian_arithmetic<order::little, uint_least32_t, 24> little_uint24_t;
typedef endian_arithmetic<order::little, uint_least32_t, 32> little_uint32_t;
typedef endian_arithmetic<order::little, uint_least64_t, 40> little_uint40_t;
typedef endian_arithmetic<order::little, uint_least64_t, 48> little_uint48_t;
typedef endian_arithmetic<order::little, uint_least64_t, 56> little_uint56_t;
typedef endian_arithmetic<order::little, uint_least64_t, 64> little_uint64_t;
// native endian signed integer unaligned types
typedef endian_arithmetic<order::native, int_least8_t, 8> native_int8_t;
typedef endian_arithmetic<order::native, int_least16_t, 16> native_int16_t;
typedef endian_arithmetic<order::native, int_least32_t, 24> native_int24_t;
typedef endian_arithmetic<order::native, int_least32_t, 32> native_int32_t;
typedef endian_arithmetic<order::native, int_least64_t, 40> native_int40_t;
typedef endian_arithmetic<order::native, int_least64_t, 48> native_int48_t;
typedef endian_arithmetic<order::native, int_least64_t, 56> native_int56_t;
typedef endian_arithmetic<order::native, int_least64_t, 64> native_int64_t;
// native endian unsigned integer unaligned types
typedef endian_arithmetic<order::native, uint_least8_t, 8> native_uint8_t;
typedef endian_arithmetic<order::native, uint_least16_t, 16> native_uint16_t;
typedef endian_arithmetic<order::native, uint_least32_t, 24> native_uint24_t;
typedef endian_arithmetic<order::native, uint_least32_t, 32> native_uint32_t;
typedef endian_arithmetic<order::native, uint_least64_t, 40> native_uint40_t;
typedef endian_arithmetic<order::native, uint_least64_t, 48> native_uint48_t;
typedef endian_arithmetic<order::native, uint_least64_t, 56> native_uint56_t;
typedef endian_arithmetic<order::native, uint_least64_t, 64> native_uint64_t;
// unaligned floating point types
typedef endian_arithmetic<order::big, float, 32, align::no> big_float32_t;
typedef endian_arithmetic<order::big, double, 64, align::no> big_float64_t;
typedef endian_arithmetic<order::little, float, 32, align::no> little_float32_t;
typedef endian_arithmetic<order::little, double, 64, align::no> little_float64_t;
typedef endian_arithmetic<order::native, float, 32, align::no> native_float32_t;
typedef endian_arithmetic<order::native, double, 64, align::no> native_float64_t;
//---------------------------------- end synopsis ------------------------------------//
template <BOOST_SCOPED_ENUM(order) Order, class T, std::size_t n_bits,
BOOST_SCOPED_ENUM(align) Align>
class endian_arithmetic
{
private:
typedef endian_buffer<Order, T, n_bits, Align> buffer_type;
#ifdef BOOST_ENDIAN_NO_CTORS
public:
#else
private:
#endif
buffer_type buf_;
public:
typedef T value_type;
#ifndef BOOST_ENDIAN_NO_CTORS
endian_arithmetic() BOOST_ENDIAN_DEFAULT_CONSTRUCT
BOOST_ENDIAN_EXPLICIT_OPT endian_arithmetic( T val ) BOOST_NOEXCEPT: buf_( val )
{
}
#endif
endian_arithmetic& operator=( T val ) BOOST_NOEXCEPT
{
buf_ = val;
return *this;
}
value_type value() const BOOST_NOEXCEPT
{
return buf_.value();
}
unsigned char const * data() const BOOST_NOEXCEPT
{
return buf_.data();
}
unsigned char * data() BOOST_NOEXCEPT
{
return buf_.data();
}
operator value_type() const BOOST_NOEXCEPT
{
return this->value();
}
operator buffer_type& () BOOST_NOEXCEPT
{
return buf_;
}
operator buffer_type const& () BOOST_NOEXCEPT
{
return buf_;
}
// operators
T operator+() const BOOST_NOEXCEPT
{
return this->value();
}
endian_arithmetic& operator+=( T y ) BOOST_NOEXCEPT
{
*this = static_cast<T>( this->value() + y );
return *this;
}
endian_arithmetic& operator-=( T y ) BOOST_NOEXCEPT
{
*this = static_cast<T>( this->value() - y );
return *this;
}
endian_arithmetic& operator*=( T y ) BOOST_NOEXCEPT
{
*this = static_cast<T>( this->value() * y );
return *this;
}
endian_arithmetic& operator/=( T y ) BOOST_NOEXCEPT
{
*this = static_cast<T>( this->value() / y );
return *this;
}
endian_arithmetic& operator%=( T y ) BOOST_NOEXCEPT
{
*this = static_cast<T>( this->value() % y );
return *this;
}
endian_arithmetic& operator&=( T y ) BOOST_NOEXCEPT
{
*this = static_cast<T>( this->value() & y );
return *this;
}
endian_arithmetic& operator|=( T y ) BOOST_NOEXCEPT
{
*this = static_cast<T>( this->value() | y );
return *this;
}
endian_arithmetic& operator^=( T y ) BOOST_NOEXCEPT
{
*this = static_cast<T>( this->value() ^ y );
return *this;
}
endian_arithmetic& operator<<=( T y ) BOOST_NOEXCEPT
{
*this = static_cast<T>( this->value() << y );
return *this;
}
endian_arithmetic& operator>>=( T y ) BOOST_NOEXCEPT
{
*this = static_cast<T>( this->value() >> y );
return *this;
}
endian_arithmetic& operator++() BOOST_NOEXCEPT
{
*this += 1;
return *this;
}
endian_arithmetic& operator--() BOOST_NOEXCEPT
{
*this -= 1;
return *this;
}
endian_arithmetic operator++(int) BOOST_NOEXCEPT
{
endian_arithmetic tmp( *this );
*this += 1;
return tmp;
}
endian_arithmetic operator--(int) BOOST_NOEXCEPT
{
endian_arithmetic tmp( *this );
*this -= 1;
return tmp;
}
template<class Ch, class Tr>
friend std::basic_ostream<Ch, Tr>&
operator<<( std::basic_ostream<Ch, Tr>& os, endian_arithmetic const& x )
{
return os << x.value();
}
template<class Ch, class Tr>
friend std::basic_istream<Ch, Tr>&
operator>>( std::basic_istream<Ch, Tr>& is, endian_arithmetic& x )
{
T i;
if( is >> i )
{
x = i;
}
return is;
}
};
} // namespace endian
} // namespace boost
#if defined(BOOST_BORLANDC) || defined(BOOST_CODEGEARC)
# pragma pack(pop)
#endif
#if defined(_MSC_VER)
# pragma warning(pop)
#endif
#endif // BOOST_ENDIAN_ARITHMETIC_HPP

View File

@@ -0,0 +1,380 @@
// boost/endian/buffers.hpp ----------------------------------------------------------//
// (C) Copyright Darin Adler 2000
// (C) Copyright Beman Dawes 2006, 2009, 2014
// (C) Copyright Peter Dimov 2019
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// See library home page at http://www.boost.org/libs/endian
//--------------------------------------------------------------------------------------//
// Original design developed by Darin Adler based on classes developed by Mark
// Borgerding. Four original class templates were combined into a single endian
// class template by Beman Dawes, who also added the unrolled_byte_loops sign
// partial specialization to correctly extend the sign when cover integer size
// differs from endian representation size.
// TODO: When a compiler supporting constexpr becomes available, try possible uses.
#ifndef BOOST_ENDIAN_BUFFERS_HPP
#define BOOST_ENDIAN_BUFFERS_HPP
#if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable: 4127) // conditional expression is constant
#endif
#include <boost/endian/detail/endian_store.hpp>
#include <boost/endian/detail/endian_load.hpp>
#include <boost/core/scoped_enum.hpp>
#include <boost/static_assert.hpp>
#include <boost/cstdint.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#include <iosfwd>
#include <climits>
#include <cstring>
#if defined(BOOST_BORLANDC) || defined(BOOST_CODEGEARC)
# pragma pack(push, 1)
#endif
# if CHAR_BIT != 8
# error Platforms with CHAR_BIT != 8 are not supported
# endif
# ifdef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
# define BOOST_ENDIAN_DEFAULT_CONSTRUCT {} // C++03
# else
# define BOOST_ENDIAN_DEFAULT_CONSTRUCT = default; // C++0x
# endif
// g++ pre-4.6 does not support unrestricted unions, but we have no Config macro for that
# if (defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) || BOOST_WORKAROUND(BOOST_GCC, < 40600)) && defined(BOOST_ENDIAN_FORCE_PODNESS)
# define BOOST_ENDIAN_NO_CTORS
# endif
//---------------------------------- synopsis ----------------------------------------//
namespace boost
{
namespace endian
{
BOOST_SCOPED_ENUM_START(align)
{no, yes
# ifdef BOOST_ENDIAN_DEPRECATED_NAMES
, unaligned = no, aligned = yes
# endif
}; BOOST_SCOPED_ENUM_END
template <BOOST_SCOPED_ENUM(order) Order, class T, std::size_t n_bits,
BOOST_SCOPED_ENUM(align) A = align::no>
class endian_buffer;
// aligned big endian signed integer buffers
typedef endian_buffer<order::big, int8_t, 8, align::yes> big_int8_buf_at;
typedef endian_buffer<order::big, int16_t, 16, align::yes> big_int16_buf_at;
typedef endian_buffer<order::big, int32_t, 32, align::yes> big_int32_buf_at;
typedef endian_buffer<order::big, int64_t, 64, align::yes> big_int64_buf_at;
// aligned big endian unsigned integer buffers
typedef endian_buffer<order::big, uint8_t, 8, align::yes> big_uint8_buf_at;
typedef endian_buffer<order::big, uint16_t, 16, align::yes> big_uint16_buf_at;
typedef endian_buffer<order::big, uint32_t, 32, align::yes> big_uint32_buf_at;
typedef endian_buffer<order::big, uint64_t, 64, align::yes> big_uint64_buf_at;
// aligned little endian signed integer buffers
typedef endian_buffer<order::little, int8_t, 8, align::yes> little_int8_buf_at;
typedef endian_buffer<order::little, int16_t, 16, align::yes> little_int16_buf_at;
typedef endian_buffer<order::little, int32_t, 32, align::yes> little_int32_buf_at;
typedef endian_buffer<order::little, int64_t, 64, align::yes> little_int64_buf_at;
// aligned little endian unsigned integer buffers
typedef endian_buffer<order::little, uint8_t, 8, align::yes> little_uint8_buf_at;
typedef endian_buffer<order::little, uint16_t, 16, align::yes> little_uint16_buf_at;
typedef endian_buffer<order::little, uint32_t, 32, align::yes> little_uint32_buf_at;
typedef endian_buffer<order::little, uint64_t, 64, align::yes> little_uint64_buf_at;
// aligned floating point buffers
typedef endian_buffer<order::big, float, 32, align::yes> big_float32_buf_at;
typedef endian_buffer<order::big, double, 64, align::yes> big_float64_buf_at;
typedef endian_buffer<order::little, float, 32, align::yes> little_float32_buf_at;
typedef endian_buffer<order::little, double, 64, align::yes> little_float64_buf_at;
// aligned native endian typedefs are not provided because
// <cstdint> types are superior for this use case
// unaligned big endian signed integer buffers
typedef endian_buffer<order::big, int_least8_t, 8> big_int8_buf_t;
typedef endian_buffer<order::big, int_least16_t, 16> big_int16_buf_t;
typedef endian_buffer<order::big, int_least32_t, 24> big_int24_buf_t;
typedef endian_buffer<order::big, int_least32_t, 32> big_int32_buf_t;
typedef endian_buffer<order::big, int_least64_t, 40> big_int40_buf_t;
typedef endian_buffer<order::big, int_least64_t, 48> big_int48_buf_t;
typedef endian_buffer<order::big, int_least64_t, 56> big_int56_buf_t;
typedef endian_buffer<order::big, int_least64_t, 64> big_int64_buf_t;
// unaligned big endian unsigned integer buffers
typedef endian_buffer<order::big, uint_least8_t, 8> big_uint8_buf_t;
typedef endian_buffer<order::big, uint_least16_t, 16> big_uint16_buf_t;
typedef endian_buffer<order::big, uint_least32_t, 24> big_uint24_buf_t;
typedef endian_buffer<order::big, uint_least32_t, 32> big_uint32_buf_t;
typedef endian_buffer<order::big, uint_least64_t, 40> big_uint40_buf_t;
typedef endian_buffer<order::big, uint_least64_t, 48> big_uint48_buf_t;
typedef endian_buffer<order::big, uint_least64_t, 56> big_uint56_buf_t;
typedef endian_buffer<order::big, uint_least64_t, 64> big_uint64_buf_t;
// unaligned little endian signed integer buffers
typedef endian_buffer<order::little, int_least8_t, 8> little_int8_buf_t;
typedef endian_buffer<order::little, int_least16_t, 16> little_int16_buf_t;
typedef endian_buffer<order::little, int_least32_t, 24> little_int24_buf_t;
typedef endian_buffer<order::little, int_least32_t, 32> little_int32_buf_t;
typedef endian_buffer<order::little, int_least64_t, 40> little_int40_buf_t;
typedef endian_buffer<order::little, int_least64_t, 48> little_int48_buf_t;
typedef endian_buffer<order::little, int_least64_t, 56> little_int56_buf_t;
typedef endian_buffer<order::little, int_least64_t, 64> little_int64_buf_t;
// unaligned little endian unsigned integer buffers
typedef endian_buffer<order::little, uint_least8_t, 8> little_uint8_buf_t;
typedef endian_buffer<order::little, uint_least16_t, 16> little_uint16_buf_t;
typedef endian_buffer<order::little, uint_least32_t, 24> little_uint24_buf_t;
typedef endian_buffer<order::little, uint_least32_t, 32> little_uint32_buf_t;
typedef endian_buffer<order::little, uint_least64_t, 40> little_uint40_buf_t;
typedef endian_buffer<order::little, uint_least64_t, 48> little_uint48_buf_t;
typedef endian_buffer<order::little, uint_least64_t, 56> little_uint56_buf_t;
typedef endian_buffer<order::little, uint_least64_t, 64> little_uint64_buf_t;
// unaligned native endian signed integer buffers
typedef endian_buffer<order::native, int_least8_t, 8> native_int8_buf_t;
typedef endian_buffer<order::native, int_least16_t, 16> native_int16_buf_t;
typedef endian_buffer<order::native, int_least32_t, 24> native_int24_buf_t;
typedef endian_buffer<order::native, int_least32_t, 32> native_int32_buf_t;
typedef endian_buffer<order::native, int_least64_t, 40> native_int40_buf_t;
typedef endian_buffer<order::native, int_least64_t, 48> native_int48_buf_t;
typedef endian_buffer<order::native, int_least64_t, 56> native_int56_buf_t;
typedef endian_buffer<order::native, int_least64_t, 64> native_int64_buf_t;
// unaligned native endian unsigned integer buffers
typedef endian_buffer<order::native, uint_least8_t, 8> native_uint8_buf_t;
typedef endian_buffer<order::native, uint_least16_t, 16> native_uint16_buf_t;
typedef endian_buffer<order::native, uint_least32_t, 24> native_uint24_buf_t;
typedef endian_buffer<order::native, uint_least32_t, 32> native_uint32_buf_t;
typedef endian_buffer<order::native, uint_least64_t, 40> native_uint40_buf_t;
typedef endian_buffer<order::native, uint_least64_t, 48> native_uint48_buf_t;
typedef endian_buffer<order::native, uint_least64_t, 56> native_uint56_buf_t;
typedef endian_buffer<order::native, uint_least64_t, 64> native_uint64_buf_t;
// unaligned floating point buffers
typedef endian_buffer<order::big, float, 32, align::no> big_float32_buf_t;
typedef endian_buffer<order::big, double, 64, align::no> big_float64_buf_t;
typedef endian_buffer<order::little, float, 32, align::no> little_float32_buf_t;
typedef endian_buffer<order::little, double, 64, align::no> little_float64_buf_t;
typedef endian_buffer<order::native, float, 32, align::no> native_float32_buf_t;
typedef endian_buffer<order::native, double, 64, align::no> native_float64_buf_t;
// Stream inserter
template <class charT, class traits, BOOST_SCOPED_ENUM(order) Order, class T,
std::size_t n_bits, BOOST_SCOPED_ENUM(align) A>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os,
const endian_buffer<Order, T, n_bits, A>& x)
{
return os << x.value();
}
// Stream extractor
template <class charT, class traits, BOOST_SCOPED_ENUM(order) Order, class T,
std::size_t n_bits, BOOST_SCOPED_ENUM(align) A>
std::basic_istream<charT, traits>&
operator>>(std::basic_istream<charT, traits>& is,
endian_buffer<Order, T, n_bits, A>& x)
{
T i;
if (is >> i)
x = i;
return is;
}
//---------------------------------- end synopsis ------------------------------------//
// endian_buffer class template specializations --------------------------------------//
// Specializations that represent unaligned bytes.
// Taking an integer type as a parameter provides a nice way to pass both
// the size and signedness of the desired integer and get the appropriate
// corresponding integer type for the interface.
// Q: Should endian_buffer supply "value_type operator value_type() const noexcept"?
// A: No. The rationale for endian_buffers is to prevent high-cost hidden
// conversions. If an implicit conversion operator is supplied, hidden conversions
// can occur.
// unaligned endian_buffer specialization
template< BOOST_SCOPED_ENUM(order) Order, class T, std::size_t n_bits >
class endian_buffer<Order, T, n_bits, align::no>
{
#ifdef BOOST_ENDIAN_NO_CTORS
public:
#endif
BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
unsigned char value_[ n_bits / 8 ];
public:
typedef T value_type;
#ifndef BOOST_ENDIAN_NO_CTORS
endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT
explicit endian_buffer( T val ) BOOST_NOEXCEPT
{
boost::endian::endian_store<T, n_bits / 8, Order>( value_, val );
}
#endif
endian_buffer& operator=( T val ) BOOST_NOEXCEPT
{
boost::endian::endian_store<T, n_bits / 8, Order>( value_, val );
return *this;
}
value_type value() const BOOST_NOEXCEPT
{
return boost::endian::endian_load<T, n_bits / 8, Order>( value_ );
}
unsigned char const * data() const BOOST_NOEXCEPT
{
return value_;
}
unsigned char * data() BOOST_NOEXCEPT
{
return value_;
}
};
// aligned specializations; only n_bits == 16/32/64 supported
// aligned endian_buffer specialization
template< BOOST_SCOPED_ENUM(order) Order, class T, std::size_t n_bits >
class endian_buffer<Order, T, n_bits, align::yes>
{
private:
BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 );
union
{
unsigned char value_[ n_bits / 8 ];
T align_;
};
public:
typedef T value_type;
#ifndef BOOST_ENDIAN_NO_CTORS
endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT
explicit endian_buffer( T val ) BOOST_NOEXCEPT
{
boost::endian::endian_store<T, n_bits / 8, Order>( value_, val );
}
#endif
endian_buffer& operator=( T val ) BOOST_NOEXCEPT
{
boost::endian::endian_store<T, n_bits / 8, Order>( value_, val );
return *this;
}
value_type value() const BOOST_NOEXCEPT
{
return boost::endian::endian_load<T, n_bits / 8, Order>( value_ );
}
unsigned char const * data() const BOOST_NOEXCEPT
{
return value_;
}
unsigned char * data() BOOST_NOEXCEPT
{
return value_;
}
};
// aligned native endian_buffer specialization
template< class T, std::size_t n_bits >
class endian_buffer<order::native, T, n_bits, align::yes>
{
private:
BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 );
T value_;
public:
typedef T value_type;
#ifndef BOOST_ENDIAN_NO_CTORS
endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT
explicit endian_buffer( T val ) BOOST_NOEXCEPT: value_( val )
{
}
#endif
endian_buffer& operator=( T val ) BOOST_NOEXCEPT
{
value_ = val;
return *this;
}
value_type value() const BOOST_NOEXCEPT
{
return value_;
}
unsigned char const * data() const BOOST_NOEXCEPT
{
return reinterpret_cast< unsigned char const* >( &value_ );
}
unsigned char * data() BOOST_NOEXCEPT
{
return reinterpret_cast< unsigned char* >( &value_ );
}
};
} // namespace endian
} // namespace boost
#if defined(BOOST_BORLANDC) || defined(BOOST_CODEGEARC)
# pragma pack(pop)
#endif
#if defined(_MSC_VER)
# pragma warning(pop)
#endif
#endif // BOOST_ENDIAN_BUFFERS_HPP

View File

@@ -0,0 +1,590 @@
// boost/endian/conversion.hpp -------------------------------------------------------//
// Copyright Beman Dawes 2010, 2011, 2014
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#ifndef BOOST_ENDIAN_CONVERSION_HPP
#define BOOST_ENDIAN_CONVERSION_HPP
#include <boost/endian/detail/endian_reverse.hpp>
#include <boost/endian/detail/endian_load.hpp>
#include <boost/endian/detail/endian_store.hpp>
#include <boost/endian/detail/order.hpp>
#include <boost/type_traits/is_class.hpp>
#include <boost/type_traits/is_array.hpp>
#include <boost/type_traits/integral_constant.hpp>
#include <boost/static_assert.hpp>
#include <boost/cstdint.hpp>
#include <boost/config.hpp>
//------------------------------------- synopsis ---------------------------------------//
namespace boost
{
namespace endian
{
//--------------------------------------------------------------------------------------//
// //
// return-by-value interfaces //
// suggested by Phil Endecott //
// //
// user-defined types (UDTs) //
// //
// All return-by-value conversion function templates are required to be implemented in //
// terms of an unqualified call to "endian_reverse(x)", a function returning the //
// value of x with endianness reversed. This provides a customization point for any //
// UDT that provides a "endian_reverse" free-function meeting the requirements. //
// It must be defined in the same namespace as the UDT itself so that it will be found //
// by argument dependent lookup (ADL). //
// //
//--------------------------------------------------------------------------------------//
// reverse byte order
// requires T to be a non-bool integral type
// in detail/endian_reverse.hpp
//
// template<class T> inline BOOST_CONSTEXPR T endian_reverse( T x ) BOOST_NOEXCEPT;
// reverse byte order unless native endianness is big
template <class EndianReversible >
inline BOOST_CONSTEXPR EndianReversible big_to_native(EndianReversible x) BOOST_NOEXCEPT;
// Returns: x if native endian order is big, otherwise endian_reverse(x)
template <class EndianReversible >
inline BOOST_CONSTEXPR EndianReversible native_to_big(EndianReversible x) BOOST_NOEXCEPT;
// Returns: x if native endian order is big, otherwise endian_reverse(x)
// reverse byte order unless native endianness is little
template <class EndianReversible >
inline BOOST_CONSTEXPR EndianReversible little_to_native(EndianReversible x) BOOST_NOEXCEPT;
// Returns: x if native endian order is little, otherwise endian_reverse(x)
template <class EndianReversible >
inline BOOST_CONSTEXPR EndianReversible native_to_little(EndianReversible x) BOOST_NOEXCEPT;
// Returns: x if native endian order is little, otherwise endian_reverse(x)
// generic conditional reverse byte order
template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To,
class EndianReversible>
inline BOOST_CONSTEXPR EndianReversible conditional_reverse(EndianReversible from) BOOST_NOEXCEPT;
// Returns: If From == To have different values, from.
// Otherwise endian_reverse(from).
// Remarks: The From == To test, and as a consequence which form the return takes, is
// is determined at compile time.
// runtime conditional reverse byte order
template <class EndianReversible >
inline BOOST_CONSTEXPR EndianReversible conditional_reverse(EndianReversible from,
BOOST_SCOPED_ENUM(order) from_order, BOOST_SCOPED_ENUM(order) to_order)
BOOST_NOEXCEPT;
// Returns: from_order == to_order ? from : endian_reverse(from).
//------------------------------------------------------------------------------------//
// Q: What happened to bswap, htobe, and the other synonym functions based on names
// popularized by BSD, OS X, and Linux?
// A: Turned out these may be implemented as macros on some systems. Ditto POSIX names
// for such functionality. Since macros would cause endless problems with functions
// of the same names, and these functions are just synonyms anyhow, they have been
// removed.
//------------------------------------------------------------------------------------//
// //
// reverse in place interfaces //
// //
// user-defined types (UDTs) //
// //
// All reverse in place function templates are required to be implemented in terms //
// of an unqualified call to "endian_reverse_inplace(x)", a function reversing //
// the endianness of x, which is a non-const reference. This provides a //
// customization point for any UDT that provides a "reverse_inplace" free-function //
// meeting the requirements. The free-function must be declared in the same //
// namespace as the UDT itself so that it will be found by argument-dependent //
// lookup (ADL). //
// //
//------------------------------------------------------------------------------------//
// reverse in place
// in detail/endian_reverse.hpp
//
// template <class EndianReversible>
// inline void endian_reverse_inplace(EndianReversible& x) BOOST_NOEXCEPT;
//
// Effects: x = endian_reverse(x)
// reverse in place unless native endianness is big
template <class EndianReversibleInplace>
inline void big_to_native_inplace(EndianReversibleInplace& x) BOOST_NOEXCEPT;
// Effects: none if native byte-order is big, otherwise endian_reverse_inplace(x)
template <class EndianReversibleInplace>
inline void native_to_big_inplace(EndianReversibleInplace& x) BOOST_NOEXCEPT;
// Effects: none if native byte-order is big, otherwise endian_reverse_inplace(x)
// reverse in place unless native endianness is little
template <class EndianReversibleInplace>
inline void little_to_native_inplace(EndianReversibleInplace& x) BOOST_NOEXCEPT;
// Effects: none if native byte-order is little, otherwise endian_reverse_inplace(x);
template <class EndianReversibleInplace>
inline void native_to_little_inplace(EndianReversibleInplace& x) BOOST_NOEXCEPT;
// Effects: none if native byte-order is little, otherwise endian_reverse_inplace(x);
// generic conditional reverse in place
template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To,
class EndianReversibleInplace>
inline void conditional_reverse_inplace(EndianReversibleInplace& x) BOOST_NOEXCEPT;
// runtime reverse in place
template <class EndianReversibleInplace>
inline void conditional_reverse_inplace(EndianReversibleInplace& x,
BOOST_SCOPED_ENUM(order) from_order, BOOST_SCOPED_ENUM(order) to_order)
BOOST_NOEXCEPT;
//----------------------------------- end synopsis -------------------------------------//
template <class EndianReversible>
inline BOOST_CONSTEXPR EndianReversible big_to_native( EndianReversible x ) BOOST_NOEXCEPT
{
return boost::endian::conditional_reverse<order::big, order::native>( x );
}
template <class EndianReversible>
inline BOOST_CONSTEXPR EndianReversible native_to_big( EndianReversible x ) BOOST_NOEXCEPT
{
return boost::endian::conditional_reverse<order::native, order::big>( x );
}
template <class EndianReversible>
inline BOOST_CONSTEXPR EndianReversible little_to_native( EndianReversible x ) BOOST_NOEXCEPT
{
return boost::endian::conditional_reverse<order::little, order::native>( x );
}
template <class EndianReversible>
inline BOOST_CONSTEXPR EndianReversible native_to_little( EndianReversible x ) BOOST_NOEXCEPT
{
return boost::endian::conditional_reverse<order::native, order::little>( x );
}
namespace detail
{
template<class EndianReversible>
inline BOOST_CONSTEXPR EndianReversible conditional_reverse_impl( EndianReversible x, boost::true_type ) BOOST_NOEXCEPT
{
return x;
}
template<class EndianReversible>
inline BOOST_CONSTEXPR EndianReversible conditional_reverse_impl( EndianReversible x, boost::false_type ) BOOST_NOEXCEPT
{
return endian_reverse( x );
}
} // namespace detail
// generic conditional reverse
template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To, class EndianReversible>
inline BOOST_CONSTEXPR EndianReversible conditional_reverse( EndianReversible x ) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT( boost::is_class<EndianReversible>::value || detail::is_endian_reversible<EndianReversible>::value );
return detail::conditional_reverse_impl( x, boost::integral_constant<bool, From == To>() );
}
// runtime conditional reverse
template <class EndianReversible>
inline BOOST_CONSTEXPR EndianReversible conditional_reverse( EndianReversible x,
BOOST_SCOPED_ENUM(order) from_order, BOOST_SCOPED_ENUM(order) to_order ) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT( boost::is_class<EndianReversible>::value || detail::is_endian_reversible<EndianReversible>::value );
return from_order == to_order? x: endian_reverse( x );
}
//--------------------------------------------------------------------------------------//
// reverse-in-place implementation //
//--------------------------------------------------------------------------------------//
template <class EndianReversibleInplace>
inline void big_to_native_inplace( EndianReversibleInplace& x ) BOOST_NOEXCEPT
{
boost::endian::conditional_reverse_inplace<order::big, order::native>( x );
}
template <class EndianReversibleInplace>
inline void native_to_big_inplace( EndianReversibleInplace& x ) BOOST_NOEXCEPT
{
boost::endian::conditional_reverse_inplace<order::native, order::big>( x );
}
template <class EndianReversibleInplace>
inline void little_to_native_inplace( EndianReversibleInplace& x ) BOOST_NOEXCEPT
{
boost::endian::conditional_reverse_inplace<order::little, order::native>( x );
}
template <class EndianReversibleInplace>
inline void native_to_little_inplace( EndianReversibleInplace& x ) BOOST_NOEXCEPT
{
boost::endian::conditional_reverse_inplace<order::native, order::little>( x );
}
namespace detail
{
template<class EndianReversibleInplace>
inline void conditional_reverse_inplace_impl( EndianReversibleInplace&, boost::true_type ) BOOST_NOEXCEPT
{
}
template<class EndianReversibleInplace>
inline void conditional_reverse_inplace_impl( EndianReversibleInplace& x, boost::false_type ) BOOST_NOEXCEPT
{
endian_reverse_inplace( x );
}
} // namespace detail
// generic conditional reverse in place
template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To, class EndianReversibleInplace>
inline void conditional_reverse_inplace( EndianReversibleInplace& x ) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT(
boost::is_class<EndianReversibleInplace>::value ||
boost::is_array<EndianReversibleInplace>::value ||
detail::is_endian_reversible_inplace<EndianReversibleInplace>::value );
detail::conditional_reverse_inplace_impl( x, boost::integral_constant<bool, From == To>() );
}
// runtime reverse in place
template <class EndianReversibleInplace>
inline void conditional_reverse_inplace( EndianReversibleInplace& x,
BOOST_SCOPED_ENUM(order) from_order, BOOST_SCOPED_ENUM(order) to_order ) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT(
boost::is_class<EndianReversibleInplace>::value ||
boost::is_array<EndianReversibleInplace>::value ||
detail::is_endian_reversible_inplace<EndianReversibleInplace>::value );
if( from_order != to_order )
{
endian_reverse_inplace( 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 );
}
// store 16
inline void store_little_s16( unsigned char * p, boost::int16_t v )
{
boost::endian::endian_store<boost::int16_t, 2, order::little>( p, v );
}
inline void store_little_u16( unsigned char * p, boost::uint16_t v )
{
boost::endian::endian_store<boost::uint16_t, 2, order::little>( p, v );
}
inline void store_big_s16( unsigned char * p, boost::int16_t v )
{
boost::endian::endian_store<boost::int16_t, 2, order::big>( p, v );
}
inline void store_big_u16( unsigned char * p, boost::uint16_t v )
{
boost::endian::endian_store<boost::uint16_t, 2, order::big>( p, v );
}
// store 24
inline void store_little_s24( unsigned char * p, boost::int32_t v )
{
boost::endian::endian_store<boost::int32_t, 3, order::little>( p, v );
}
inline void store_little_u24( unsigned char * p, boost::uint32_t v )
{
boost::endian::endian_store<boost::uint32_t, 3, order::little>( p, v );
}
inline void store_big_s24( unsigned char * p, boost::int32_t v )
{
boost::endian::endian_store<boost::int32_t, 3, order::big>( p, v );
}
inline void store_big_u24( unsigned char * p, boost::uint32_t v )
{
boost::endian::endian_store<boost::uint32_t, 3, order::big>( p, v );
}
// store 32
inline void store_little_s32( unsigned char * p, boost::int32_t v )
{
boost::endian::endian_store<boost::int32_t, 4, order::little>( p, v );
}
inline void store_little_u32( unsigned char * p, boost::uint32_t v )
{
boost::endian::endian_store<boost::uint32_t, 4, order::little>( p, v );
}
inline void store_big_s32( unsigned char * p, boost::int32_t v )
{
boost::endian::endian_store<boost::int32_t, 4, order::big>( p, v );
}
inline void store_big_u32( unsigned char * p, boost::uint32_t v )
{
boost::endian::endian_store<boost::uint32_t, 4, order::big>( p, v );
}
// store 40
inline void store_little_s40( unsigned char * p, boost::int64_t v )
{
boost::endian::endian_store<boost::int64_t, 5, order::little>( p, v );
}
inline void store_little_u40( unsigned char * p, boost::uint64_t v )
{
boost::endian::endian_store<boost::uint64_t, 5, order::little>( p, v );
}
inline void store_big_s40( unsigned char * p, boost::int64_t v )
{
boost::endian::endian_store<boost::int64_t, 5, order::big>( p, v );
}
inline void store_big_u40( unsigned char * p, boost::uint64_t v )
{
boost::endian::endian_store<boost::uint64_t, 5, order::big>( p, v );
}
// store 48
inline void store_little_s48( unsigned char * p, boost::int64_t v )
{
boost::endian::endian_store<boost::int64_t, 6, order::little>( p, v );
}
inline void store_little_u48( unsigned char * p, boost::uint64_t v )
{
boost::endian::endian_store<boost::uint64_t, 6, order::little>( p, v );
}
inline void store_big_s48( unsigned char * p, boost::int64_t v )
{
boost::endian::endian_store<boost::int64_t, 6, order::big>( p, v );
}
inline void store_big_u48( unsigned char * p, boost::uint64_t v )
{
boost::endian::endian_store<boost::uint64_t, 6, order::big>( p, v );
}
// store 56
inline void store_little_s56( unsigned char * p, boost::int64_t v )
{
boost::endian::endian_store<boost::int64_t, 7, order::little>( p, v );
}
inline void store_little_u56( unsigned char * p, boost::uint64_t v )
{
boost::endian::endian_store<boost::uint64_t, 7, order::little>( p, v );
}
inline void store_big_s56( unsigned char * p, boost::int64_t v )
{
boost::endian::endian_store<boost::int64_t, 7, order::big>( p, v );
}
inline void store_big_u56( unsigned char * p, boost::uint64_t v )
{
boost::endian::endian_store<boost::uint64_t, 7, order::big>( p, v );
}
// store 64
inline void store_little_s64( unsigned char * p, boost::int64_t v )
{
boost::endian::endian_store<boost::int64_t, 8, order::little>( p, v );
}
inline void store_little_u64( unsigned char * p, boost::uint64_t v )
{
boost::endian::endian_store<boost::uint64_t, 8, order::little>( p, v );
}
inline void store_big_s64( unsigned char * p, boost::int64_t v )
{
boost::endian::endian_store<boost::int64_t, 8, order::big>( p, v );
}
inline void store_big_u64( unsigned char * p, boost::uint64_t v )
{
boost::endian::endian_store<boost::uint64_t, 8, order::big>( p, v );
}
} // namespace endian
} // namespace boost
#endif // BOOST_ENDIAN_CONVERSION_HPP

View File

@@ -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

View File

@@ -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

View 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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View 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

View File

@@ -0,0 +1,118 @@
// boost/endian/endian.hpp -----------------------------------------------------------//
// Copyright Beman Dawes 2015
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// See library home page at http://www.boost.org/libs/endian
#ifndef BOOST_ENDIAN_ENDIAN_HPP
#define BOOST_ENDIAN_ENDIAN_HPP
#ifndef BOOST_ENDIAN_DEPRECATED_NAMES
# error "<boost/endian/endian.hpp> is deprecated. Define BOOST_ENDIAN_DEPRECATED_NAMES to use."
#endif
#include <boost/config/header_deprecated.hpp>
BOOST_HEADER_DEPRECATED( "<boost/endian/arithmetic.hpp>" )
#include <boost/endian/arithmetic.hpp>
#include <boost/config.hpp>
namespace boost
{
namespace endian
{
typedef order endianness;
typedef align alignment;
# ifndef BOOST_NO_CXX11_TEMPLATE_ALIASES
template <BOOST_SCOPED_ENUM(order) Order, class T, std::size_t n_bits,
BOOST_SCOPED_ENUM(align) Align = align::no>
using endian = endian_arithmetic<Order, T, n_bits, Align>;
# endif
// unaligned big endian signed integer types
typedef endian_arithmetic< order::big, int_least8_t, 8 > big8_t;
typedef endian_arithmetic< order::big, int_least16_t, 16 > big16_t;
typedef endian_arithmetic< order::big, int_least32_t, 24 > big24_t;
typedef endian_arithmetic< order::big, int_least32_t, 32 > big32_t;
typedef endian_arithmetic< order::big, int_least64_t, 40 > big40_t;
typedef endian_arithmetic< order::big, int_least64_t, 48 > big48_t;
typedef endian_arithmetic< order::big, int_least64_t, 56 > big56_t;
typedef endian_arithmetic< order::big, int_least64_t, 64 > big64_t;
// unaligned big endian_arithmetic unsigned integer types
typedef endian_arithmetic< order::big, uint_least8_t, 8 > ubig8_t;
typedef endian_arithmetic< order::big, uint_least16_t, 16 > ubig16_t;
typedef endian_arithmetic< order::big, uint_least32_t, 24 > ubig24_t;
typedef endian_arithmetic< order::big, uint_least32_t, 32 > ubig32_t;
typedef endian_arithmetic< order::big, uint_least64_t, 40 > ubig40_t;
typedef endian_arithmetic< order::big, uint_least64_t, 48 > ubig48_t;
typedef endian_arithmetic< order::big, uint_least64_t, 56 > ubig56_t;
typedef endian_arithmetic< order::big, uint_least64_t, 64 > ubig64_t;
// unaligned little endian_arithmetic signed integer types
typedef endian_arithmetic< order::little, int_least8_t, 8 > little8_t;
typedef endian_arithmetic< order::little, int_least16_t, 16 > little16_t;
typedef endian_arithmetic< order::little, int_least32_t, 24 > little24_t;
typedef endian_arithmetic< order::little, int_least32_t, 32 > little32_t;
typedef endian_arithmetic< order::little, int_least64_t, 40 > little40_t;
typedef endian_arithmetic< order::little, int_least64_t, 48 > little48_t;
typedef endian_arithmetic< order::little, int_least64_t, 56 > little56_t;
typedef endian_arithmetic< order::little, int_least64_t, 64 > little64_t;
// unaligned little endian_arithmetic unsigned integer types
typedef endian_arithmetic< order::little, uint_least8_t, 8 > ulittle8_t;
typedef endian_arithmetic< order::little, uint_least16_t, 16 > ulittle16_t;
typedef endian_arithmetic< order::little, uint_least32_t, 24 > ulittle24_t;
typedef endian_arithmetic< order::little, uint_least32_t, 32 > ulittle32_t;
typedef endian_arithmetic< order::little, uint_least64_t, 40 > ulittle40_t;
typedef endian_arithmetic< order::little, uint_least64_t, 48 > ulittle48_t;
typedef endian_arithmetic< order::little, uint_least64_t, 56 > ulittle56_t;
typedef endian_arithmetic< order::little, uint_least64_t, 64 > ulittle64_t;
// unaligned native endian_arithmetic signed integer types
typedef endian_arithmetic< order::native, int_least8_t, 8 > native8_t;
typedef endian_arithmetic< order::native, int_least16_t, 16 > native16_t;
typedef endian_arithmetic< order::native, int_least32_t, 24 > native24_t;
typedef endian_arithmetic< order::native, int_least32_t, 32 > native32_t;
typedef endian_arithmetic< order::native, int_least64_t, 40 > native40_t;
typedef endian_arithmetic< order::native, int_least64_t, 48 > native48_t;
typedef endian_arithmetic< order::native, int_least64_t, 56 > native56_t;
typedef endian_arithmetic< order::native, int_least64_t, 64 > native64_t;
// unaligned native endian_arithmetic unsigned integer types
typedef endian_arithmetic< order::native, uint_least8_t, 8 > unative8_t;
typedef endian_arithmetic< order::native, uint_least16_t, 16 > unative16_t;
typedef endian_arithmetic< order::native, uint_least32_t, 24 > unative24_t;
typedef endian_arithmetic< order::native, uint_least32_t, 32 > unative32_t;
typedef endian_arithmetic< order::native, uint_least64_t, 40 > unative40_t;
typedef endian_arithmetic< order::native, uint_least64_t, 48 > unative48_t;
typedef endian_arithmetic< order::native, uint_least64_t, 56 > unative56_t;
typedef endian_arithmetic< order::native, uint_least64_t, 64 > unative64_t;
// aligned native endian_arithmetic typedefs are not provided because
// <cstdint> types are superior for this use case
typedef endian_arithmetic< order::big, int16_t, 16, align::yes > aligned_big16_t;
typedef endian_arithmetic< order::big, uint16_t, 16, align::yes > aligned_ubig16_t;
typedef endian_arithmetic< order::little, int16_t, 16, align::yes > aligned_little16_t;
typedef endian_arithmetic< order::little, uint16_t, 16, align::yes > aligned_ulittle16_t;
typedef endian_arithmetic< order::big, int32_t, 32, align::yes > aligned_big32_t;
typedef endian_arithmetic< order::big, uint32_t, 32, align::yes > aligned_ubig32_t;
typedef endian_arithmetic< order::little, int32_t, 32, align::yes > aligned_little32_t;
typedef endian_arithmetic< order::little, uint32_t, 32, align::yes > aligned_ulittle32_t;
typedef endian_arithmetic< order::big, int64_t, 64, align::yes > aligned_big64_t;
typedef endian_arithmetic< order::big, uint64_t, 64, align::yes > aligned_ubig64_t;
typedef endian_arithmetic< order::little, int64_t, 64, align::yes > aligned_little64_t;
typedef endian_arithmetic< order::little, uint64_t, 64, align::yes > aligned_ulittle64_t;
} // namespace endian
} // namespace boost
#endif //BOOST_ENDIAN_ENDIAN_HPP