diff --git a/boost/integer/endian.hpp b/boost/integer/endian.hpp deleted file mode 100644 index 47db4a8..0000000 --- a/boost/integer/endian.hpp +++ /dev/null @@ -1,431 +0,0 @@ -// Boost endian.hpp header file -------------------------------------------------------// - -// (C) Copyright Darin Adler 2000 -// (C) Copyright Beman Dawes 2006, 2009 - -// 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_HPP -#define BOOST_ENDIAN_HPP - -#ifdef BOOST_ENDIAN_LOG -# include -#endif - -#if defined(__BORLANDC__) || defined( __CODEGEARC__) -# pragma pack(push, 1) -#endif - -#include -#include -#define BOOST_MINIMAL_INTEGER_COVER_OPERATORS -#define BOOST_NO_IO_COVER_OPERATORS -#include -#undef BOOST_NO_IO_COVER_OPERATORS -#undef BOOST_MINIMAL_INTEGER_COVER_OPERATORS -#include -#include -#include -#include -#include -#include - -# if CHAR_BIT != 8 -# error Platforms with CHAR_BIT != 8 are not supported -# endif - -# ifdef BOOST_NO_DEFAULTED_FUNCTIONS -# define BOOST_ENDIAN_DEFAULT_CONSTRUCT {} // C++03 -# else -# define BOOST_ENDIAN_DEFAULT_CONSTRUCT = default; // C++0x -# endif - -# if defined(BOOST_NO_DEFAULTED_FUNCTIONS) && defined(BOOST_ENDIAN_FORCE_PODNESS) -# define BOOST_ENDIAN_NO_CTORS -# endif - - -namespace boost -{ - namespace detail - { - // Unrolled loops for loading and storing streams of bytes. - - template ::value > - struct unrolled_byte_loops - { - typedef unrolled_byte_loops next; - - static T load_big(const unsigned char* bytes) - { return *(bytes - 1) | (next::load_big(bytes - 1) << 8); } - static T load_little(const unsigned char* bytes) - { return *bytes | (next::load_little(bytes + 1) << 8); } - - static void store_big(char* bytes, T value) - { - *(bytes - 1) = static_cast(value); - next::store_big(bytes - 1, value >> 8); - } - static void store_little(char* bytes, T value) - { - *bytes = static_cast(value); - next::store_little(bytes + 1, value >> 8); - } - }; - - template - struct unrolled_byte_loops - { - static T load_big(const unsigned char* bytes) - { return *(bytes - 1); } - static T load_little(const unsigned char* bytes) - { return *bytes; } - static void store_big(char* bytes, T value) - { *(bytes - 1) = static_cast(value); } - static void store_little(char* bytes, T value) - { *bytes = static_cast(value); } - - }; - - template - struct unrolled_byte_loops - { - static T load_big(const unsigned char* bytes) - { return *reinterpret_cast(bytes - 1); } - static T load_little(const unsigned char* bytes) - { return *reinterpret_cast(bytes); } - static void store_big(char* bytes, T value) - { *(bytes - 1) = static_cast(value); } - static void store_little(char* bytes, T value) - { *bytes = static_cast(value); } - }; - - template - inline - T load_big_endian(const void* bytes) - { - return unrolled_byte_loops::load_big - (static_cast(bytes) + n_bytes); - } - - template - inline - T load_little_endian(const void* bytes) - { - return unrolled_byte_loops::load_little - (static_cast(bytes)); - } - - template - inline - void store_big_endian(void* bytes, T value) - { - unrolled_byte_loops::store_big - (static_cast(bytes) + n_bytes, value); - } - - template - inline - void store_little_endian(void* bytes, T value) - { - unrolled_byte_loops::store_little - (static_cast(bytes), value); - } - - } // namespace detail - - namespace integer - { - -# ifdef BOOST_ENDIAN_LOG - bool endian_log(true); -# endif - - - // endian class template and specializations ---------------------------------------// - - BOOST_SCOPED_ENUM_START(endianness) { big, little, native }; BOOST_SCOPED_ENUM_END - BOOST_SCOPED_ENUM_START(alignment) { unaligned, aligned }; BOOST_SCOPED_ENUM_END - - template - class endian; - - // 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. - - // unaligned big endian specialization - template - class endian< endianness::big, T, n_bits, alignment::unaligned > - : cover_operators< endian< endianness::big, T, n_bits >, T > - { - BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits ); - public: - typedef T value_type; -# ifndef BOOST_ENDIAN_NO_CTORS - endian() BOOST_ENDIAN_DEFAULT_CONSTRUCT - explicit endian(T val) - { -# ifdef BOOST_ENDIAN_LOG - if ( endian_log ) - std::clog << "big, unaligned, " << n_bits << "-bits, construct(" << val << ")\n"; -# endif - detail::store_big_endian(m_value, val); - } -# endif - endian & operator=(T val) { detail::store_big_endian(m_value, val); return *this; } - operator T() const - { -# ifdef BOOST_ENDIAN_LOG - if ( endian_log ) - std::clog << "big, unaligned, " << n_bits << "-bits, convert(" << detail::load_big_endian(m_value) << ")\n"; -# endif - return detail::load_big_endian(m_value); - } - const char* data() const { return m_value; } - private: - char m_value[n_bits/8]; - }; - - // unaligned little endian specialization - template - class endian< endianness::little, T, n_bits, alignment::unaligned > - : cover_operators< endian< endianness::little, T, n_bits >, T > - { - BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits ); - public: - typedef T value_type; -# ifndef BOOST_ENDIAN_NO_CTORS - endian() BOOST_ENDIAN_DEFAULT_CONSTRUCT - explicit endian(T val) - { -# ifdef BOOST_ENDIAN_LOG - if ( endian_log ) - std::clog << "little, unaligned, " << n_bits << "-bits, construct(" << val << ")\n"; -# endif - detail::store_little_endian(m_value, val); - } -# endif - endian & operator=(T val) { detail::store_little_endian(m_value, val); return *this; } - operator T() const - { -# ifdef BOOST_ENDIAN_LOG - if ( endian_log ) - std::clog << "little, unaligned, " << n_bits << "-bits, convert(" << detail::load_little_endian(m_value) << ")\n"; -# endif - return detail::load_little_endian(m_value); - } - const char* data() const { return m_value; } - private: - char m_value[n_bits/8]; - }; - - // unaligned native endian specialization - template - class endian< endianness::native, T, n_bits, alignment::unaligned > - : cover_operators< endian< endianness::native, T, n_bits >, T > - { - BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits ); - public: - typedef T value_type; -# ifndef BOOST_ENDIAN_NO_CTORS - endian() BOOST_ENDIAN_DEFAULT_CONSTRUCT -# ifdef BOOST_BIG_ENDIAN - explicit endian(T val) { detail::store_big_endian(m_value, val); } -# else - explicit endian(T val) { detail::store_little_endian(m_value, val); } -# endif -# endif -# ifdef BOOST_BIG_ENDIAN - endian & operator=(T val) { detail::store_big_endian(m_value, val); return *this; } - operator T() const { return detail::load_big_endian(m_value); } -# else - endian & operator=(T val) { detail::store_little_endian(m_value, val); return *this; } - operator T() const { return detail::load_little_endian(m_value); } -# endif - const char* data() const { return m_value; } - private: - char m_value[n_bits/8]; - }; - - // Specializations that mimic built-in integer types. - // These typically have the same alignment as the underlying types. - - // aligned big endian specialization - template - class endian< endianness::big, T, n_bits, alignment::aligned > - : cover_operators< endian< endianness::big, T, n_bits, alignment::aligned >, T > - { - BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits ); - BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 ); - public: - typedef T value_type; -# ifndef BOOST_ENDIAN_NO_CTORS - endian() BOOST_ENDIAN_DEFAULT_CONSTRUCT -# ifdef BOOST_BIG_ENDIAN - endian(T val) : m_value(val) { } -# else - explicit endian(T val) { detail::store_big_endian(&m_value, val); } -# endif -# endif -# ifdef BOOST_BIG_ENDIAN - endian & operator=(T val) { m_value = val); return *this; } - operator T() const { return m_value; } -# else - endian & operator=(T val) { detail::store_big_endian(&m_value, val); return *this; } - operator T() const { return detail::load_big_endian(&m_value); } -# endif - const char* data() const { return reinterpret_cast(&m_value); } - private: - T m_value; - }; - - // aligned little endian specialization - template - class endian< endianness::little, T, n_bits, alignment::aligned > - : cover_operators< endian< endianness::little, T, n_bits, alignment::aligned >, T > - { - BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits ); - BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 ); - public: - typedef T value_type; -# ifndef BOOST_ENDIAN_NO_CTORS - endian() BOOST_ENDIAN_DEFAULT_CONSTRUCT -# ifdef BOOST_LITTLE_ENDIAN - endian(T val) : m_value(val) { } -# else - explicit endian(T val) { detail::store_little_endian(&m_value, val); } -# endif -# endif -# ifdef BOOST_LITTLE_ENDIAN - endian & operator=(T val) { m_value = val; return *this; } - operator T() const { return m_value; } - #else - endian & operator=(T val) { detail::store_little_endian(&m_value, val); return *this; } - operator T() const { return detail::load_little_endian(&m_value); } - #endif - const char* data() const { return reinterpret_cast(&m_value); } - private: - T m_value; - }; - - // naming convention typedefs ------------------------------------------------------// - - // unaligned big endian signed integer types - typedef endian< endianness::big, int_least8_t, 8 > big8_t; - typedef endian< endianness::big, int_least16_t, 16 > big16_t; - typedef endian< endianness::big, int_least32_t, 24 > big24_t; - typedef endian< endianness::big, int_least32_t, 32 > big32_t; - typedef endian< endianness::big, int_least64_t, 40 > big40_t; - typedef endian< endianness::big, int_least64_t, 48 > big48_t; - typedef endian< endianness::big, int_least64_t, 56 > big56_t; - typedef endian< endianness::big, int_least64_t, 64 > big64_t; - - // unaligned big endian unsigned integer types - typedef endian< endianness::big, uint_least8_t, 8 > ubig8_t; - typedef endian< endianness::big, uint_least16_t, 16 > ubig16_t; - typedef endian< endianness::big, uint_least32_t, 24 > ubig24_t; - typedef endian< endianness::big, uint_least32_t, 32 > ubig32_t; - typedef endian< endianness::big, uint_least64_t, 40 > ubig40_t; - typedef endian< endianness::big, uint_least64_t, 48 > ubig48_t; - typedef endian< endianness::big, uint_least64_t, 56 > ubig56_t; - typedef endian< endianness::big, uint_least64_t, 64 > ubig64_t; - - // unaligned little endian signed integer types - typedef endian< endianness::little, int_least8_t, 8 > little8_t; - typedef endian< endianness::little, int_least16_t, 16 > little16_t; - typedef endian< endianness::little, int_least32_t, 24 > little24_t; - typedef endian< endianness::little, int_least32_t, 32 > little32_t; - typedef endian< endianness::little, int_least64_t, 40 > little40_t; - typedef endian< endianness::little, int_least64_t, 48 > little48_t; - typedef endian< endianness::little, int_least64_t, 56 > little56_t; - typedef endian< endianness::little, int_least64_t, 64 > little64_t; - - // unaligned little endian unsigned integer types - typedef endian< endianness::little, uint_least8_t, 8 > ulittle8_t; - typedef endian< endianness::little, uint_least16_t, 16 > ulittle16_t; - typedef endian< endianness::little, uint_least32_t, 24 > ulittle24_t; - typedef endian< endianness::little, uint_least32_t, 32 > ulittle32_t; - typedef endian< endianness::little, uint_least64_t, 40 > ulittle40_t; - typedef endian< endianness::little, uint_least64_t, 48 > ulittle48_t; - typedef endian< endianness::little, uint_least64_t, 56 > ulittle56_t; - typedef endian< endianness::little, uint_least64_t, 64 > ulittle64_t; - - // unaligned native endian signed integer types - typedef endian< endianness::native, int_least8_t, 8 > native8_t; - typedef endian< endianness::native, int_least16_t, 16 > native16_t; - typedef endian< endianness::native, int_least32_t, 24 > native24_t; - typedef endian< endianness::native, int_least32_t, 32 > native32_t; - typedef endian< endianness::native, int_least64_t, 40 > native40_t; - typedef endian< endianness::native, int_least64_t, 48 > native48_t; - typedef endian< endianness::native, int_least64_t, 56 > native56_t; - typedef endian< endianness::native, int_least64_t, 64 > native64_t; - - // unaligned native endian unsigned integer types - typedef endian< endianness::native, uint_least8_t, 8 > unative8_t; - typedef endian< endianness::native, uint_least16_t, 16 > unative16_t; - typedef endian< endianness::native, uint_least32_t, 24 > unative24_t; - typedef endian< endianness::native, uint_least32_t, 32 > unative32_t; - typedef endian< endianness::native, uint_least64_t, 40 > unative40_t; - typedef endian< endianness::native, uint_least64_t, 48 > unative48_t; - typedef endian< endianness::native, uint_least64_t, 56 > unative56_t; - typedef endian< endianness::native, uint_least64_t, 64 > unative64_t; - -#define BOOST_HAS_INT16_T -#define BOOST_HAS_INT32_T -#define BOOST_HAS_INT64_T - - // These types only present if platform has exact size integers: - // aligned big endian signed integer types - // aligned big endian unsigned integer types - // aligned little endian signed integer types - // aligned little endian unsigned integer types - - // aligned native endian typedefs are not provided because - // types are superior for this use case - -# if defined(BOOST_HAS_INT16_T) - typedef endian< endianness::big, int16_t, 16, alignment::aligned > aligned_big16_t; - typedef endian< endianness::big, uint16_t, 16, alignment::aligned > aligned_ubig16_t; - typedef endian< endianness::little, int16_t, 16, alignment::aligned > aligned_little16_t; - typedef endian< endianness::little, uint16_t, 16, alignment::aligned > aligned_ulittle16_t; -# endif - -# if defined(BOOST_HAS_INT32_T) - typedef endian< endianness::big, int32_t, 32, alignment::aligned > aligned_big32_t; - typedef endian< endianness::big, uint32_t, 32, alignment::aligned > aligned_ubig32_t; - typedef endian< endianness::little, int32_t, 32, alignment::aligned > aligned_little32_t; - typedef endian< endianness::little, uint32_t, 32, alignment::aligned > aligned_ulittle32_t; -# endif - -# if defined(BOOST_HAS_INT64_T) - typedef endian< endianness::big, int64_t, 64, alignment::aligned > aligned_big64_t; - typedef endian< endianness::big, uint64_t, 64, alignment::aligned > aligned_ubig64_t; - typedef endian< endianness::little, int64_t, 64, alignment::aligned > aligned_little64_t; - typedef endian< endianness::little, uint64_t, 64, alignment::aligned > aligned_ulittle64_t; -# endif - - } // namespace integer -} // namespace boost - -#if defined(__BORLANDC__) || defined( __CODEGEARC__) -# pragma pack(pop) -#endif - -#endif // BOOST_ENDIAN_HPP diff --git a/boost/integer/endian_flip.hpp b/boost/integer/endian_flip.hpp deleted file mode 100644 index 5336d1a..0000000 --- a/boost/integer/endian_flip.hpp +++ /dev/null @@ -1,202 +0,0 @@ -// boost/endian/conversion.hpp -------------------------------------------------------// - -// Copyright Beman Dawes 2010, 2011 - -// 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 -#include - -//------------------------------------- synopsis ---------------------------------------// - -namespace boost -{ -namespace endian -{ - // unconditional modifying (i.e. in-place) endianness reversal - - inline void flip(int16_t& x); - inline void flip(int32_t& x); - inline void flip(int64_t& x); - inline void flip(uint16_t& x); - inline void flip(uint32_t& x); - inline void flip(uint64_t& x); - - // unconditional non-modifying endianness reversing copy - - inline void flip(int16_t source, int16_t& target); - inline void flip(int32_t source, int32_t& target); - inline void flip(int64_t source, int64_t& target); - inline void flip(uint16_t source, uint16_t& target); - inline void flip(uint32_t source, uint32_t& target); - inline void flip(uint64_t source, uint64_t& target); - - // conditional modifying (i.e. in-place) endianness reversal; - // no effect if native endianness and specified endianness are the same - - template inline void to_big(T& x); // if different, convert native to big - template inline void to_little(T& x); // if different, convert native to little - template inline void from_big(T& x); // if different, convert big to native - template inline void from_little(T& x); // if different, convert little to native - - // non-modifying copy, conditionally reversing endianness; - // copy the first argument to the second argument, converting to or from the - // specified endianness if different than native endianness - - template inline void to_big(T native, T& big); - template inline void to_little(T native, T& little); - template inline void from_big(T big, T& native); - template inline void from_little(T little, T& native); - -//----------------------------------- implementation -----------------------------------// - - inline void flip(int16_t& x) - { - char* rep = reinterpret_cast(&x); - char tmp; - tmp = *rep; - *rep = *(rep+1); - *(rep+1) = tmp; - } - - inline void flip(int32_t& x) - { - char* rep = reinterpret_cast(&x); - char tmp; - tmp = *rep; - *rep = *(rep+3); - *(rep+3) = tmp; - tmp = *(rep+1); - *(rep+1) = *(rep+2); - *(rep+2) = tmp; - } - - inline void flip(int64_t& x) - { - char* rep = reinterpret_cast(&x); - char tmp; - tmp = *rep; - *rep = *(rep+7); - *(rep+7) = tmp; - tmp = *(rep+1); - *(rep+1) = *(rep+6); - *(rep+6) = tmp; - tmp = *(rep+2); - *(rep+2) = *(rep+5); - *(rep+5) = tmp; - tmp = *(rep+3); - *(rep+3) = *(rep+4); - *(rep+4) = tmp; - } - - inline void flip(uint16_t& x) - { - char* rep = reinterpret_cast(&x); - char tmp; - tmp = *rep; - *rep = *(rep+1); - *(rep+1) = tmp; - } - - inline void flip(uint32_t& x) - { - char* rep = reinterpret_cast(&x); - char tmp; - tmp = *rep; - *rep = *(rep+3); - *(rep+3) = tmp; - tmp = *(rep+1); - *(rep+1) = *(rep+2); - *(rep+2) = tmp; - } - - inline void flip(uint64_t& x) - { - char* rep = reinterpret_cast(&x); - char tmp; - tmp = *rep; - *rep = *(rep+7); - *(rep+7) = tmp; - tmp = *(rep+1); - *(rep+1) = *(rep+6); - *(rep+6) = tmp; - tmp = *(rep+2); - *(rep+2) = *(rep+5); - *(rep+5) = tmp; - tmp = *(rep+3); - *(rep+3) = *(rep+4); - *(rep+4) = tmp; - } - - inline void flip(int16_t source, int16_t& target) - { - const char* s (reinterpret_cast(&source)); - char * t (reinterpret_cast(&target) + sizeof(target) - 1); - *t = *s; - *++t = *++s; - } - - inline void flip(int32_t source, int32_t& target) - { - const char* s (reinterpret_cast(&source)); - char * t (reinterpret_cast(&target) + sizeof(target) - 1); - *t = *s; - *++t = *++s; - *++t = *++s; - *++t = *++s; - } - - inline void flip(int64_t source, int64_t& target) - { - const char* s (reinterpret_cast(&source)); - char * t (reinterpret_cast(&target) + sizeof(target) - 1); - *t = *s; - *++t = *++s; - *++t = *++s; - *++t = *++s; - *++t = *++s; - *++t = *++s; - *++t = *++s; - *++t = *++s; - } - - inline void flip(uint16_t source, uint16_t& target) - { - const char* s (reinterpret_cast(&source)); - char * t (reinterpret_cast(&target) + sizeof(target) - 1); - *t = *s; - *++t = *++s; - } - - inline void flip(uint32_t source, uint32_t& target) - { - const char* s (reinterpret_cast(&source)); - char * t (reinterpret_cast(&target) + sizeof(target) - 1); - *t = *s; - *++t = *++s; - *++t = *++s; - *++t = *++s; - } - - inline void flip(uint64_t source, uint64_t& target) - { - const char* s (reinterpret_cast(&source)); - char * t (reinterpret_cast(&target) + sizeof(target) - 1); - *t = *s; - *++t = *++s; - *++t = *++s; - *++t = *++s; - *++t = *++s; - *++t = *++s; - *++t = *++s; - *++t = *++s; - } - -} // namespace endian -} // namespace boost - -#endif // BOOST_ENDIAN_CONVERSION_HPP