|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r68832 - in sandbox/endian_ext: boost/integer boost/integer/endian libs/integer/doc libs/integer/endian libs/integer/endian/doc libs/integer/endian/example libs/integer/endian/test libs/integer/example libs/integer/test
From: vicente.botet_at_[hidden]
Date: 2011-02-13 08:17:35
Author: viboes
Date: 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
New Revision: 68832
URL: http://svn.boost.org/trac/boost/changeset/68832
Log:
Integer.Endian: Move to integer/endian directory to make evident the extension
Added:
sandbox/endian_ext/boost/integer/endian/
sandbox/endian_ext/boost/integer/endian/cover_operators.hpp (contents, props changed)
sandbox/endian_ext/boost/integer/endian/domain_map.hpp (contents, props changed)
sandbox/endian_ext/boost/integer/endian/endian.hpp (contents, props changed)
sandbox/endian_ext/boost/integer/endian/endian_binary_stream.hpp (contents, props changed)
sandbox/endian_ext/boost/integer/endian/endian_conversion.hpp (contents, props changed)
sandbox/endian_ext/boost/integer/endian/endian_flip.hpp (contents, props changed)
sandbox/endian_ext/boost/integer/endian/endian_pack.hpp (contents, props changed)
sandbox/endian_ext/boost/integer/endian/endian_type.hpp (contents, props changed)
sandbox/endian_ext/boost/integer/endian/endian_view.hpp (contents, props changed)
sandbox/endian_ext/boost/integer/endian/endianness.hpp (contents, props changed)
sandbox/endian_ext/libs/integer/endian/
sandbox/endian_ext/libs/integer/endian/doc/
sandbox/endian_ext/libs/integer/endian/doc/Jamfile.v2 (contents, props changed)
sandbox/endian_ext/libs/integer/endian/doc/endian.html (contents, props changed)
sandbox/endian_ext/libs/integer/endian/doc/index.html (contents, props changed)
sandbox/endian_ext/libs/integer/endian/doc/integer_endian.qbk (contents, props changed)
sandbox/endian_ext/libs/integer/endian/example/
sandbox/endian_ext/libs/integer/endian/example/endian_example.cpp (contents, props changed)
sandbox/endian_ext/libs/integer/endian/example/endian_hello_world.cpp (contents, props changed)
sandbox/endian_ext/libs/integer/endian/example/endian_hello_world_1.cpp (contents, props changed)
sandbox/endian_ext/libs/integer/endian/example/endian_hello_world_2.cpp (contents, props changed)
sandbox/endian_ext/libs/integer/endian/example/endian_quantity.cpp (contents, props changed)
sandbox/endian_ext/libs/integer/endian/example/packet_example.cpp (contents, props changed)
sandbox/endian_ext/libs/integer/endian/test/
sandbox/endian_ext/libs/integer/endian/test/Jamfile.v2 (contents, props changed)
sandbox/endian_ext/libs/integer/endian/test/binary_stream_test.cpp (contents, props changed)
sandbox/endian_ext/libs/integer/endian/test/endian_binary_stream_test.cpp (contents, props changed)
sandbox/endian_ext/libs/integer/endian/test/endian_convert_test.cpp (contents, props changed)
sandbox/endian_ext/libs/integer/endian/test/endian_convert_unique_endian_test.cpp (contents, props changed)
sandbox/endian_ext/libs/integer/endian/test/endian_flip_test.cpp (contents, props changed)
sandbox/endian_ext/libs/integer/endian/test/endian_in_union_test.cpp (contents, props changed)
sandbox/endian_ext/libs/integer/endian/test/endian_operations_test.cpp (contents, props changed)
sandbox/endian_ext/libs/integer/endian/test/endian_pack_test.cpp (contents, props changed)
sandbox/endian_ext/libs/integer/endian/test/endian_test.cpp (contents, props changed)
sandbox/endian_ext/libs/integer/endian/test/endian_type_test.cpp (contents, props changed)
sandbox/endian_ext/libs/integer/endian/test/endian_view_test.cpp (contents, props changed)
sandbox/endian_ext/libs/integer/endian/test/scoped_enum_emulation_test.cpp (contents, props changed)
Removed:
sandbox/endian_ext/boost/integer/cover_operators.hpp
sandbox/endian_ext/boost/integer/endian.hpp
sandbox/endian_ext/boost/integer/endian_binary_stream.hpp
sandbox/endian_ext/boost/integer/endian_conversion.hpp
sandbox/endian_ext/boost/integer/endian_flip.hpp
sandbox/endian_ext/boost/integer/endian_pack.hpp
sandbox/endian_ext/boost/integer/endian_type.hpp
sandbox/endian_ext/boost/integer/endian_view.hpp
sandbox/endian_ext/libs/integer/doc/
sandbox/endian_ext/libs/integer/example/
sandbox/endian_ext/libs/integer/test/
Deleted: sandbox/endian_ext/boost/integer/cover_operators.hpp
==============================================================================
--- sandbox/endian_ext/boost/integer/cover_operators.hpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
+++ (empty file)
@@ -1,111 +0,0 @@
-// boost/integer/cover_operators.hpp ----------------------------------------//
-
-// Copyright Darin Adler 2000
-// Copyright Beman Dawes 2008
-
-// Distributed under the Boost Software License, Version 1.0. (See accompanying
-// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-
-//----------------------------------------------------------------------------//
-
-// If the class being covered has a non-explicit conversion to an integer type
-// then a smaller number of cover operations are needed. Define the macro
-// BOOST_MINIMAL_INTEGER_COVER_OPERATORS to indicate this.
-
-// Define BOOST_NO_IO_COVER_OPERATORS if I/O cover operations are not desired.
-
-//----------------------------------------------------------------------------//
-
-#ifndef BOOST_INTEGER_COVER_OPERATORS_HPP
-#define BOOST_INTEGER_COVER_OPERATORS_HPP
-
-# ifndef BOOST_MINIMAL_INTEGER_COVER_OPERATORS
-# include <boost/operators.hpp>
-# endif
-
-#include <iosfwd>
-
-namespace boost
-{
- namespace integer
- {
-
- // A class that adds integer operators to an integer cover class
-
- template <typename T, typename IntegerType>
- class cover_operators
-# ifndef BOOST_MINIMAL_INTEGER_COVER_OPERATORS
- : boost::operators<T>
-# endif
- {
- // The other operations take advantage of the type conversion that's
- // built into unary +.
-
- // Unary operations.
- friend IntegerType operator+(const T& x) { return x; }
-# ifndef BOOST_MINIMAL_INTEGER_COVER_OPERATORS
- friend IntegerType operator-(const T& x) { return -+x; }
- friend IntegerType operator~(const T& x) { return ~+x; }
- friend IntegerType operator!(const T& x) { return !+x; }
-
- // The basic ordering operations.
- friend bool operator==(const T& x, IntegerType y) { return +x == y; }
- friend bool operator<(const T& x, IntegerType y) { return +x < y; }
-# endif
-
- // The basic arithmetic operations.
- friend T& operator+=(T& x, IntegerType y) { return x = +x + y; }
- friend T& operator-=(T& x, IntegerType y) { return x = +x - y; }
- friend T& operator*=(T& x, IntegerType y) { return x = +x * y; }
- friend T& operator/=(T& x, IntegerType y) { return x = +x / y; }
- friend T& operator%=(T& x, IntegerType y) { return x = +x % y; }
- friend T& operator&=(T& x, IntegerType y) { return x = +x & y; }
- friend T& operator|=(T& x, IntegerType y) { return x = +x | y; }
- friend T& operator^=(T& x, IntegerType y) { return x = +x ^ y; }
- friend T& operator<<=(T& x, IntegerType y) { return x = +x << y; }
- friend T& operator>>=(T& x, IntegerType y) { return x = +x >> y; }
-
- // A few binary arithmetic operations not covered by operators base class.
- friend IntegerType operator<<(const T& x, IntegerType y) { return +x << y; }
- friend IntegerType operator>>(const T& x, IntegerType y) { return +x >> y; }
-
- // Auto-increment and auto-decrement can be defined in terms of the
- // arithmetic operations.
- friend T& operator++(T& x) { return x += 1; }
- friend T& operator--(T& x) { return x -= 1; }
-
-# ifdef BOOST_MINIMAL_INTEGER_COVER_OPERATORS
- friend T operator++(T& x, int)
- {
- T tmp(x);
- x += 1;
- return tmp;
- }
- friend T operator--(T& x, int)
- {
- T tmp(x);
- x -= 1;
- return tmp;
- }
-# endif
-
-# ifndef BOOST_NO_IO_COVER_OPERATORS
- // TODO: stream I/O needs to be templatized on the stream type, so will
- // work with wide streams, etc.
-
- // Stream input and output.
- friend std::ostream& operator<<(std::ostream& s, const T& x)
- { return s << +x; }
- friend std::istream& operator>>(std::istream& s, T& x)
- {
- IntegerType i;
- if (s >> i)
- x = i;
- return s;
- }
-# endif
- };
- } // namespace integer
-} // namespace boost
-
-#endif // BOOST_INTEGER_COVER_OPERATORS_HPP
Deleted: sandbox/endian_ext/boost/integer/endian.hpp
==============================================================================
--- sandbox/endian_ext/boost/integer/endian.hpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
+++ (empty file)
@@ -1,352 +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.
-
-// Split of endian.hpp into endian.hpp and endian_pack?hpp done by Vicente J. Botet Escriba.
-
-// TODO: When a compiler supporting constexpr becomes available, try possible uses.
-
-#ifndef BOOST_INTEGER_ENDIAN_HPP
-#define BOOST_INTEGER_ENDIAN_HPP
-
-#include <boost/integer/endian_pack.hpp>
-
-
-#if defined(__BORLANDC__) || defined( __CODEGEARC__)
-# pragma pack(push, 1)
-#endif
-
-#include <boost/config.hpp>
-#define BOOST_MINIMAL_INTEGER_COVER_OPERATORS
-#define BOOST_NO_IO_COVER_OPERATORS
-#include <boost/integer/cover_operators.hpp>
-#undef BOOST_NO_IO_COVER_OPERATORS
-#undef BOOST_MINIMAL_INTEGER_COVER_OPERATORS
-#include <boost/type_traits/is_signed.hpp>
-#include <boost/cstdint.hpp>
-#include <boost/static_assert.hpp>
-#include <iosfwd>
-#include <climits>
-#include <limits>
-#include <cstddef>
-
-namespace boost
-{
-
- namespace integer
- {
-
- template <typename E,
- typename T,
- std::size_t n_bits=sizeof(T)*8,
- BOOST_SCOPED_ENUM(alignment) A = alignment::aligned
- > class endian
- : cover_operators< endian< E, T, n_bits, A>, T >
- {
- endian_pack<E, T, n_bits, A> pack_;
-
- public:
- typedef T value_type;
-# ifndef BOOST_ENDIAN_NO_CTORS
- endian() BOOST_ENDIAN_DEFAULT_CONSTRUCT
- template <typename T2>
- explicit endian(T2 val)
- //~ explicit endian(T val)
- : pack_(val)
- {
- }
-# endif
- endian & operator=(T val) {
- pack_=val;
- return *this;
- }
- operator T() const
- {
- return T(pack_);
- }
- const char* data() const { return pack_.data(); }
-
- };
-
- // naming convention typedefs ------------------------------------------------------//
-
- // unaligned big endian signed integer types
- typedef endian< big_endian, int_least8_t, 8, alignment::unaligned > big8_t;
- typedef endian< big_endian, int_least16_t, 16, alignment::unaligned > big16_t;
- typedef endian< big_endian, int_least32_t, 24, alignment::unaligned > big24_t;
- typedef endian< big_endian, int_least32_t, 32, alignment::unaligned > big32_t;
- typedef endian< big_endian, int_least64_t, 40, alignment::unaligned > big40_t;
- typedef endian< big_endian, int_least64_t, 48, alignment::unaligned > big48_t;
- typedef endian< big_endian, int_least64_t, 56, alignment::unaligned > big56_t;
- typedef endian< big_endian, int_least64_t, 64, alignment::unaligned > big64_t;
-
- // unaligned big endian unsigned integer types
- typedef endian< big_endian, uint_least8_t, 8, alignment::unaligned > ubig8_t;
- typedef endian< big_endian, uint_least16_t, 16, alignment::unaligned > ubig16_t;
- typedef endian< big_endian, uint_least32_t, 24, alignment::unaligned > ubig24_t;
- typedef endian< big_endian, uint_least32_t, 32, alignment::unaligned > ubig32_t;
- typedef endian< big_endian, uint_least64_t, 40, alignment::unaligned > ubig40_t;
- typedef endian< big_endian, uint_least64_t, 48, alignment::unaligned > ubig48_t;
- typedef endian< big_endian, uint_least64_t, 56, alignment::unaligned > ubig56_t;
- typedef endian< big_endian, uint_least64_t, 64, alignment::unaligned > ubig64_t;
-
- // unaligned little endian signed integer types
- typedef endian< little_endian, int_least8_t, 8, alignment::unaligned > little8_t;
- typedef endian< little_endian, int_least16_t, 16, alignment::unaligned > little16_t;
- typedef endian< little_endian, int_least32_t, 24, alignment::unaligned > little24_t;
- typedef endian< little_endian, int_least32_t, 32, alignment::unaligned > little32_t;
- typedef endian< little_endian, int_least64_t, 40, alignment::unaligned > little40_t;
- typedef endian< little_endian, int_least64_t, 48, alignment::unaligned > little48_t;
- typedef endian< little_endian, int_least64_t, 56, alignment::unaligned > little56_t;
- typedef endian< little_endian, int_least64_t, 64, alignment::unaligned > little64_t;
-
- // unaligned little endian unsigned integer types
- typedef endian< little_endian, uint_least8_t, 8, alignment::unaligned > ulittle8_t;
- typedef endian< little_endian, uint_least16_t, 16, alignment::unaligned > ulittle16_t;
- typedef endian< little_endian, uint_least32_t, 24, alignment::unaligned > ulittle24_t;
- typedef endian< little_endian, uint_least32_t, 32, alignment::unaligned > ulittle32_t;
- typedef endian< little_endian, uint_least64_t, 40, alignment::unaligned > ulittle40_t;
- typedef endian< little_endian, uint_least64_t, 48, alignment::unaligned > ulittle48_t;
- typedef endian< little_endian, uint_least64_t, 56, alignment::unaligned > ulittle56_t;
- typedef endian< little_endian, uint_least64_t, 64, alignment::unaligned > ulittle64_t;
-
- // unaligned native endian signed integer types
- typedef endian< native_endian, int_least8_t, 8, alignment::unaligned > native8_t;
- typedef endian< native_endian, int_least16_t, 16, alignment::unaligned > native16_t;
- typedef endian< native_endian, int_least32_t, 24, alignment::unaligned > native24_t;
- typedef endian< native_endian, int_least32_t, 32, alignment::unaligned > native32_t;
- typedef endian< native_endian, int_least64_t, 40, alignment::unaligned > native40_t;
- typedef endian< native_endian, int_least64_t, 48, alignment::unaligned > native48_t;
- typedef endian< native_endian, int_least64_t, 56, alignment::unaligned > native56_t;
- typedef endian< native_endian, int_least64_t, 64, alignment::unaligned > native64_t;
-
- // unaligned native endian unsigned integer types
- typedef endian< native_endian, uint_least8_t, 8, alignment::unaligned > unative8_t;
- typedef endian< native_endian, uint_least16_t, 16, alignment::unaligned > unative16_t;
- typedef endian< native_endian, uint_least32_t, 24, alignment::unaligned > unative24_t;
- typedef endian< native_endian, uint_least32_t, 32, alignment::unaligned > unative32_t;
- typedef endian< native_endian, uint_least64_t, 40, alignment::unaligned > unative40_t;
- typedef endian< native_endian, uint_least64_t, 48, alignment::unaligned > unative48_t;
- typedef endian< native_endian, uint_least64_t, 56, alignment::unaligned > unative56_t;
- typedef endian< native_endian, uint_least64_t, 64, alignment::unaligned > 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
- // <cstdint> types are superior for this use case
-
-# if defined(BOOST_HAS_INT16_T)
- typedef endian< big_endian, int16_t, 16, alignment::aligned > aligned_big16_t;
- typedef endian< big_endian, uint16_t, 16, alignment::aligned > aligned_ubig16_t;
- typedef endian< little_endian, int16_t, 16, alignment::aligned > aligned_little16_t;
- typedef endian< little_endian, uint16_t, 16, alignment::aligned > aligned_ulittle16_t;
-# endif
-
-# if defined(BOOST_HAS_INT32_T)
- typedef endian< big_endian, int32_t, 32, alignment::aligned > aligned_big32_t;
- typedef endian< big_endian, uint32_t, 32, alignment::aligned > aligned_ubig32_t;
- typedef endian< little_endian, int32_t, 32, alignment::aligned > aligned_little32_t;
- typedef endian< little_endian, uint32_t, 32, alignment::aligned > aligned_ulittle32_t;
-# endif
-
-# if defined(BOOST_HAS_INT64_T)
- typedef endian< big_endian, int64_t, 64, alignment::aligned > aligned_big64_t;
- typedef endian< big_endian, uint64_t, 64, alignment::aligned > aligned_ubig64_t;
- typedef endian< little_endian, int64_t, 64, alignment::aligned > aligned_little64_t;
- typedef endian< little_endian, uint64_t, 64, alignment::aligned > aligned_ulittle64_t;
-# endif
-
- template<typename OSTREAM, typename E,
- typename T, std::size_t N,
- BOOST_SCOPED_ENUM(alignment) A>
- OSTREAM&
- operator<<(OSTREAM & os,
- const endian< E,T,N,A > & aval) {
- os << T(aval);
- return os;
-
- }
-
-
- } // namespace integer
-} // namespace boost
-
-#if defined(__BORLANDC__) || defined( __CODEGEARC__)
-# pragma pack(pop)
-#endif
-
-#if 0
-namespace std {
- template <typename E,
- typename T,
- size_t N
- > class numeric_limits<boost::integer::endian<E,T,N,boost::integer::alignment::aligned> >
- {
- typedef T value_type;
- public:
-
- BOOST_STATIC_CONSTANT(bool, is_specialized = true);
- static value_type min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return numeric_limits<value_type>::(min)(); }
- static value_type max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return numeric_limits<value_type>::(max)(); }
- BOOST_STATIC_CONSTANT(int, digits = numeric_limits<value_type>::digits);
- BOOST_STATIC_CONSTANT(int, digits10 = numeric_limits<value_type>::digits10);
- BOOST_STATIC_CONSTANT(bool, is_signed = numeric_limits<value_type>::is_signed);
- BOOST_STATIC_CONSTANT(bool, is_integer = numeric_limits<value_type>::is_integer);
- BOOST_STATIC_CONSTANT(bool, is_exact = numeric_limits<value_type>::is_exact);
- BOOST_STATIC_CONSTANT(int, radix = numeric_limits<value_type>::radix);
- static value_type epsilon() throw() { return numeric_limits<value_type>::epsilon(); };
- static value_type round_error() throw() { return numeric_limits<value_type>::round_error(); };
-
- BOOST_STATIC_CONSTANT(int, min_exponent = numeric_limits<value_type>::min_exponent);
- BOOST_STATIC_CONSTANT(int, min_exponent10 = numeric_limits<value_type>::min_exponent10);
- BOOST_STATIC_CONSTANT(int, max_exponent = numeric_limits<value_type>::max_exponent);
- BOOST_STATIC_CONSTANT(int, max_exponent10 = numeric_limits<value_type>::max_exponent10);
-
- BOOST_STATIC_CONSTANT(bool, has_infinity = numeric_limits<value_type>::has_infinity);
- BOOST_STATIC_CONSTANT(bool, has_quiet_NaN = numeric_limits<value_type>::has_quiet_NaN);
- BOOST_STATIC_CONSTANT(bool, has_signaling_NaN = numeric_limits<value_type>::has_signaling_NaN);
- BOOST_STATIC_CONSTANT(bool, has_denorm = numeric_limits<value_type>::has_denorm);
- BOOST_STATIC_CONSTANT(bool, has_denorm_loss = numeric_limits<value_type>::has_denorm_loss);
- static value_type infinity() throw() { return numeric_limits<value_type>::infinity(); };
- static value_type quiet_NaN() throw() { return numeric_limits<value_type>::quiet_NaN(); };
- static value_type signaling_NaN() throw() { return numeric_limits<value_type>::signaling_NaN(); };
- static value_type denorm_min() throw() { return numeric_limits<value_type>::denorm_min(); };
-
- BOOST_STATIC_CONSTANT(bool, is_iec559 = numeric_limits<value_type>::is_iec559);
- BOOST_STATIC_CONSTANT(bool, is_bounded = numeric_limits<value_type>::is_bounded);
- BOOST_STATIC_CONSTANT(bool, is_modulo = numeric_limits<value_type>::is_modulo);
-
- BOOST_STATIC_CONSTANT(bool, traps = numeric_limits<value_type>::traps);
- BOOST_STATIC_CONSTANT(bool, tinyness_before = numeric_limits<value_type>::tinyness_before);
- BOOST_STATIC_CONSTANT(float_round_style, round_style = numeric_limits<value_type>::round_style);
-
- };
-
-namespace std {
- template <typename E,
- typename T,
- size_t N
- > class numeric_limits<boost::integer::endian<E,T,N,boost::integer::alignment::aligned> >
- {
- typedef T value_type;
- public:
-
- BOOST_STATIC_CONSTANT(bool, is_specialized = true);
- static value_type min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return numeric_limits<value_type>::(min)(); }
- static value_type max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return numeric_limits<value_type>::(max)(); }
- BOOST_STATIC_CONSTANT(int, digits = numeric_limits<value_type>::digits);
- BOOST_STATIC_CONSTANT(int, digits10 = numeric_limits<value_type>::digits10);
- BOOST_STATIC_CONSTANT(bool, is_signed = numeric_limits<value_type>::is_signed);
- BOOST_STATIC_CONSTANT(bool, is_integer = numeric_limits<value_type>::is_integer);
- BOOST_STATIC_CONSTANT(bool, is_exact = numeric_limits<value_type>::is_exact);
- BOOST_STATIC_CONSTANT(int, radix = numeric_limits<value_type>::radix);
- static value_type epsilon() throw() { return numeric_limits<value_type>::epsilon(); };
- static value_type round_error() throw() { return numeric_limits<value_type>::round_error(); };
-
- BOOST_STATIC_CONSTANT(int, min_exponent = numeric_limits<value_type>::min_exponent);
- BOOST_STATIC_CONSTANT(int, min_exponent10 = numeric_limits<value_type>::min_exponent10);
- BOOST_STATIC_CONSTANT(int, max_exponent = numeric_limits<value_type>::max_exponent);
- BOOST_STATIC_CONSTANT(int, max_exponent10 = numeric_limits<value_type>::max_exponent10);
-
- BOOST_STATIC_CONSTANT(bool, has_infinity = numeric_limits<value_type>::has_infinity);
- BOOST_STATIC_CONSTANT(bool, has_quiet_NaN = numeric_limits<value_type>::has_quiet_NaN);
- BOOST_STATIC_CONSTANT(bool, has_signaling_NaN = numeric_limits<value_type>::has_signaling_NaN);
- BOOST_STATIC_CONSTANT(bool, has_denorm = numeric_limits<value_type>::has_denorm);
- BOOST_STATIC_CONSTANT(bool, has_denorm_loss = numeric_limits<value_type>::has_denorm_loss);
- static value_type infinity() throw() { return numeric_limits<value_type>::infinity(); };
- static value_type quiet_NaN() throw() { return numeric_limits<value_type>::quiet_NaN(); };
- static value_type signaling_NaN() throw() { return numeric_limits<value_type>::signaling_NaN(); };
- static value_type denorm_min() throw() { return numeric_limits<value_type>::denorm_min(); };
-
- BOOST_STATIC_CONSTANT(bool, is_iec559 = numeric_limits<value_type>::is_iec559);
- BOOST_STATIC_CONSTANT(bool, is_bounded = numeric_limits<value_type>::is_bounded);
- BOOST_STATIC_CONSTANT(bool, is_modulo = numeric_limits<value_type>::is_modulo);
-
- BOOST_STATIC_CONSTANT(bool, traps = numeric_limits<value_type>::traps);
- BOOST_STATIC_CONSTANT(bool, tinyness_before = numeric_limits<value_type>::tinyness_before);
- BOOST_STATIC_CONSTANT(float_round_style, round_style = numeric_limits<value_type>::round_style);
-
- };
-
-
-namespace std {
- template <typename E,
- typename T,
- size_t N
- > class numeric_limits<boost::integer::endian<E,T,N,boost::integer::alignment::unaligned> >
- {
- typedef T value_type;
- public:
-
- BOOST_STATIC_CONSTANT(bool, is_specialized = true);
- static value_type min BOOST_PREVENT_MACRO_SUBSTITUTION (){
- return numeric_limits<value_type>::is_signed
- ? low_bit_mask<value_type, N>::value
- : 0;
- }
- static value_type max BOOST_PREVENT_MACRO_SUBSTITUTION (){
- return numeric_limits<value_type>::is_signed
- ?low_bit_mask<value_type, N-1>::value
- :low_bit_mask<value_type, N>::value;
- }
- BOOST_STATIC_CONSTANT(int, digits = N);
- BOOST_STATIC_CONSTANT(int, digits10 = 2<<N);
- BOOST_STATIC_CONSTANT(bool, is_signed = numeric_limits<value_type>::is_signed);
- BOOST_STATIC_CONSTANT(bool, is_integer = numeric_limits<value_type>::is_integer);
- BOOST_STATIC_CONSTANT(bool, is_exact = numeric_limits<value_type>::is_exact);
- BOOST_STATIC_CONSTANT(int, radix = numeric_limits<value_type>::radix);
- static value_type epsilon() throw() { return numeric_limits<value_type>::epsilon(); };
- static value_type round_error() throw() { return numeric_limits<value_type>::round_error(); };
-
- BOOST_STATIC_CONSTANT(int, min_exponent = numeric_limits<value_type>::min_exponent);
- BOOST_STATIC_CONSTANT(int, min_exponent10 = numeric_limits<value_type>::min_exponent10);
- BOOST_STATIC_CONSTANT(int, max_exponent = numeric_limits<value_type>::max_exponent);
- BOOST_STATIC_CONSTANT(int, max_exponent10 = numeric_limits<value_type>::max_exponent10);
-
- BOOST_STATIC_CONSTANT(bool, has_infinity = numeric_limits<value_type>::has_infinity);
- BOOST_STATIC_CONSTANT(bool, has_quiet_NaN = numeric_limits<value_type>::has_quiet_NaN);
- BOOST_STATIC_CONSTANT(bool, has_signaling_NaN = numeric_limits<value_type>::has_signaling_NaN);
- BOOST_STATIC_CONSTANT(bool, has_denorm = numeric_limits<value_type>::has_denorm);
- BOOST_STATIC_CONSTANT(bool, has_denorm_loss = numeric_limits<value_type>::has_denorm_loss);
- static value_type infinity() throw() { return numeric_limits<value_type>::infinity(); };
- static value_type quiet_NaN() throw() { return numeric_limits<value_type>::quiet_NaN(); };
- static value_type signaling_NaN() throw() { return numeric_limits<value_type>::signaling_NaN(); };
- static value_type denorm_min() throw() { return numeric_limits<value_type>::denorm_min(); };
-
- BOOST_STATIC_CONSTANT(bool, is_iec559 = numeric_limits<value_type>::is_iec559);
- BOOST_STATIC_CONSTANT(bool, is_bounded = numeric_limits<value_type>::is_bounded);
- BOOST_STATIC_CONSTANT(bool, is_modulo = numeric_limits<value_type>::is_modulo);
-
- BOOST_STATIC_CONSTANT(bool, traps = numeric_limits<value_type>::traps);
- BOOST_STATIC_CONSTANT(bool, tinyness_before = numeric_limits<value_type>::tinyness_before);
- BOOST_STATIC_CONSTANT(float_round_style, round_style = numeric_limits<value_type>::round_style);
-
- };
-
-
-} // namespace std
-
-#endif
-#endif // BOOST_ENDIAN_HPP
Added: sandbox/endian_ext/boost/integer/endian/cover_operators.hpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/boost/integer/endian/cover_operators.hpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,111 @@
+// boost/integer/cover_operators.hpp ----------------------------------------//
+
+// Copyright Darin Adler 2000
+// Copyright Beman Dawes 2008
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+//----------------------------------------------------------------------------//
+
+// If the class being covered has a non-explicit conversion to an integer type
+// then a smaller number of cover operations are needed. Define the macro
+// BOOST_MINIMAL_INTEGER_COVER_OPERATORS to indicate this.
+
+// Define BOOST_NO_IO_COVER_OPERATORS if I/O cover operations are not desired.
+
+//----------------------------------------------------------------------------//
+
+#ifndef BOOST_INTEGER_COVER_OPERATORS_HPP
+#define BOOST_INTEGER_COVER_OPERATORS_HPP
+
+# ifndef BOOST_MINIMAL_INTEGER_COVER_OPERATORS
+# include <boost/operators.hpp>
+# endif
+
+#include <iosfwd>
+
+namespace boost
+{
+ namespace integer
+ {
+
+ // A class that adds integer operators to an integer cover class
+
+ template <typename T, typename IntegerType>
+ class cover_operators
+# ifndef BOOST_MINIMAL_INTEGER_COVER_OPERATORS
+ : boost::operators<T>
+# endif
+ {
+ // The other operations take advantage of the type conversion that's
+ // built into unary +.
+
+ // Unary operations.
+ friend IntegerType operator+(const T& x) { return x; }
+# ifndef BOOST_MINIMAL_INTEGER_COVER_OPERATORS
+ friend IntegerType operator-(const T& x) { return -+x; }
+ friend IntegerType operator~(const T& x) { return ~+x; }
+ friend IntegerType operator!(const T& x) { return !+x; }
+
+ // The basic ordering operations.
+ friend bool operator==(const T& x, IntegerType y) { return +x == y; }
+ friend bool operator<(const T& x, IntegerType y) { return +x < y; }
+# endif
+
+ // The basic arithmetic operations.
+ friend T& operator+=(T& x, IntegerType y) { return x = +x + y; }
+ friend T& operator-=(T& x, IntegerType y) { return x = +x - y; }
+ friend T& operator*=(T& x, IntegerType y) { return x = +x * y; }
+ friend T& operator/=(T& x, IntegerType y) { return x = +x / y; }
+ friend T& operator%=(T& x, IntegerType y) { return x = +x % y; }
+ friend T& operator&=(T& x, IntegerType y) { return x = +x & y; }
+ friend T& operator|=(T& x, IntegerType y) { return x = +x | y; }
+ friend T& operator^=(T& x, IntegerType y) { return x = +x ^ y; }
+ friend T& operator<<=(T& x, IntegerType y) { return x = +x << y; }
+ friend T& operator>>=(T& x, IntegerType y) { return x = +x >> y; }
+
+ // A few binary arithmetic operations not covered by operators base class.
+ friend IntegerType operator<<(const T& x, IntegerType y) { return +x << y; }
+ friend IntegerType operator>>(const T& x, IntegerType y) { return +x >> y; }
+
+ // Auto-increment and auto-decrement can be defined in terms of the
+ // arithmetic operations.
+ friend T& operator++(T& x) { return x += 1; }
+ friend T& operator--(T& x) { return x -= 1; }
+
+# ifdef BOOST_MINIMAL_INTEGER_COVER_OPERATORS
+ friend T operator++(T& x, int)
+ {
+ T tmp(x);
+ x += 1;
+ return tmp;
+ }
+ friend T operator--(T& x, int)
+ {
+ T tmp(x);
+ x -= 1;
+ return tmp;
+ }
+# endif
+
+# ifndef BOOST_NO_IO_COVER_OPERATORS
+ // TODO: stream I/O needs to be templatized on the stream type, so will
+ // work with wide streams, etc.
+
+ // Stream input and output.
+ friend std::ostream& operator<<(std::ostream& s, const T& x)
+ { return s << +x; }
+ friend std::istream& operator>>(std::istream& s, T& x)
+ {
+ IntegerType i;
+ if (s >> i)
+ x = i;
+ return s;
+ }
+# endif
+ };
+ } // namespace integer
+} // namespace boost
+
+#endif // BOOST_INTEGER_COVER_OPERATORS_HPP
Added: sandbox/endian_ext/boost/integer/endian/domain_map.hpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/boost/integer/endian/domain_map.hpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,106 @@
+// Boost endian_view.hpp header file -------------------------------------------------------//
+
+// (C) Copyright VicenteJ Botet Escriba 2010-2011
+
+// 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/integer/endian
+
+//--------------------------------------------------------------------------------------//
+
+
+#ifndef BOOST_ENDIAN_DOMAIN_MAP__HPP
+#define BOOST_ENDIAN_DOMAIN_MAP__HPP
+
+#include <boost/integer/endian/endianness.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/push_back.hpp>
+#include <boost/mpl/void.hpp>
+#include <boost/fusion/include/deref.hpp>
+#include <boost/fusion/include/next.hpp>
+#include <boost/fusion/include/begin.hpp>
+#include <boost/fusion/include/end.hpp>
+#include <boost/fusion/include/is_sequence.hpp>
+#include <boost/type_traits/is_fundamental.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+#include <boost/type_traits/remove_cv.hpp>
+
+namespace boost {
+
+namespace integer {
+
+namespace endianness {
+
+ namespace endian_detail {
+
+ template <typename Domain, typename T,
+ bool isFundamental = is_fundamental<T>::value,
+ bool IsSeq = fusion::traits::is_sequence<T>::value
+ >
+ struct domain_map_impl;
+
+ }
+
+ /// By default the shared endianess of a type depends on whether it is fundamental and or a fusion sequence.
+ template <typename Domain, typename T>
+ struct domain_map : endian_detail::domain_map_impl<Domain, T> {};
+
+ namespace endian_detail {
+
+ // fundamental types are native
+ template <typename Domain, typename T, bool IsSeq>
+ struct domain_map_impl<Domain, T, true, IsSeq> {
+ typedef Domain type;
+ };
+
+ // other type which has not been explicitly declared is undefined,
+ template <typename Domain, typename T>
+ struct domain_map_impl<Domain, T, false, false> {};
+
+ template <typename Domain, typename SharedTree, typename It, typename End>
+ struct domain_map_loop {
+ private:
+ typedef
+ typename remove_reference<
+ typename remove_cv<
+ typename fusion::result_of::deref<It>::type
+ >::type
+ >::type it_type;
+ public:
+ typedef typename domain_map_loop<Domain,
+ typename mpl::push_back<SharedTree, typename domain_map<Domain, it_type>::type>::type,
+ typename fusion::result_of::next<It>::type,
+ End
+ >::type type;
+ };
+
+ // When iteration ends, accumulated SharedTree
+ template <typename Domain, typename SharedTree, typename End>
+ struct domain_map_loop<Domain, SharedTree, End, End> {
+ typedef SharedTree type;
+ };
+
+ // fusion sequences are mixed if not all the elements habve the same endianess,
+ // otherwise the endianess of all the types.
+ template <typename Domain, typename Seq>
+ struct domain_map_impl<Domain, Seq, false, true> :
+ domain_map_loop<Domain, mpl::vector<>,
+ typename fusion::result_of::begin<Seq>::type,
+ typename fusion::result_of::end<Seq>::type
+ >
+ {};
+
+ }
+ /// All the elements of an array are seen with the same endianess.
+ template <typename Domain, typename T, std::size_t N>
+ struct domain_map<Domain,T[N]> {
+ typedef typename domain_map<Domain, T>::type type;
+ };
+
+} // namespace endianness
+} // namespace integer
+} // namespace boost
+
+
+#endif // BOOST_ENDIAN_DOMAIN_MAP__HPP
Added: sandbox/endian_ext/boost/integer/endian/endian.hpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/boost/integer/endian/endian.hpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,352 @@
+// 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/integer/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.
+
+// Split of endian.hpp into endian.hpp and endian_pack?hpp done by Vicente J. Botet Escriba.
+
+// TODO: When a compiler supporting constexpr becomes available, try possible uses.
+
+#ifndef BOOST_INTEGER_ENDIAN_HPP
+#define BOOST_INTEGER_ENDIAN_HPP
+
+#include <boost/integer/endian/endian_pack.hpp>
+
+
+#if defined(__BORLANDC__) || defined( __CODEGEARC__)
+# pragma pack(push, 1)
+#endif
+
+#include <boost/config.hpp>
+#define BOOST_MINIMAL_INTEGER_COVER_OPERATORS
+#define BOOST_NO_IO_COVER_OPERATORS
+#include <boost/integer/endian/cover_operators.hpp>
+#undef BOOST_NO_IO_COVER_OPERATORS
+#undef BOOST_MINIMAL_INTEGER_COVER_OPERATORS
+#include <boost/type_traits/is_signed.hpp>
+#include <boost/cstdint.hpp>
+#include <boost/static_assert.hpp>
+#include <iosfwd>
+#include <climits>
+#include <limits>
+#include <cstddef>
+
+namespace boost
+{
+
+ namespace integer
+ {
+
+ template <typename E,
+ typename T,
+ std::size_t n_bits=sizeof(T)*8,
+ BOOST_SCOPED_ENUM(alignment) A = alignment::aligned
+ > class endian
+ : cover_operators< endian< E, T, n_bits, A>, T >
+ {
+ endian_pack<E, T, n_bits, A> pack_;
+
+ public:
+ typedef T value_type;
+# ifndef BOOST_ENDIAN_NO_CTORS
+ endian() BOOST_ENDIAN_DEFAULT_CONSTRUCT
+ template <typename T2>
+ explicit endian(T2 val)
+ //~ explicit endian(T val)
+ : pack_(val)
+ {
+ }
+# endif
+ endian & operator=(T val) {
+ pack_=val;
+ return *this;
+ }
+ operator T() const
+ {
+ return T(pack_);
+ }
+ const char* data() const { return pack_.data(); }
+
+ };
+
+ // naming convention typedefs ------------------------------------------------------//
+
+ // unaligned big endian signed integer types
+ typedef endian< big_endian, int_least8_t, 8, alignment::unaligned > big8_t;
+ typedef endian< big_endian, int_least16_t, 16, alignment::unaligned > big16_t;
+ typedef endian< big_endian, int_least32_t, 24, alignment::unaligned > big24_t;
+ typedef endian< big_endian, int_least32_t, 32, alignment::unaligned > big32_t;
+ typedef endian< big_endian, int_least64_t, 40, alignment::unaligned > big40_t;
+ typedef endian< big_endian, int_least64_t, 48, alignment::unaligned > big48_t;
+ typedef endian< big_endian, int_least64_t, 56, alignment::unaligned > big56_t;
+ typedef endian< big_endian, int_least64_t, 64, alignment::unaligned > big64_t;
+
+ // unaligned big endian unsigned integer types
+ typedef endian< big_endian, uint_least8_t, 8, alignment::unaligned > ubig8_t;
+ typedef endian< big_endian, uint_least16_t, 16, alignment::unaligned > ubig16_t;
+ typedef endian< big_endian, uint_least32_t, 24, alignment::unaligned > ubig24_t;
+ typedef endian< big_endian, uint_least32_t, 32, alignment::unaligned > ubig32_t;
+ typedef endian< big_endian, uint_least64_t, 40, alignment::unaligned > ubig40_t;
+ typedef endian< big_endian, uint_least64_t, 48, alignment::unaligned > ubig48_t;
+ typedef endian< big_endian, uint_least64_t, 56, alignment::unaligned > ubig56_t;
+ typedef endian< big_endian, uint_least64_t, 64, alignment::unaligned > ubig64_t;
+
+ // unaligned little endian signed integer types
+ typedef endian< little_endian, int_least8_t, 8, alignment::unaligned > little8_t;
+ typedef endian< little_endian, int_least16_t, 16, alignment::unaligned > little16_t;
+ typedef endian< little_endian, int_least32_t, 24, alignment::unaligned > little24_t;
+ typedef endian< little_endian, int_least32_t, 32, alignment::unaligned > little32_t;
+ typedef endian< little_endian, int_least64_t, 40, alignment::unaligned > little40_t;
+ typedef endian< little_endian, int_least64_t, 48, alignment::unaligned > little48_t;
+ typedef endian< little_endian, int_least64_t, 56, alignment::unaligned > little56_t;
+ typedef endian< little_endian, int_least64_t, 64, alignment::unaligned > little64_t;
+
+ // unaligned little endian unsigned integer types
+ typedef endian< little_endian, uint_least8_t, 8, alignment::unaligned > ulittle8_t;
+ typedef endian< little_endian, uint_least16_t, 16, alignment::unaligned > ulittle16_t;
+ typedef endian< little_endian, uint_least32_t, 24, alignment::unaligned > ulittle24_t;
+ typedef endian< little_endian, uint_least32_t, 32, alignment::unaligned > ulittle32_t;
+ typedef endian< little_endian, uint_least64_t, 40, alignment::unaligned > ulittle40_t;
+ typedef endian< little_endian, uint_least64_t, 48, alignment::unaligned > ulittle48_t;
+ typedef endian< little_endian, uint_least64_t, 56, alignment::unaligned > ulittle56_t;
+ typedef endian< little_endian, uint_least64_t, 64, alignment::unaligned > ulittle64_t;
+
+ // unaligned native endian signed integer types
+ typedef endian< native_endian, int_least8_t, 8, alignment::unaligned > native8_t;
+ typedef endian< native_endian, int_least16_t, 16, alignment::unaligned > native16_t;
+ typedef endian< native_endian, int_least32_t, 24, alignment::unaligned > native24_t;
+ typedef endian< native_endian, int_least32_t, 32, alignment::unaligned > native32_t;
+ typedef endian< native_endian, int_least64_t, 40, alignment::unaligned > native40_t;
+ typedef endian< native_endian, int_least64_t, 48, alignment::unaligned > native48_t;
+ typedef endian< native_endian, int_least64_t, 56, alignment::unaligned > native56_t;
+ typedef endian< native_endian, int_least64_t, 64, alignment::unaligned > native64_t;
+
+ // unaligned native endian unsigned integer types
+ typedef endian< native_endian, uint_least8_t, 8, alignment::unaligned > unative8_t;
+ typedef endian< native_endian, uint_least16_t, 16, alignment::unaligned > unative16_t;
+ typedef endian< native_endian, uint_least32_t, 24, alignment::unaligned > unative24_t;
+ typedef endian< native_endian, uint_least32_t, 32, alignment::unaligned > unative32_t;
+ typedef endian< native_endian, uint_least64_t, 40, alignment::unaligned > unative40_t;
+ typedef endian< native_endian, uint_least64_t, 48, alignment::unaligned > unative48_t;
+ typedef endian< native_endian, uint_least64_t, 56, alignment::unaligned > unative56_t;
+ typedef endian< native_endian, uint_least64_t, 64, alignment::unaligned > 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
+ // <cstdint> types are superior for this use case
+
+# if defined(BOOST_HAS_INT16_T)
+ typedef endian< big_endian, int16_t, 16, alignment::aligned > aligned_big16_t;
+ typedef endian< big_endian, uint16_t, 16, alignment::aligned > aligned_ubig16_t;
+ typedef endian< little_endian, int16_t, 16, alignment::aligned > aligned_little16_t;
+ typedef endian< little_endian, uint16_t, 16, alignment::aligned > aligned_ulittle16_t;
+# endif
+
+# if defined(BOOST_HAS_INT32_T)
+ typedef endian< big_endian, int32_t, 32, alignment::aligned > aligned_big32_t;
+ typedef endian< big_endian, uint32_t, 32, alignment::aligned > aligned_ubig32_t;
+ typedef endian< little_endian, int32_t, 32, alignment::aligned > aligned_little32_t;
+ typedef endian< little_endian, uint32_t, 32, alignment::aligned > aligned_ulittle32_t;
+# endif
+
+# if defined(BOOST_HAS_INT64_T)
+ typedef endian< big_endian, int64_t, 64, alignment::aligned > aligned_big64_t;
+ typedef endian< big_endian, uint64_t, 64, alignment::aligned > aligned_ubig64_t;
+ typedef endian< little_endian, int64_t, 64, alignment::aligned > aligned_little64_t;
+ typedef endian< little_endian, uint64_t, 64, alignment::aligned > aligned_ulittle64_t;
+# endif
+
+ template<typename OSTREAM, typename E,
+ typename T, std::size_t N,
+ BOOST_SCOPED_ENUM(alignment) A>
+ OSTREAM&
+ operator<<(OSTREAM & os,
+ const endian< E,T,N,A > & aval) {
+ os << T(aval);
+ return os;
+
+ }
+
+
+ } // namespace integer
+} // namespace boost
+
+#if defined(__BORLANDC__) || defined( __CODEGEARC__)
+# pragma pack(pop)
+#endif
+
+#if 0
+namespace std {
+ template <typename E,
+ typename T,
+ size_t N
+ > class numeric_limits<boost::integer::endian<E,T,N,boost::integer::alignment::aligned> >
+ {
+ typedef T value_type;
+ public:
+
+ BOOST_STATIC_CONSTANT(bool, is_specialized = true);
+ static value_type min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return numeric_limits<value_type>::(min)(); }
+ static value_type max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return numeric_limits<value_type>::(max)(); }
+ BOOST_STATIC_CONSTANT(int, digits = numeric_limits<value_type>::digits);
+ BOOST_STATIC_CONSTANT(int, digits10 = numeric_limits<value_type>::digits10);
+ BOOST_STATIC_CONSTANT(bool, is_signed = numeric_limits<value_type>::is_signed);
+ BOOST_STATIC_CONSTANT(bool, is_integer = numeric_limits<value_type>::is_integer);
+ BOOST_STATIC_CONSTANT(bool, is_exact = numeric_limits<value_type>::is_exact);
+ BOOST_STATIC_CONSTANT(int, radix = numeric_limits<value_type>::radix);
+ static value_type epsilon() throw() { return numeric_limits<value_type>::epsilon(); };
+ static value_type round_error() throw() { return numeric_limits<value_type>::round_error(); };
+
+ BOOST_STATIC_CONSTANT(int, min_exponent = numeric_limits<value_type>::min_exponent);
+ BOOST_STATIC_CONSTANT(int, min_exponent10 = numeric_limits<value_type>::min_exponent10);
+ BOOST_STATIC_CONSTANT(int, max_exponent = numeric_limits<value_type>::max_exponent);
+ BOOST_STATIC_CONSTANT(int, max_exponent10 = numeric_limits<value_type>::max_exponent10);
+
+ BOOST_STATIC_CONSTANT(bool, has_infinity = numeric_limits<value_type>::has_infinity);
+ BOOST_STATIC_CONSTANT(bool, has_quiet_NaN = numeric_limits<value_type>::has_quiet_NaN);
+ BOOST_STATIC_CONSTANT(bool, has_signaling_NaN = numeric_limits<value_type>::has_signaling_NaN);
+ BOOST_STATIC_CONSTANT(bool, has_denorm = numeric_limits<value_type>::has_denorm);
+ BOOST_STATIC_CONSTANT(bool, has_denorm_loss = numeric_limits<value_type>::has_denorm_loss);
+ static value_type infinity() throw() { return numeric_limits<value_type>::infinity(); };
+ static value_type quiet_NaN() throw() { return numeric_limits<value_type>::quiet_NaN(); };
+ static value_type signaling_NaN() throw() { return numeric_limits<value_type>::signaling_NaN(); };
+ static value_type denorm_min() throw() { return numeric_limits<value_type>::denorm_min(); };
+
+ BOOST_STATIC_CONSTANT(bool, is_iec559 = numeric_limits<value_type>::is_iec559);
+ BOOST_STATIC_CONSTANT(bool, is_bounded = numeric_limits<value_type>::is_bounded);
+ BOOST_STATIC_CONSTANT(bool, is_modulo = numeric_limits<value_type>::is_modulo);
+
+ BOOST_STATIC_CONSTANT(bool, traps = numeric_limits<value_type>::traps);
+ BOOST_STATIC_CONSTANT(bool, tinyness_before = numeric_limits<value_type>::tinyness_before);
+ BOOST_STATIC_CONSTANT(float_round_style, round_style = numeric_limits<value_type>::round_style);
+
+ };
+
+namespace std {
+ template <typename E,
+ typename T,
+ size_t N
+ > class numeric_limits<boost::integer::endian<E,T,N,boost::integer::alignment::aligned> >
+ {
+ typedef T value_type;
+ public:
+
+ BOOST_STATIC_CONSTANT(bool, is_specialized = true);
+ static value_type min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return numeric_limits<value_type>::(min)(); }
+ static value_type max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return numeric_limits<value_type>::(max)(); }
+ BOOST_STATIC_CONSTANT(int, digits = numeric_limits<value_type>::digits);
+ BOOST_STATIC_CONSTANT(int, digits10 = numeric_limits<value_type>::digits10);
+ BOOST_STATIC_CONSTANT(bool, is_signed = numeric_limits<value_type>::is_signed);
+ BOOST_STATIC_CONSTANT(bool, is_integer = numeric_limits<value_type>::is_integer);
+ BOOST_STATIC_CONSTANT(bool, is_exact = numeric_limits<value_type>::is_exact);
+ BOOST_STATIC_CONSTANT(int, radix = numeric_limits<value_type>::radix);
+ static value_type epsilon() throw() { return numeric_limits<value_type>::epsilon(); };
+ static value_type round_error() throw() { return numeric_limits<value_type>::round_error(); };
+
+ BOOST_STATIC_CONSTANT(int, min_exponent = numeric_limits<value_type>::min_exponent);
+ BOOST_STATIC_CONSTANT(int, min_exponent10 = numeric_limits<value_type>::min_exponent10);
+ BOOST_STATIC_CONSTANT(int, max_exponent = numeric_limits<value_type>::max_exponent);
+ BOOST_STATIC_CONSTANT(int, max_exponent10 = numeric_limits<value_type>::max_exponent10);
+
+ BOOST_STATIC_CONSTANT(bool, has_infinity = numeric_limits<value_type>::has_infinity);
+ BOOST_STATIC_CONSTANT(bool, has_quiet_NaN = numeric_limits<value_type>::has_quiet_NaN);
+ BOOST_STATIC_CONSTANT(bool, has_signaling_NaN = numeric_limits<value_type>::has_signaling_NaN);
+ BOOST_STATIC_CONSTANT(bool, has_denorm = numeric_limits<value_type>::has_denorm);
+ BOOST_STATIC_CONSTANT(bool, has_denorm_loss = numeric_limits<value_type>::has_denorm_loss);
+ static value_type infinity() throw() { return numeric_limits<value_type>::infinity(); };
+ static value_type quiet_NaN() throw() { return numeric_limits<value_type>::quiet_NaN(); };
+ static value_type signaling_NaN() throw() { return numeric_limits<value_type>::signaling_NaN(); };
+ static value_type denorm_min() throw() { return numeric_limits<value_type>::denorm_min(); };
+
+ BOOST_STATIC_CONSTANT(bool, is_iec559 = numeric_limits<value_type>::is_iec559);
+ BOOST_STATIC_CONSTANT(bool, is_bounded = numeric_limits<value_type>::is_bounded);
+ BOOST_STATIC_CONSTANT(bool, is_modulo = numeric_limits<value_type>::is_modulo);
+
+ BOOST_STATIC_CONSTANT(bool, traps = numeric_limits<value_type>::traps);
+ BOOST_STATIC_CONSTANT(bool, tinyness_before = numeric_limits<value_type>::tinyness_before);
+ BOOST_STATIC_CONSTANT(float_round_style, round_style = numeric_limits<value_type>::round_style);
+
+ };
+
+
+namespace std {
+ template <typename E,
+ typename T,
+ size_t N
+ > class numeric_limits<boost::integer::endian<E,T,N,boost::integer::alignment::unaligned> >
+ {
+ typedef T value_type;
+ public:
+
+ BOOST_STATIC_CONSTANT(bool, is_specialized = true);
+ static value_type min BOOST_PREVENT_MACRO_SUBSTITUTION (){
+ return numeric_limits<value_type>::is_signed
+ ? low_bit_mask<value_type, N>::value
+ : 0;
+ }
+ static value_type max BOOST_PREVENT_MACRO_SUBSTITUTION (){
+ return numeric_limits<value_type>::is_signed
+ ?low_bit_mask<value_type, N-1>::value
+ :low_bit_mask<value_type, N>::value;
+ }
+ BOOST_STATIC_CONSTANT(int, digits = N);
+ BOOST_STATIC_CONSTANT(int, digits10 = 2<<N);
+ BOOST_STATIC_CONSTANT(bool, is_signed = numeric_limits<value_type>::is_signed);
+ BOOST_STATIC_CONSTANT(bool, is_integer = numeric_limits<value_type>::is_integer);
+ BOOST_STATIC_CONSTANT(bool, is_exact = numeric_limits<value_type>::is_exact);
+ BOOST_STATIC_CONSTANT(int, radix = numeric_limits<value_type>::radix);
+ static value_type epsilon() throw() { return numeric_limits<value_type>::epsilon(); };
+ static value_type round_error() throw() { return numeric_limits<value_type>::round_error(); };
+
+ BOOST_STATIC_CONSTANT(int, min_exponent = numeric_limits<value_type>::min_exponent);
+ BOOST_STATIC_CONSTANT(int, min_exponent10 = numeric_limits<value_type>::min_exponent10);
+ BOOST_STATIC_CONSTANT(int, max_exponent = numeric_limits<value_type>::max_exponent);
+ BOOST_STATIC_CONSTANT(int, max_exponent10 = numeric_limits<value_type>::max_exponent10);
+
+ BOOST_STATIC_CONSTANT(bool, has_infinity = numeric_limits<value_type>::has_infinity);
+ BOOST_STATIC_CONSTANT(bool, has_quiet_NaN = numeric_limits<value_type>::has_quiet_NaN);
+ BOOST_STATIC_CONSTANT(bool, has_signaling_NaN = numeric_limits<value_type>::has_signaling_NaN);
+ BOOST_STATIC_CONSTANT(bool, has_denorm = numeric_limits<value_type>::has_denorm);
+ BOOST_STATIC_CONSTANT(bool, has_denorm_loss = numeric_limits<value_type>::has_denorm_loss);
+ static value_type infinity() throw() { return numeric_limits<value_type>::infinity(); };
+ static value_type quiet_NaN() throw() { return numeric_limits<value_type>::quiet_NaN(); };
+ static value_type signaling_NaN() throw() { return numeric_limits<value_type>::signaling_NaN(); };
+ static value_type denorm_min() throw() { return numeric_limits<value_type>::denorm_min(); };
+
+ BOOST_STATIC_CONSTANT(bool, is_iec559 = numeric_limits<value_type>::is_iec559);
+ BOOST_STATIC_CONSTANT(bool, is_bounded = numeric_limits<value_type>::is_bounded);
+ BOOST_STATIC_CONSTANT(bool, is_modulo = numeric_limits<value_type>::is_modulo);
+
+ BOOST_STATIC_CONSTANT(bool, traps = numeric_limits<value_type>::traps);
+ BOOST_STATIC_CONSTANT(bool, tinyness_before = numeric_limits<value_type>::tinyness_before);
+ BOOST_STATIC_CONSTANT(float_round_style, round_style = numeric_limits<value_type>::round_style);
+
+ };
+
+
+} // namespace std
+
+#endif
+#endif // BOOST_ENDIAN_HPP
Added: sandbox/endian_ext/boost/integer/endian/endian_binary_stream.hpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/boost/integer/endian/endian_binary_stream.hpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,130 @@
+// boost/integer/endian_binary_stream.hpp --------------------------------------------//
+
+// Copyright Beman Dawes 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/integer/endian
+
+#ifndef BOOST_ENDIAN_BINARY_STREAM_HPP
+#define BOOST_ENDIAN_BINARY_STREAM_HPP
+
+#include <boost/integer/endian/endian.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <ostream>
+#include <istream>
+
+// unformatted binary (as opposed to formatted character) stream insertion
+// and extraction.
+
+// Warning: Use only on streams opened with filemode std::ios_base::binary. Thus
+// unformatted binary I/O should not be with the standard streams (cout, cin, etc.)
+// since they are opened in text mode. Use on text streams may produce incorrect
+// results, such as insertion of unwanted characters or premature end-of-file.
+// For example, on Windows 0x0D would become 0x0D, 0x0A.
+
+// Caution: When mixing formatted (i.e. operator << or >>) and unformatted (i.e.
+// operator <= or >=) be aware that << and >> take precedence over <= and >=. Use
+// parentheses to force correct order of evaluation. For example:
+//
+// my_stream << foo <= bar; // no parentheses needed
+// (my_stream <= foo) << bar; // parentheses required
+
+// This implementation uses reinterpret_cast<>() when needed to convert one pointer
+// type to another. See 5.2.10 [expr.reinterpret.cast], Reinterpret cast, para 7.
+
+namespace boost
+{
+ namespace integer
+ {
+ template< class T > struct is_endian { static const bool value = false; };
+
+ #if 1
+ template<typename E,
+ typename T,
+ std::size_t N,
+ BOOST_SCOPED_ENUM(alignment) A>
+ struct is_endian<endian_pack<E,T,N,A> > { static const bool value = true; };
+ template<typename E,
+ typename T,
+ std::size_t N,
+ BOOST_SCOPED_ENUM(alignment) A>
+ struct is_endian<endian<E,T,N,A> > { static const bool value = true; };
+ #else
+ template<> struct is_endian<big8_t> { static const bool value = true; };
+ template<> struct is_endian<big16_t> { static const bool value = true; };
+ template<> struct is_endian<big24_t> { static const bool value = true; };
+ template<> struct is_endian<big32_t> { static const bool value = true; };
+ template<> struct is_endian<big40_t> { static const bool value = true; };
+ template<> struct is_endian<big48_t> { static const bool value = true; };
+ template<> struct is_endian<big56_t> { static const bool value = true; };
+ template<> struct is_endian<big64_t> { static const bool value = true; };
+
+ template<> struct is_endian<ubig8_t> { static const bool value = true; };
+ template<> struct is_endian<ubig16_t> { static const bool value = true; };
+ template<> struct is_endian<ubig24_t> { static const bool value = true; };
+ template<> struct is_endian<ubig32_t> { static const bool value = true; };
+ template<> struct is_endian<ubig40_t> { static const bool value = true; };
+ template<> struct is_endian<ubig48_t> { static const bool value = true; };
+ template<> struct is_endian<ubig56_t> { static const bool value = true; };
+ template<> struct is_endian<ubig64_t> { static const bool value = true; };
+
+ template<> struct is_endian<little8_t> { static const bool value = true; };
+ template<> struct is_endian<little16_t> { static const bool value = true; };
+ template<> struct is_endian<little24_t> { static const bool value = true; };
+ template<> struct is_endian<little32_t> { static const bool value = true; };
+ template<> struct is_endian<little40_t> { static const bool value = true; };
+ template<> struct is_endian<little48_t> { static const bool value = true; };
+ template<> struct is_endian<little56_t> { static const bool value = true; };
+ template<> struct is_endian<little64_t> { static const bool value = true; };
+
+ template<> struct is_endian<ulittle8_t> { static const bool value = true; };
+ template<> struct is_endian<ulittle16_t> { static const bool value = true; };
+ template<> struct is_endian<ulittle24_t> { static const bool value = true; };
+ template<> struct is_endian<ulittle32_t> { static const bool value = true; };
+ template<> struct is_endian<ulittle40_t> { static const bool value = true; };
+ template<> struct is_endian<ulittle48_t> { static const bool value = true; };
+ template<> struct is_endian<ulittle56_t> { static const bool value = true; };
+ template<> struct is_endian<ulittle64_t> { static const bool value = true; };
+
+ # if defined(BOOST_HAS_INT16_T)
+ template<> struct is_endian<aligned_big16_t> { static const bool value = true; };
+ template<> struct is_endian<aligned_ubig16_t> { static const bool value = true; };
+ template<> struct is_endian<aligned_little16_t> { static const bool value = true; };
+ template<> struct is_endian<aligned_ulittle16_t> { static const bool value = true; };
+# endif
+
+# if defined(BOOST_HAS_INT32_T)
+ template<> struct is_endian<aligned_big32_t> { static const bool value = true; };
+ template<> struct is_endian<aligned_ubig32_t> { static const bool value = true; };
+ template<> struct is_endian<aligned_little32_t> { static const bool value = true; };
+ template<> struct is_endian<aligned_ulittle32_t> { static const bool value = true; };
+# endif
+
+# if defined(BOOST_HAS_INT64_T)
+ template<> struct is_endian<aligned_big64_t> { static const bool value = true; };
+ template<> struct is_endian<aligned_ubig64_t> { static const bool value = true; };
+ template<> struct is_endian<aligned_little64_t> { static const bool value = true; };
+ template<> struct is_endian<aligned_ulittle64_t> { static const bool value = true; };
+# endif
+ #endif
+
+ template < class Endian >
+ inline typename boost::enable_if< is_endian<Endian>, std::ostream & >::type
+ operator<=( std::ostream & os, const Endian & e )
+ {
+ return os.write( e.data(), sizeof(e) );
+ }
+
+ template < class Endian >
+ inline typename boost::enable_if< is_endian<Endian>, std::istream & >::type
+ operator>=( std::istream & is, Endian & e )
+ {
+ return is.read( reinterpret_cast<char*>(&e), sizeof(e) );
+ }
+
+ } // namespace integer
+} // namespace boost
+
+#endif // BOOST_ENDIAN_BINARY_STREAM_HPP
Added: sandbox/endian_ext/boost/integer/endian/endian_conversion.hpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/boost/integer/endian/endian_conversion.hpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,227 @@
+// Boost endian_view.hpp header file -------------------------------------------------------//
+
+// (C) Copyright VicenteJ Botet Escriba 2010-20111
+
+// 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/integer/endian
+
+//--------------------------------------------------------------------------------------//
+
+
+#ifndef BOOST_INTEGER_ENDIAN_CONVERT_HPP
+#define BOOST_INTEGER_ENDIAN_CONVERT_HPP
+
+#include <boost/integer/endian/endianness.hpp>
+#include <boost/integer/endian/domain_map.hpp>
+#include <boost/mpl/deref.hpp>
+#include <boost/mpl/next.hpp>
+#include <boost/mpl/begin.hpp>
+#include <boost/mpl/end.hpp>
+#include <boost/fusion/include/deref.hpp>
+#include <boost/fusion/include/next.hpp>
+#include <boost/fusion/include/begin.hpp>
+#include <boost/fusion/include/end.hpp>
+#include <boost/fusion/include/is_sequence.hpp>
+#include <boost/type_traits/is_fundamental.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+#include <boost/type_traits/remove_cv.hpp>
+
+#include <boost/integer/endian/endian_view.hpp>
+
+namespace boost {
+namespace integer {
+
+ template <typename EndianTarget, typename EndianSource, typename T>
+ inline void convert_to_from(T& r);
+
+ template <typename EndianTarget, typename EndianSource, typename T>
+ inline void convert_to_from_impl(T& r);
+
+ namespace integer_detail {
+ template <typename EndianTarget, typename EndianSource, typename T,
+ bool IsFundamental = is_fundamental<T>::value,
+ bool IsSeq = fusion::traits::is_sequence<T>::value
+ >
+ struct convert_to_from;
+
+ template <
+ typename ItTarget, typename EndTarget,
+ typename ItSource, typename EndSource>
+ struct convert_to_from_seq_loop {
+ template <typename It, typename End>
+ static void apply(It& it, End& end) {
+ boost::integer::convert_to_from_impl<
+ typename mpl::deref<ItTarget>::type,
+ typename mpl::deref<ItSource>::type,
+ typename remove_reference<typename remove_cv<typename fusion::result_of::deref<It>::type>::type >::type
+ >
+ (fusion::deref(it));
+ convert_to_from_seq_loop<
+ typename mpl::next<ItTarget>::type, EndTarget,
+ typename mpl::next<ItSource>::type, EndSource
+ >::apply(fusion::next(it), end);
+ }
+ };
+
+ template <typename EndTarget, typename EndSource>
+ struct convert_to_from_seq_loop<EndTarget, EndTarget, EndSource, EndSource> {
+ template <typename It, typename End>
+ static void apply(It& , End& ) {
+ }
+ };
+
+ template <typename EndianTarget, typename EndianSource, typename T>
+ struct convert_to_from_seq {
+ static void apply(T& r) {
+ convert_to_from_seq_loop<
+ typename mpl::begin<EndianTarget>::type,
+ typename mpl::end<EndianTarget>::type,
+ typename mpl::begin<EndianSource>::type,
+ typename mpl::end<EndianSource>::type >
+ ::apply(fusion::begin(r), fusion::end(r));
+
+ }
+ };
+
+ // same endianess do nothiong
+ template <typename E, typename T, bool IsFundamental, bool IsSeq>
+ struct convert_to_from<E, E, T, IsFundamental, IsSeq> {
+ static void apply(T& ) {
+ }
+ };
+
+ template <typename E, typename T>
+ struct convert_to_from<E, E, T, false, false> {
+ static void apply(T& ) {
+ }
+ };
+
+ template <typename E, typename T>
+ struct convert_to_from<E,E,T,false,true> {
+ static void apply(T& ) {
+ }
+ };
+
+ // on fundamentals apply endian views
+ template <typename T>
+ struct convert_to_from<endianness::big, endianness::little, T, true, false> {
+ static void apply(T& r) {
+ as_big(r)=as_little(r);
+ }
+ };
+ // on fundamentals apply endian views
+ template <typename T>
+ struct convert_to_from<endianness::little, endianness::big, T, true, false> {
+ static void apply(T& r) {
+ as_little(r)=as_big(r);
+ }
+ };
+ template <typename EndianTarget, typename EndianSource, typename T>
+ struct convert_to_from<EndianTarget, EndianSource, T, false, true>
+ : convert_to_from_seq<EndianTarget,EndianSource,T> {};
+
+ template <typename EndianTarget, typename EndianSource, typename T>
+ struct convert_to_from<EndianTarget, EndianSource, T, false, false> {
+ static void apply(T& ) {
+ }
+ //~ template <typename T>
+ //~ static void apply(T& r) {
+ //~ //use ADL to find this
+ //~ convert_to_from_impl<EndianTarget,EndianSource,T>(r);
+ //~ }
+ };
+
+ } // namespace integer_detail
+
+template <typename EndianTarget, typename EndianSource, typename T>
+inline void convert_to_from_impl(T& r) {
+ integer_detail::convert_to_from<
+ EndianTarget,
+ EndianSource,
+ T
+ >::apply(r);
+}
+
+template <typename EndianTarget, typename EndianSource, typename T>
+void convert_to_from(T& r) {
+ integer_detail::convert_to_from<
+ typename endianness::domain_map<EndianTarget,T>::type,
+ typename endianness::domain_map<EndianSource,T>::type,
+ T
+ >::apply(r);
+}
+
+template <typename Endian>
+struct to {
+ typedef Endian type;
+};
+
+template <typename Endian>
+struct from {
+ typedef Endian type;
+};
+
+template <typename Endian>
+struct is_to : mpl::false_ {};
+template <typename Endian>
+struct is_to<to<Endian> > : mpl::true_ {};
+
+template <typename Endian>
+struct is_from : mpl::false_ {};
+template <typename Endian>
+struct is_from<from<Endian> > : mpl::true_ {};
+
+
+template <typename Endian1, typename Endian2, typename T>
+void convert(T& r) {
+ typedef
+ typename mpl::if_<is_to<Endian1>, typename Endian1::type,
+ typename mpl::if_<is_to<Endian2>, typename Endian2::type,
+ void
+ >::type
+ >::type EndianTarget;
+ typedef
+ typename mpl::if_<is_from<Endian1>, typename Endian1::type,
+ typename mpl::if_<is_from<Endian2>, typename Endian2::type,
+ void
+ >::type
+ >::type EndianSource;
+
+ integer_detail::convert_to_from<
+ typename endianness::domain_map<EndianTarget,T>::type,
+ typename endianness::domain_map<EndianSource,T>::type,
+ T
+ >::apply(r);
+}
+
+
+//~ template <typename EndianTarget, typename EndianSource, typename T, typename N>
+//~ void convert_to_from(T[N] a) {
+ //~ for (unsigned int i=0; i<N; ++i) {
+ //~ convert_to_from<EndianTarget, EndianSource, T>(a[i]);
+ //~ }
+//~ }
+
+template <typename EndianSource, typename T>
+void convert_from(T& r) {
+ integer_detail::convert_to_from<
+ typename endianness::domain_map<endianness::native,T>::type,
+ typename endianness::domain_map<EndianSource,T>::type,
+ T>::apply(r);
+}
+
+template <typename EndianTarget, typename T>
+void convert_to(T& r) {
+ integer_detail::convert_to_from<
+ typename endianness::domain_map<EndianTarget,T>::type,
+ typename endianness::domain_map<endianness::native, T>::type,
+ T>::apply(r);
+}
+
+} // namespace integer
+} // namespace boost
+
+
+#endif // BOOST_INTEGER_ENDIAN_CONVERT_HPP
Added: sandbox/endian_ext/boost/integer/endian/endian_flip.hpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/boost/integer/endian/endian_flip.hpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,96 @@
+// endian_flip.hpp -------------------------------------------------------------------//
+
+// Copyright Beman Dawes 2010
+
+// Distributed under the Boost Software License, Version 1.0.
+// http://www.boost.org/LICENSE_1_0.txt
+
+#ifndef BOOST_ENDIAN_FLIP_HPP
+#define BOOST_ENDIAN_FLIP_HPP
+
+#include <boost/integer.hpp>
+namespace boost
+{
+namespace integer
+{
+ inline void endian_flip(int16_t& x)
+ {
+ char* rep = reinterpret_cast<char*>(&x);
+ char tmp;
+ tmp = *rep;
+ *rep = *(rep+1);
+ *(rep+1) = tmp;
+ }
+
+ inline void endian_flip(int32_t& x)
+ {
+ char* rep = reinterpret_cast<char*>(&x);
+ char tmp;
+ tmp = *rep;
+ *rep = *(rep+3);
+ *(rep+3) = tmp;
+ tmp = *(rep+1);
+ *(rep+1) = *(rep+2);
+ *(rep+2) = tmp;
+ }
+
+ inline void endian_flip(int64_t& x)
+ {
+ char* rep = reinterpret_cast<char*>(&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 endian_flip(uint16_t& x)
+ {
+ char* rep = reinterpret_cast<char*>(&x);
+ char tmp;
+ tmp = *rep;
+ *rep = *(rep+1);
+ *(rep+1) = tmp;
+ }
+
+ inline void endian_flip(uint32_t& x)
+ {
+ char* rep = reinterpret_cast<char*>(&x);
+ char tmp;
+ tmp = *rep;
+ *rep = *(rep+3);
+ *(rep+3) = tmp;
+ tmp = *(rep+1);
+ *(rep+1) = *(rep+2);
+ *(rep+2) = tmp;
+ }
+
+ inline void endian_flip(uint64_t& x)
+ {
+ char* rep = reinterpret_cast<char*>(&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;
+ }
+} // namespace integer
+} // namespace boost
+
+#endif // BOOST_ENDIAN_FLIP_HPP
Added: sandbox/endian_ext/boost/integer/endian/endian_pack.hpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/boost/integer/endian/endian_pack.hpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,515 @@
+// Boost endian_pack.hpp header file -------------------------------------------------------//
+
+// (C) Copyright Darin Adler 2000
+// (C) Copyright Beman Dawes 2006, 2009
+// (C) Copyright VicenteJ Botet Escriba 2010-20111
+
+// 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/integer/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.
+
+// Split of endian.hpp into endian.hpp and endian_pack.hpp done by Vicente J. Botet Escriba.
+// Definition of native depending on BOOST_BIG_ENDIAN to big or little done by Vicente J. Botet Escriba.
+// Change the definition of endian_pack using types instead of enum endianness done by Vicente J. Botet Escriba.
+
+// TODO: When a compiler supporting constexpr becomes available, try possible uses.
+#define BOOST_ENDIAN_ALLOWS_UDT
+
+#ifndef BOOST_INTEGER_ENDIAN_PACK_HPP
+#define BOOST_INTEGER_ENDIAN_PACK_HPP
+
+#ifdef BOOST_ENDIAN_LOG
+# include <iostream>
+#endif
+
+#if defined(__BORLANDC__) || defined( __CODEGEARC__)
+# pragma pack(push, 1)
+#endif
+
+#include <boost/config.hpp>
+#include <boost/type_traits/is_signed.hpp>
+//#include <climits>
+#include <boost/integer_traits.hpp>
+#include <boost/cstdint.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/detail/scoped_enum_emulation.hpp>
+//~ #include <iosfwd>
+#include <climits>
+#include <algorithm>
+
+# include <boost/integer/endian/endianness.hpp>
+
+# 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 <typename T, std::size_t n_bytes,
+ bool sign=boost::is_signed<T>::value >
+ struct unrolled_byte_loops
+ {
+ typedef unrolled_byte_loops<T, n_bytes - 1, sign> 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<char>(value);
+ next::store_big(bytes - 1, value >> 8);
+ }
+ static void store_little(char* bytes, T value)
+ {
+ *bytes = static_cast<char>(value);
+ next::store_little(bytes + 1, value >> 8);
+ }
+ };
+
+ template <typename T>
+ struct unrolled_byte_loops<T, 1, false>
+ {
+ 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<char>(value); }
+ static void store_little(char* bytes, T value)
+ { *bytes = static_cast<char>(value); }
+
+ };
+
+ template <typename T>
+ struct unrolled_byte_loops<T, 1, true>
+ {
+ static T load_big(const unsigned char* bytes)
+ { return *reinterpret_cast<const signed char*>(bytes - 1); }
+ static T load_little(const unsigned char* bytes)
+ { return *reinterpret_cast<const signed char*>(bytes); }
+ static void store_big(char* bytes, T value)
+ { *(bytes - 1) = static_cast<char>(value); }
+ static void store_little(char* bytes, T value)
+ { *bytes = static_cast<char>(value); }
+ };
+
+ template <typename T, std::size_t n_bytes>
+ inline
+ T load_big_endian(const void* bytes)
+ {
+ return unrolled_byte_loops<T, n_bytes>::load_big
+ (static_cast<const unsigned char*>(bytes) + n_bytes);
+ }
+
+ template <typename T, std::size_t n_bytes>
+ inline
+ T load_little_endian(const void* bytes)
+ {
+ return unrolled_byte_loops<T, n_bytes>::load_little
+ (static_cast<const unsigned char*>(bytes));
+ }
+
+ template <typename T, std::size_t n_bytes>
+ inline
+ void store_big_endian(void* bytes, T value)
+ {
+ unrolled_byte_loops<T, n_bytes>::store_big
+ (static_cast<char*>(bytes) + n_bytes, value);
+ }
+
+ template <typename T, std::size_t n_bytes>
+ inline
+ void store_little_endian(void* bytes, T value)
+ {
+ unrolled_byte_loops<T, n_bytes>::store_little
+ (static_cast<char*>(bytes), value);
+ }
+
+ ///////////////////////
+ template<std::size_t L> inline
+ void unrolled_reverse_copy(char* dst, const char* src) {
+ *dst = *src;
+ unrolled_reverse_copy<L-1>(dst+1, src-1);
+ } // unrolled_reverse_copy
+
+ template<> inline void unrolled_reverse_copy<1>(char* dst, const char* src)
+ { *dst = *src; }
+
+ template<> inline void unrolled_reverse_copy<0>(char*, const char*) { }
+
+ template<std::size_t L, bool>
+ struct reverse_copy_helper {
+ static void copy(char* dst, const char* src)
+ { std::reverse_copy(src, src+L, dst); }
+ };
+
+ template<std::size_t L>
+ struct reverse_copy_helper<L, true> {
+ static void copy(char* dst, const char* src)
+ { unrolled_reverse_copy<L>(dst, src+(L-1)); }
+ };
+
+ template<std::size_t L> inline
+ void reverse_copy(void* dst, const void* src) {
+ reverse_copy_helper< L, (L<=16) >::copy(static_cast<char*>(dst),
+ static_cast<const char*>(src));
+ }
+
+ } // namespace detail
+
+ namespace integer
+ {
+
+# ifdef BOOST_ENDIAN_LOG
+ bool endian_log(true);
+# endif
+
+
+ BOOST_SCOPED_ENUM_START(alignment) { unaligned, aligned }; BOOST_SCOPED_ENUM_END
+
+ template <typename E,
+ typename T,
+ std::size_t n_bits=sizeof(T)*8,
+ BOOST_SCOPED_ENUM(alignment) A = alignment::aligned
+ > class endian_pack;
+
+ // 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 <typename T, std::size_t n_bits>
+ class endian_pack<big_endian, T, n_bits, alignment::unaligned >
+
+ {
+ BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
+ public:
+ typedef big_endian endian_type;
+ typedef T value_type;
+ static const std::size_t width = n_bits;
+ static const BOOST_SCOPED_ENUM(alignment) alignment_value = alignment::unaligned;
+# ifndef BOOST_ENDIAN_NO_CTORS
+ endian_pack() BOOST_ENDIAN_DEFAULT_CONSTRUCT
+ template <typename T2>
+ explicit endian_pack(T2 val)
+ //~ explicit endian_pack(T val)
+ {
+# ifdef BOOST_ENDIAN_LOG
+ if ( endian_log )
+ std::clog << "big, unaligned, " << n_bits << "-bits, construct(" << val << ")\n";
+# endif
+ boost::detail::store_big_endian<T, n_bits/8>(m_value, val);
+ }
+# endif
+ endian_pack & operator=(T val) { boost::detail::store_big_endian<T, n_bits/8>(m_value, val); return *this; }
+ operator T() const
+ {
+# ifdef BOOST_ENDIAN_LOG
+ if ( endian_log )
+ std::clog << "big, unaligned, " << n_bits << "-bits, convert(" << boost::detail::load_big_endian<T, n_bits/8>(m_value) << ")\n";
+# endif
+ return boost::detail::load_big_endian<T, n_bits/8>(m_value);
+ }
+ const char* data() const { return m_value; }
+ private:
+ char m_value[n_bits/8];
+ };
+
+ // unaligned little endian specialization
+ template <typename T, std::size_t n_bits>
+ class endian_pack< little_endian, T, n_bits, alignment::unaligned >
+ {
+ BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
+ public:
+ typedef little_endian endian_type;
+ typedef T value_type;
+ static const std::size_t width = n_bits;
+ static const BOOST_SCOPED_ENUM(alignment) alignment_value = alignment::unaligned;
+# ifndef BOOST_ENDIAN_NO_CTORS
+ endian_pack() BOOST_ENDIAN_DEFAULT_CONSTRUCT
+ explicit endian_pack(T val)
+ {
+# ifdef BOOST_ENDIAN_LOG
+ if ( endian_log )
+ std::clog << "little, unaligned, " << n_bits << "-bits, construct(" << val << ")\n";
+# endif
+ boost::detail::store_little_endian<T, n_bits/8>(m_value, val);
+ }
+# endif
+ endian_pack & operator=(T val) { detail::store_little_endian<T, n_bits/8>(m_value, val); return *this; }
+ operator T() const
+ {
+# ifdef BOOST_ENDIAN_LOG
+ if ( endian_log )
+ std::clog << "little, unaligned, " << n_bits << "-bits, convert(" << boost::detail::load_little_endian<T, n_bits/8>(m_value) << ")\n";
+# endif
+ return boost::detail::load_little_endian<T, n_bits/8>(m_value);
+ }
+ 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.
+
+#if defined(BOOST_ENDIAN_ALLOWS_UDT)
+ // aligned endian specialization
+ template <typename E, typename T, std::size_t n_bits>
+ class endian_pack< E, T, n_bits, alignment::aligned >
+ {
+ BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
+ BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 );
+ public:
+ typedef E endian_type;
+ typedef T value_type;
+ private:
+ void store(const value_type& v)
+ { detail::reverse_copy<sizeof(value_type)>(m_value, &v); }
+
+ void retrieve(value_type* result) const
+ { detail::reverse_copy<sizeof(value_type)>(result, m_value); }
+ public:
+ static const std::size_t width = n_bits;
+ static const BOOST_SCOPED_ENUM(alignment) alignment_value = alignment::aligned;
+# ifndef BOOST_ENDIAN_NO_CTORS
+ endian_pack() BOOST_ENDIAN_DEFAULT_CONSTRUCT
+ explicit endian_pack(T val) { store(val); }
+# endif
+ endian_pack & operator=(T val) { store(val); return *this; }
+ operator T() const { value_type rval; retrieve(&rval); return rval; }
+ //~ const char* data() const { return reinterpret_cast<const char *>(&m_value); }
+ const char* data() const { return m_value; }
+ private:
+ //~ T m_value;
+ char m_value[sizeof(value_type)];
+ };
+
+ // aligned native endian specialization
+ template <typename T, std::size_t n_bits>
+ class endian_pack< native_endian, T, n_bits, alignment::aligned >
+ {
+ BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
+ BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 );
+ public:
+ typedef native_endian endian_type;
+ typedef T value_type;
+ static const std::size_t width = n_bits;
+ static const BOOST_SCOPED_ENUM(alignment) alignment_value = alignment::aligned;
+# ifndef BOOST_ENDIAN_NO_CTORS
+ endian_pack() BOOST_ENDIAN_DEFAULT_CONSTRUCT
+ explicit endian_pack(T val) : m_value(val) { }
+# endif
+ endian_pack & operator=(T val) { m_value = val; return *this; }
+ operator T() const { return m_value; }
+ const char* data() const { return reinterpret_cast<const char *>(&m_value); }
+ private:
+ T m_value;
+ };
+#else
+ // aligned big endian specialization
+ template <typename T, std::size_t n_bits>
+ class endian_pack< big_endian, T, n_bits, alignment::aligned >
+ {
+ BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
+ BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 );
+ public:
+ typedef big_endian endian_type;
+ typedef T value_type;
+ static const std::size_t width = n_bits;
+ static const BOOST_SCOPED_ENUM(alignment) alignment_value = alignment::aligned;
+# ifndef BOOST_ENDIAN_NO_CTORS
+ endian_pack() BOOST_ENDIAN_DEFAULT_CONSTRUCT
+# ifdef BOOST_BIG_ENDIAN
+ explicit endian_pack(T val) : m_value(val) { }
+# else
+ explicit endian_pack(T val) { boost::detail::store_big_endian<T, sizeof(T)>(&m_value, val); }
+# endif
+# endif
+# ifdef BOOST_BIG_ENDIAN
+ endian_pack & operator=(T val) { m_value = val); return *this; }
+ operator T() const { return m_value; }
+# else
+ endian_pack & operator=(T val) { boost::detail::store_big_endian<T, sizeof(T)>(&m_value, val); return *this; }
+ operator T() const { return boost::detail::load_big_endian<T, sizeof(T)>(&m_value); }
+# endif
+ const char* data() const { return reinterpret_cast<const char *>(&m_value); }
+ private:
+ T m_value;
+ };
+
+ // aligned little endian specialization
+ template <typename T, std::size_t n_bits>
+ class endian_pack< little_endian, T, n_bits, alignment::aligned >
+ {
+ BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
+ BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 );
+ public:
+ typedef little_endian endian_type;
+ typedef T value_type;
+ static const std::size_t width = n_bits;
+ static const BOOST_SCOPED_ENUM(alignment) alignment_value = alignment::aligned;
+# ifndef BOOST_ENDIAN_NO_CTORS
+ endian_pack() BOOST_ENDIAN_DEFAULT_CONSTRUCT
+# ifdef BOOST_LITTLE_ENDIAN
+ explicit endian_pack(T val) : m_value(val) { }
+# else
+ explicit endian_pack(T val) { boost::detail::store_little_endian<T, sizeof(T)>(&m_value, val); }
+# endif
+# endif
+# ifdef BOOST_LITTLE_ENDIAN
+ endian_pack & operator=(T val) { m_value = val; return *this; }
+ operator T() const { return m_value; }
+ #else
+ endian_pack & operator=(T val) { boost::detail::store_little_endian<T, sizeof(T)>(&m_value, val); return *this; }
+ operator T() const { return boost::detail::load_little_endian<T, sizeof(T)>(&m_value); }
+ #endif
+ const char* data() const { return reinterpret_cast<const char *>(&m_value); }
+ private:
+ T m_value;
+ };
+#endif
+
+ // naming convention typedefs ------------------------------------------------------//
+
+ // unaligned big endian_pack signed integer types
+ typedef endian_pack< big_endian, int_least8_t, 8, alignment::unaligned > big8_pt;
+ typedef endian_pack< big_endian, int_least16_t, 16, alignment::unaligned > big16_pt;
+ typedef endian_pack< big_endian, int_least32_t, 24, alignment::unaligned > big24_pt;
+ typedef endian_pack< big_endian, int_least32_t, 32, alignment::unaligned > big32_pt;
+ typedef endian_pack< big_endian, int_least64_t, 40, alignment::unaligned > big40_pt;
+ typedef endian_pack< big_endian, int_least64_t, 48, alignment::unaligned > big48_pt;
+ typedef endian_pack< big_endian, int_least64_t, 56, alignment::unaligned > big56_pt;
+ typedef endian_pack< big_endian, int_least64_t, 64, alignment::unaligned > big64_pt;
+
+ // unaligned big endian_pack unsigned integer types
+ typedef endian_pack< big_endian, uint_least8_t, 8, alignment::unaligned > ubig8_pt;
+ typedef endian_pack< big_endian, uint_least16_t, 16, alignment::unaligned > ubig16_pt;
+ typedef endian_pack< big_endian, uint_least32_t, 24, alignment::unaligned > ubig24_pt;
+ typedef endian_pack< big_endian, uint_least32_t, 32, alignment::unaligned > ubig32_pt;
+ typedef endian_pack< big_endian, uint_least64_t, 40, alignment::unaligned > ubig40_pt;
+ typedef endian_pack< big_endian, uint_least64_t, 48, alignment::unaligned > ubig48_pt;
+ typedef endian_pack< big_endian, uint_least64_t, 56, alignment::unaligned > ubig56_pt;
+ typedef endian_pack< big_endian, uint_least64_t, 64, alignment::unaligned > ubig64_pt;
+
+ // unaligned little endian_pack signed integer types
+ typedef endian_pack< little_endian, int_least8_t, 8, alignment::unaligned > little8_pt;
+ typedef endian_pack< little_endian, int_least16_t, 16, alignment::unaligned > little16_pt;
+ typedef endian_pack< little_endian, int_least32_t, 24, alignment::unaligned > little24_pt;
+ typedef endian_pack< little_endian, int_least32_t, 32, alignment::unaligned > little32_pt;
+ typedef endian_pack< little_endian, int_least64_t, 40, alignment::unaligned > little40_pt;
+ typedef endian_pack< little_endian, int_least64_t, 48, alignment::unaligned > little48_pt;
+ typedef endian_pack< little_endian, int_least64_t, 56, alignment::unaligned > little56_pt;
+ typedef endian_pack< little_endian, int_least64_t, 64, alignment::unaligned > little64_pt;
+
+ // unaligned little endian_pack unsigned integer types
+ typedef endian_pack< little_endian, uint_least8_t, 8, alignment::unaligned > ulittle8_pt;
+ typedef endian_pack< little_endian, uint_least16_t, 16, alignment::unaligned > ulittle16_pt;
+ typedef endian_pack< little_endian, uint_least32_t, 24, alignment::unaligned > ulittle24_pt;
+ typedef endian_pack< little_endian, uint_least32_t, 32, alignment::unaligned > ulittle32_pt;
+ typedef endian_pack< little_endian, uint_least64_t, 40, alignment::unaligned > ulittle40_pt;
+ typedef endian_pack< little_endian, uint_least64_t, 48, alignment::unaligned > ulittle48_pt;
+ typedef endian_pack< little_endian, uint_least64_t, 56, alignment::unaligned > ulittle56_pt;
+ typedef endian_pack< little_endian, uint_least64_t, 64, alignment::unaligned > ulittle64_pt;
+
+ // unaligned native endian_pack signed integer types
+ typedef endian_pack< native_endian, int_least8_t, 8, alignment::unaligned > native8_pt;
+ typedef endian_pack< native_endian, int_least16_t, 16, alignment::unaligned > native16_pt;
+ typedef endian_pack< native_endian, int_least32_t, 24, alignment::unaligned > native24_pt;
+ typedef endian_pack< native_endian, int_least32_t, 32, alignment::unaligned > native32_pt;
+ typedef endian_pack< native_endian, int_least64_t, 40, alignment::unaligned > native40_pt;
+ typedef endian_pack< native_endian, int_least64_t, 48, alignment::unaligned > native48_pt;
+ typedef endian_pack< native_endian, int_least64_t, 56, alignment::unaligned > native56_pt;
+ typedef endian_pack< native_endian, int_least64_t, 64, alignment::unaligned > native64_pt;
+
+ // unaligned native endian_pack unsigned integer types
+ typedef endian_pack< native_endian, uint_least8_t, 8, alignment::unaligned > unative8_pt;
+ typedef endian_pack< native_endian, uint_least16_t, 16, alignment::unaligned > unative16_pt;
+ typedef endian_pack< native_endian, uint_least32_t, 24, alignment::unaligned > unative24_pt;
+ typedef endian_pack< native_endian, uint_least32_t, 32, alignment::unaligned > unative32_pt;
+ typedef endian_pack< native_endian, uint_least64_t, 40, alignment::unaligned > unative40_pt;
+ typedef endian_pack< native_endian, uint_least64_t, 48, alignment::unaligned > unative48_pt;
+ typedef endian_pack< native_endian, uint_least64_t, 56, alignment::unaligned > unative56_pt;
+ typedef endian_pack< native_endian, uint_least64_t, 64, alignment::unaligned > unative64_pt;
+
+#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_pack signed integer types
+ // aligned big endian_pack unsigned integer types
+ // aligned little endian_pack signed integer types
+ // aligned little endian_pack unsigned integer types
+
+ // aligned native endian_pack typedefs are not provided because
+ // <cstdint> types are superior for this use case
+
+# if defined(BOOST_HAS_INT16_T)
+ typedef endian_pack< big_endian, int16_t, 16, alignment::aligned > aligned_big16_pt;
+ typedef endian_pack< big_endian, uint16_t, 16, alignment::aligned > aligned_ubig16_pt;
+ typedef endian_pack< little_endian, int16_t, 16, alignment::aligned > aligned_little16_pt;
+ typedef endian_pack< little_endian, uint16_t, 16, alignment::aligned > aligned_ulittle16_pt;
+# endif
+
+# if defined(BOOST_HAS_INT32_T)
+ typedef endian_pack< big_endian, int32_t, 32, alignment::aligned > aligned_big32_pt;
+ typedef endian_pack< big_endian, uint32_t, 32, alignment::aligned > aligned_ubig32_pt;
+ typedef endian_pack< little_endian, int32_t, 32, alignment::aligned > aligned_little32_pt;
+ typedef endian_pack< little_endian, uint32_t, 32, alignment::aligned > aligned_ulittle32_pt;
+# endif
+
+# if defined(BOOST_HAS_INT64_T)
+ typedef endian_pack< big_endian, int64_t, 64, alignment::aligned > aligned_big64_pt;
+ typedef endian_pack< big_endian, uint64_t, 64, alignment::aligned > aligned_ubig64_pt;
+ typedef endian_pack< little_endian, int64_t, 64, alignment::aligned > aligned_little64_pt;
+ typedef endian_pack< little_endian, uint64_t, 64, alignment::aligned > aligned_ulittle64_pt;
+# endif
+
+ template<typename OSTREAM, typename E,
+ typename T, std::size_t N,
+ BOOST_SCOPED_ENUM(alignment) A>
+ OSTREAM&
+ operator<<(OSTREAM & os,
+ const endian_pack< E,T,N,A > & aval) {
+ os << T(aval);
+ return os;
+
+ }
+
+ } // namespace integer
+} // namespace boost
+
+#if defined(__BORLANDC__) || defined( __CODEGEARC__)
+# pragma pack(pop)
+#endif
+
+#endif // BOOST_INTEGER_ENDIAN_PACK_HPP
Added: sandbox/endian_ext/boost/integer/endian/endian_type.hpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/boost/integer/endian/endian_type.hpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,169 @@
+// Boost endian_type.hpp header file -------------------------------------------------------//
+
+// (C) Copyright VicenteJ Botet Escriba 2010-2011
+
+// 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/integer/endian
+
+//--------------------------------------------------------------------------------------//
+
+#ifndef BOOST_INTEGER_ENDIAN_TYPE_HPP
+#define BOOST_INTEGER_ENDIAN_TYPE_HPP
+
+#include <boost/integer/endian/endian.hpp>
+
+#include <boost/type_traits/is_fundamental.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/fusion/support/is_sequence.hpp>
+#include <boost/fusion/sequence/intrinsic/front.hpp>
+#include <boost/fusion/iterator/next.hpp>
+#include <boost/fusion/iterator/deref.hpp>
+#include <boost/fusion/sequence/intrinsic/begin.hpp>
+#include <boost/fusion/sequence/intrinsic/end.hpp>
+#include <boost/fusion/iterator/value_of_data.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/int.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/type_traits/remove_cv.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+
+
+namespace boost {
+namespace integer {
+
+namespace integer_detail {
+
+template <typename T,
+ bool isFundamental = is_fundamental<T>::value,
+ bool IsSeq = fusion::traits::is_sequence<T>::value
+ >
+struct endian_type_impl;
+
+}
+
+template <typename T>
+struct endian_type : integer_detail::endian_type_impl<T> {
+};
+
+namespace integer_detail {
+
+//~ // fundamental types are native
+template <typename T, bool IsSeq>
+struct endian_type_impl<T, true, IsSeq> {
+ typedef endianness::native type;
+};
+
+// we can consider that any other type which has not been explicitly declared is native, but it is more conservative to state that it could be mixted.
+template <typename T>
+struct endian_type_impl<T, false, false> {
+ typedef endianness::mixed type;
+};
+
+// if temp is equal the endian_type of the *it continue otherwise mixed
+template <typename res, typename It, typename End
+> struct endian_type_loop {
+private:
+ typedef
+ typename remove_reference<
+ typename remove_cv<
+ typename fusion::result_of::deref<It>::type
+ >::type
+ >::type it_type;
+public:
+ typedef typename mpl::if_<is_same<typename endian_type< it_type >::type,res>,
+ typename endian_type_loop<res,typename fusion::result_of::next<It>::type, End>::type,
+ endianness::mixed
+ >::type type;
+};
+
+// endian_type of mixed is mixed
+template <typename It, typename End>
+struct endian_type_loop<endianness::mixed,It,End> {
+ typedef endianness::mixed type;
+};
+
+// temp when iteration ends
+template <typename temp, typename End>
+struct endian_type_loop<temp,End,End> {
+ typedef temp type;
+};
+
+// fusion sequences are mixed if not all the elements habve the same endianess,
+// otherwise the endianess of all the types.
+template <typename Seq>
+struct endian_type_impl<Seq, false, true> {
+private:
+ typedef typename remove_reference<
+ typename remove_cv<
+ typename fusion::result_of::front<Seq>::type
+ >::type
+ >::type front_type;
+
+public:
+ typedef typename endian_type_loop<typename endian_type< front_type >::type,
+ typename fusion::result_of::begin<Seq>::type,
+ typename fusion::result_of::end<Seq>::type
+ >::type type;
+};
+
+
+}
+
+
+template <typename T>
+struct endian_type<T*> {
+ // it is undefined the endianess of a pointer
+};
+
+template <typename T, std::size_t N>
+struct endian_type<T[N]> : endian_type<T> {};
+
+// endianess of endian<E,T,n_bits,A> is E
+template <
+ typename E,
+ typename T,
+ std::size_t n_bits,
+ BOOST_SCOPED_ENUM(alignment) A
+> struct endian_type<endian_pack<E,T,n_bits,A> >
+{
+ typedef E type;
+};
+
+// endianess of endian<E,T,n_bits,A> is E
+template <
+ typename E,
+ typename T,
+ std::size_t n_bits,
+ BOOST_SCOPED_ENUM(alignment) A
+> struct endian_type<endian<E,T,n_bits,A> >
+{
+ typedef E type;
+};
+
+template <typename T>
+struct is_native :
+ is_same<typename endian_type<T>::type, endianness::native>
+{};
+
+template <typename T>
+struct is_big :
+ is_same<typename endian_type<T>::type, endianness::big>
+{};
+
+template <typename T>
+struct is_little :
+ is_same<typename endian_type<T>::type, endianness::little>
+{};
+
+template <typename T>
+struct is_mixed :
+ is_same<typename endian_type<T>::type, endianness::mixed>
+{};
+
+
+} // namespace integer
+} // namespace boost
+
+#endif // BOOST_ENDIAN_HPP
Added: sandbox/endian_ext/boost/integer/endian/endian_view.hpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/boost/integer/endian/endian_view.hpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,133 @@
+// Boost endian_view.hpp header file -------------------------------------------------------//
+
+// (C) Copyright VicenteJ Botet Escriba 2010-20111
+
+// 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/integer/endian
+
+//--------------------------------------------------------------------------------------//
+
+
+#ifndef BOOST_INTEGER_ENDIAN_VIEW_HPP
+#define BOOST_INTEGER_ENDIAN_VIEW_HPP
+
+#include <boost/integer/endian/endian_pack.hpp>
+#include <boost/fusion/include/is_sequence.hpp>
+#include <boost/type_traits/is_fundamental.hpp>
+
+namespace boost {
+
+namespace integer {
+
+ template <typename EndianSource, typename T>
+ void convert_from(T& r);
+ template <typename EndianTarget, typename T>
+ void convert_to(T& r);
+ template <typename EndianTarget, typename EndianSource, typename T>
+ void convert_to_from(T& r);
+
+ template <typename Endian, typename T,
+ bool IsFundamental = is_fundamental<T>::value,
+ bool IsSeq = fusion::traits::is_sequence<T>::value
+ >
+ class endian_view;
+
+ template <typename Endian, typename T >
+ class endian_view<Endian,T,true,false>
+ {
+ //~ typedef typename Endian::value_type T;
+ //~ template friend
+ public:
+ typedef T value_type;
+ value_type &ref_;
+
+ typedef endian_pack<Endian,value_type> endian_t;
+ endian_view(value_type& ref) : ref_(ref) {};
+ operator value_type() const {
+ endian_t& v=reinterpret_cast<endian_t&>(ref_);
+ return v;
+ }
+ endian_view& operator=(value_type val) {
+ endian_t& v=reinterpret_cast<endian_t&>(ref_);
+ v=val;
+ return *this;
+ }
+ endian_view& operator=(endian_view const& rhs) {
+ if (this!=&rhs) {
+ ref_=rhs.ref_;
+ }
+ return *this;
+ }
+ template <typename Endian2 >
+ endian_view& operator=(endian_view<Endian2,T,true,false> const& rhs) {
+ endian_t& v=reinterpret_cast<endian_t&>(ref_);
+ endian_pack<Endian2,value_type>& val=reinterpret_cast<endian_pack<Endian2,value_type>&>(rhs.ref_);
+ v=val;
+ return *this;
+ }
+ };
+
+ template <typename Endian, typename T >
+ class endian_view<Endian,T,false,true>
+ {
+ public:
+ typedef T value_type;
+ value_type &ref_;
+
+ endian_view(value_type& ref) : ref_(ref) {};
+ operator value_type() const {
+ value_type res=ref_;
+ convert_from<Endian>(res);
+ return res;
+ }
+ endian_view& operator=(value_type val) {
+ ref_=val;
+ convert_to<Endian>(ref_);
+ return *this;
+ }
+ endian_view& operator=(endian_view const& rhs) {
+ if (this!=&rhs) {
+ ref_=rhs.ref_;
+ }
+ return *this;
+ }
+ template <typename Endian2 >
+ endian_view& operator=(endian_view<Endian2,T,true,false> const& rhs) {
+ ref_=rhs.ref_;
+ convert_to_from<Endian2,Endian>(ref_);
+ return *this;
+ }
+ };
+
+ template <typename E, typename T>
+ endian_view<E,T> as_endian(T& v) {
+ return endian_view<E,T>(v);
+ }
+
+ template <typename T>
+ endian_view<native_endian,T> as(T& v)
+ {
+ return as_endian<native_endian>(v);
+ }
+ template <typename T>
+ endian_view<little_endian,T> as_little(T& v)
+ {
+ return as_endian<little_endian>(v);
+ }
+
+ template <typename T>
+ endian_view<big_endian,T> as_big(T& v)
+ {
+ return as_endian<big_endian>(v);
+ }
+
+
+} // namespace integer
+} // namespace boost
+
+#include <boost/integer/endian/endian_conversion.hpp>
+
+
+#endif // BOOST_INTEGER_ENDIAN_VIEW_HPP
Added: sandbox/endian_ext/boost/integer/endian/endianness.hpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/boost/integer/endian/endianness.hpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,73 @@
+// Boost endian_view.hpp header file -------------------------------------------------------//
+
+// (C) Copyright VicenteJ Botet Escriba 2010
+
+// 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_ENDIANNESS__HPP
+#define BOOST_ENDIAN_ENDIANNESS__HPP
+
+//~ #include <boost/config.hpp>
+#include <boost/detail/endian.hpp>
+#ifdef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+#include <boost/detail/scoped_enum_emulation.hpp>
+#endif
+
+namespace boost {
+namespace integer {
+
+# ifdef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+ // endian class template and specializations ---------------------------------------//
+# ifdef BOOST_BIG_ENDIAN
+ BOOST_SCOPED_ENUM_START(endianness) { big, little, middle, mixed, native=big }; BOOST_SCOPED_ENUM_END
+# else
+ BOOST_SCOPED_ENUM_START(endianness) { big, little, middle, mixed, native=little }; BOOST_SCOPED_ENUM_END
+# endif
+ const BOOST_SCOPED_ENUM_START(endianness) big_endian = endianness::big;
+ const BOOST_SCOPED_ENUM_START(endianness) little_endian = endianness::little;
+ const BOOST_SCOPED_ENUM_START(endianness) middle_endian = endianness::middle;
+ const BOOST_SCOPED_ENUM_START(endianness) mixed_endian = endianness::mixed;
+ const BOOST_SCOPED_ENUM_START(endianness) native_endian = endianness::native;
+#else
+
+namespace endianness {
+
+
+ struct big {
+ //~ static const BOOST_SCOPED_ENUM(endianness) value= endianness::big;
+ };
+ struct little {
+ //~ static const BOOST_SCOPED_ENUM(endianness) value= endianness::little;
+ };
+ struct middle {
+ //~ static const BOOST_SCOPED_ENUM(endianness) value= endianness::middle;
+ };
+ struct mixed {
+ //~ static const BOOST_SCOPED_ENUM(endianness) value= endianness::mixed;
+ };
+# ifdef BOOST_BIG_ENDIAN
+ typedef big native ;
+# else
+ typedef little native ;
+# endif
+
+}
+
+ typedef endianness::big big_endian;
+ typedef endianness::little little_endian;
+ typedef endianness::middle middle_endian;
+ typedef endianness::mixed mixed_endian;
+ typedef endianness::native native_endian;
+# endif
+
+} // namespace integer
+} // namespace boost
+
+
+#endif // BOOST_ENDIAN_ENDIANNESS__HPP
Deleted: sandbox/endian_ext/boost/integer/endian_binary_stream.hpp
==============================================================================
--- sandbox/endian_ext/boost/integer/endian_binary_stream.hpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
+++ (empty file)
@@ -1,131 +0,0 @@
-// boost/integer/endian_binary_stream.hpp --------------------------------------------//
-
-// Copyright Beman Dawes 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
-
-#ifndef BOOST_ENDIAN_BINARY_STREAM_HPP
-#define BOOST_ENDIAN_BINARY_STREAM_HPP
-
-#include <boost/integer/endian.hpp>
-#include <boost/utility/enable_if.hpp>
-#include <ostream>
-#include <istream>
-
-// unformatted binary (as opposed to formatted character) stream insertion
-// and extraction.
-
-// Warning: Use only on streams opened with filemode std::ios_base::binary. Thus
-// unformatted binary I/O should not be with the standard streams (cout, cin, etc.)
-// since they are opened in text mode. Use on text streams may produce incorrect
-// results, such as insertion of unwanted characters or premature end-of-file.
-// For example, on Windows 0x0D would become 0x0D, 0x0A.
-
-// Caution: When mixing formatted (i.e. operator << or >>) and unformatted (i.e.
-// operator <= or >=) be aware that << and >> take precedence over <= and >=. Use
-// parentheses to force correct order of evaluation. For example:
-//
-// my_stream << foo <= bar; // no parentheses needed
-// (my_stream <= foo) << bar; // parentheses required
-
-// This implementation uses reinterpret_cast<>() when needed to convert one pointer
-// type to another. See 5.2.10 [expr.reinterpret.cast], Reinterpret cast, para 7.
-
-namespace boost
-{
- namespace integer
- {
- template< class T > struct is_endian { static const bool value = false; };
-
- #if 1
- template<typename E,
- typename T,
- std::size_t N,
- BOOST_SCOPED_ENUM(alignment) A>
- struct is_endian<endian_pack<E,T,N,A> > { static const bool value = true; };
- template<typename E,
- typename T,
- std::size_t N,
- BOOST_SCOPED_ENUM(alignment) A>
- struct is_endian<endian<E,T,N,A> > { static const bool value = true; };
- #else
- template<> struct is_endian<big8_t> { static const bool value = true; };
- template<> struct is_endian<big16_t> { static const bool value = true; };
- template<> struct is_endian<big24_t> { static const bool value = true; };
- template<> struct is_endian<big32_t> { static const bool value = true; };
- template<> struct is_endian<big40_t> { static const bool value = true; };
- template<> struct is_endian<big48_t> { static const bool value = true; };
- template<> struct is_endian<big56_t> { static const bool value = true; };
- template<> struct is_endian<big64_t> { static const bool value = true; };
-
- template<> struct is_endian<ubig8_t> { static const bool value = true; };
- template<> struct is_endian<ubig16_t> { static const bool value = true; };
- template<> struct is_endian<ubig24_t> { static const bool value = true; };
- template<> struct is_endian<ubig32_t> { static const bool value = true; };
- template<> struct is_endian<ubig40_t> { static const bool value = true; };
- template<> struct is_endian<ubig48_t> { static const bool value = true; };
- template<> struct is_endian<ubig56_t> { static const bool value = true; };
- template<> struct is_endian<ubig64_t> { static const bool value = true; };
-
- template<> struct is_endian<little8_t> { static const bool value = true; };
- template<> struct is_endian<little16_t> { static const bool value = true; };
- template<> struct is_endian<little24_t> { static const bool value = true; };
- template<> struct is_endian<little32_t> { static const bool value = true; };
- template<> struct is_endian<little40_t> { static const bool value = true; };
- template<> struct is_endian<little48_t> { static const bool value = true; };
- template<> struct is_endian<little56_t> { static const bool value = true; };
- template<> struct is_endian<little64_t> { static const bool value = true; };
-
- template<> struct is_endian<ulittle8_t> { static const bool value = true; };
- template<> struct is_endian<ulittle16_t> { static const bool value = true; };
- template<> struct is_endian<ulittle24_t> { static const bool value = true; };
- template<> struct is_endian<ulittle32_t> { static const bool value = true; };
- template<> struct is_endian<ulittle40_t> { static const bool value = true; };
- template<> struct is_endian<ulittle48_t> { static const bool value = true; };
- template<> struct is_endian<ulittle56_t> { static const bool value = true; };
- template<> struct is_endian<ulittle64_t> { static const bool value = true; };
-
- # if defined(BOOST_HAS_INT16_T)
- template<> struct is_endian<aligned_big16_t> { static const bool value = true; };
- template<> struct is_endian<aligned_ubig16_t> { static const bool value = true; };
- template<> struct is_endian<aligned_little16_t> { static const bool value = true; };
- template<> struct is_endian<aligned_ulittle16_t> { static const bool value = true; };
-# endif
-
-# if defined(BOOST_HAS_INT32_T)
- template<> struct is_endian<aligned_big32_t> { static const bool value = true; };
- template<> struct is_endian<aligned_ubig32_t> { static const bool value = true; };
- template<> struct is_endian<aligned_little32_t> { static const bool value = true; };
- template<> struct is_endian<aligned_ulittle32_t> { static const bool value = true; };
-# endif
-
-# if defined(BOOST_HAS_INT64_T)
- template<> struct is_endian<aligned_big64_t> { static const bool value = true; };
- template<> struct is_endian<aligned_ubig64_t> { static const bool value = true; };
- template<> struct is_endian<aligned_little64_t> { static const bool value = true; };
- template<> struct is_endian<aligned_ulittle64_t> { static const bool value = true; };
-# endif
- #endif
-
- template < class Endian >
- inline typename boost::enable_if< is_endian<Endian>, std::ostream & >::type
- operator<=( std::ostream & os, const Endian & e )
- {
- //~ return os.write( reinterpret_cast<const char*>(&e), sizeof(e) );
- return os.write( e.data(), sizeof(e) );
- }
-
- template < class Endian >
- inline typename boost::enable_if< is_endian<Endian>, std::istream & >::type
- operator>=( std::istream & is, Endian & e )
- {
- return is.read( reinterpret_cast<char*>(&e), sizeof(e) );
- }
-
- } // namespace integer
-} // namespace boost
-
-#endif // BOOST_ENDIAN_BINARY_STREAM_HPP
Deleted: sandbox/endian_ext/boost/integer/endian_conversion.hpp
==============================================================================
--- sandbox/endian_ext/boost/integer/endian_conversion.hpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
+++ (empty file)
@@ -1,227 +0,0 @@
-// Boost endian_view.hpp header file -------------------------------------------------------//
-
-// (C) Copyright VicenteJ Botet Escriba 2010
-
-// 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_INTEGER_ENDIAN_CONVERT_HPP
-#define BOOST_INTEGER_ENDIAN_CONVERT_HPP
-
-#include <boost/endian/endianness.hpp>
-#include <boost/endian/domain_map.hpp>
-#include <boost/mpl/deref.hpp>
-#include <boost/mpl/next.hpp>
-#include <boost/mpl/begin.hpp>
-#include <boost/mpl/end.hpp>
-#include <boost/fusion/include/deref.hpp>
-#include <boost/fusion/include/next.hpp>
-#include <boost/fusion/include/begin.hpp>
-#include <boost/fusion/include/end.hpp>
-#include <boost/fusion/include/is_sequence.hpp>
-#include <boost/type_traits/is_fundamental.hpp>
-#include <boost/type_traits/remove_reference.hpp>
-#include <boost/type_traits/remove_cv.hpp>
-
-#include <boost/integer/endian_view.hpp>
-
-namespace boost {
-namespace integer {
-
- template <typename EndianTarget, typename EndianSource, typename T>
- inline void convert_to_from(T& r);
-
- template <typename EndianTarget, typename EndianSource, typename T>
- inline void convert_to_from_impl(T& r);
-
- namespace integer_detail {
- template <typename EndianTarget, typename EndianSource, typename T,
- bool IsFundamental = is_fundamental<T>::value,
- bool IsSeq = fusion::traits::is_sequence<T>::value
- >
- struct convert_to_from;
-
- template <
- typename ItTarget, typename EndTarget,
- typename ItSource, typename EndSource>
- struct convert_to_from_seq_loop {
- template <typename It, typename End>
- static void apply(It& it, End& end) {
- boost::integer::convert_to_from_impl<
- typename mpl::deref<ItTarget>::type,
- typename mpl::deref<ItSource>::type,
- typename remove_reference<typename remove_cv<typename fusion::result_of::deref<It>::type>::type >::type
- >
- (fusion::deref(it));
- convert_to_from_seq_loop<
- typename mpl::next<ItTarget>::type, EndTarget,
- typename mpl::next<ItSource>::type, EndSource
- >::apply(fusion::next(it), end);
- }
- };
-
- template <typename EndTarget, typename EndSource>
- struct convert_to_from_seq_loop<EndTarget, EndTarget, EndSource, EndSource> {
- template <typename It, typename End>
- static void apply(It& it, End& end) {
- }
- };
-
- template <typename EndianTarget, typename EndianSource, typename T>
- struct convert_to_from_seq {
- static void apply(T& r) {
- convert_to_from_seq_loop<
- typename mpl::begin<EndianTarget>::type,
- typename mpl::end<EndianTarget>::type,
- typename mpl::begin<EndianSource>::type,
- typename mpl::end<EndianSource>::type >
- ::apply(fusion::begin(r), fusion::end(r));
-
- }
- };
-
- // same endianess do nothiong
- template <typename E, typename T, bool IsFundamental, bool IsSeq>
- struct convert_to_from<E, E, T, IsFundamental, IsSeq> {
- static void apply(T& r) {
- }
- };
-
- template <typename E, typename T>
- struct convert_to_from<E, E, T, false, false> {
- static void apply(T& r) {
- }
- };
-
- template <typename E, typename T>
- struct convert_to_from<E,E,T,false,true> {
- static void apply(T& r) {
- }
- };
-
- // on fundamentals apply endian views
- template <typename T>
- struct convert_to_from<endianness::big, endianness::little, T, true, false> {
- static void apply(T& r) {
- as_big(r)=as_little(r);
- }
- };
- // on fundamentals apply endian views
- template <typename T>
- struct convert_to_from<endianness::little, endianness::big, T, true, false> {
- static void apply(T& r) {
- as_little(r)=as_big(r);
- }
- };
- template <typename EndianTarget, typename EndianSource, typename T>
- struct convert_to_from<EndianTarget, EndianSource, T, false, true>
- : convert_to_from_seq<EndianTarget,EndianSource,T> {};
-
- template <typename EndianTarget, typename EndianSource, typename T>
- struct convert_to_from<EndianTarget, EndianSource, T, false, false> {
- static void apply(T& r) {
- }
- //~ template <typename T>
- //~ static void apply(T& r) {
- //~ //use ADL to find this
- //~ convert_to_from_impl<EndianTarget,EndianSource,T>(r);
- //~ }
- };
-
- } // namespace integer_detail
-
-template <typename EndianTarget, typename EndianSource, typename T>
-inline void convert_to_from_impl(T& r) {
- integer_detail::convert_to_from<
- EndianTarget,
- EndianSource,
- T
- >::apply(r);
-}
-
-template <typename EndianTarget, typename EndianSource, typename T>
-void convert_to_from(T& r) {
- integer_detail::convert_to_from<
- typename endianness::domain_map<EndianTarget,T>::type,
- typename endianness::domain_map<EndianSource,T>::type,
- T
- >::apply(r);
-}
-
-template <typename Endian>
-struct to {
- typedef Endian type;
-};
-
-template <typename Endian>
-struct from {
- typedef Endian type;
-};
-
-template <typename Endian>
-struct is_to : mpl::false_ {};
-template <typename Endian>
-struct is_to<to<Endian> > : mpl::true_ {};
-
-template <typename Endian>
-struct is_from : mpl::false_ {};
-template <typename Endian>
-struct is_from<from<Endian> > : mpl::true_ {};
-
-
-template <typename Endian1, typename Endian2, typename T>
-void convert(T& r) {
- typedef
- typename mpl::if_<is_to<Endian1>, typename Endian1::type,
- typename mpl::if_<is_to<Endian2>, typename Endian2::type,
- void
- >::type
- >::type EndianTarget;
- typedef
- typename mpl::if_<is_from<Endian1>, typename Endian1::type,
- typename mpl::if_<is_from<Endian2>, typename Endian2::type,
- void
- >::type
- >::type EndianSource;
-
- integer_detail::convert_to_from<
- typename endianness::domain_map<EndianTarget,T>::type,
- typename endianness::domain_map<EndianSource,T>::type,
- T
- >::apply(r);
-}
-
-
-//~ template <typename EndianTarget, typename EndianSource, typename T, typename N>
-//~ void convert_to_from(T[N] a) {
- //~ for (unsigned int i=0; i<N; ++i) {
- //~ convert_to_from<EndianTarget, EndianSource, T>(a[i]);
- //~ }
-//~ }
-
-template <typename EndianSource, typename T>
-void convert_from(T& r) {
- integer_detail::convert_to_from<
- typename endianness::domain_map<endianness::native,T>::type,
- typename endianness::domain_map<EndianSource,T>::type,
- T>::apply(r);
-}
-
-template <typename EndianTarget, typename T>
-void convert_to(T& r) {
- integer_detail::convert_to_from<
- typename endianness::domain_map<EndianTarget,T>::type,
- typename endianness::domain_map<endianness::native, T>::type,
- T>::apply(r);
-}
-
-} // namespace integer
-} // namespace boost
-
-
-#endif // BOOST_INTEGER_ENDIAN_CONVERT_HPP
Deleted: sandbox/endian_ext/boost/integer/endian_flip.hpp
==============================================================================
--- sandbox/endian_ext/boost/integer/endian_flip.hpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
+++ (empty file)
@@ -1,96 +0,0 @@
-// endian_flip.hpp -------------------------------------------------------------------//
-
-// Copyright Beman Dawes 2010
-
-// Distributed under the Boost Software License, Version 1.0.
-// http://www.boost.org/LICENSE_1_0.txt
-
-#ifndef BOOST_ENDIAN_FLIP_HPP
-#define BOOST_ENDIAN_FLIP_HPP
-
-#include <boost/integer.hpp>
-namespace boost
-{
-namespace integer
-{
- inline void endian_flip(int16_t& x)
- {
- char* rep = reinterpret_cast<char*>(&x);
- char tmp;
- tmp = *rep;
- *rep = *(rep+1);
- *(rep+1) = tmp;
- }
-
- inline void endian_flip(int32_t& x)
- {
- char* rep = reinterpret_cast<char*>(&x);
- char tmp;
- tmp = *rep;
- *rep = *(rep+3);
- *(rep+3) = tmp;
- tmp = *(rep+1);
- *(rep+1) = *(rep+2);
- *(rep+2) = tmp;
- }
-
- inline void endian_flip(int64_t& x)
- {
- char* rep = reinterpret_cast<char*>(&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 endian_flip(uint16_t& x)
- {
- char* rep = reinterpret_cast<char*>(&x);
- char tmp;
- tmp = *rep;
- *rep = *(rep+1);
- *(rep+1) = tmp;
- }
-
- inline void endian_flip(uint32_t& x)
- {
- char* rep = reinterpret_cast<char*>(&x);
- char tmp;
- tmp = *rep;
- *rep = *(rep+3);
- *(rep+3) = tmp;
- tmp = *(rep+1);
- *(rep+1) = *(rep+2);
- *(rep+2) = tmp;
- }
-
- inline void endian_flip(uint64_t& x)
- {
- char* rep = reinterpret_cast<char*>(&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;
- }
-} // namespace integer
-} // namespace boost
-
-#endif // BOOST_ENDIAN_FLIP_HPP
Deleted: sandbox/endian_ext/boost/integer/endian_pack.hpp
==============================================================================
--- sandbox/endian_ext/boost/integer/endian_pack.hpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
+++ (empty file)
@@ -1,514 +0,0 @@
-// Boost endian_pack.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.
-
-// Split of endian.hpp into endian.hpp and endian_pack.hpp done by Vicente J. Botet Escriba.
-// Definition of native depending on BOOST_BIG_ENDIAN to big or little done by Vicente J. Botet Escriba.
-// Change the definition of endian_pack using types instead of enum endianness done by Vicente J. Botet Escriba.
-
-// TODO: When a compiler supporting constexpr becomes available, try possible uses.
-#define BOOST_ENDIAN_ALLOWS_UDT
-
-#ifndef BOOST_INTEGER_ENDIAN_PACK_HPP
-#define BOOST_INTEGER_ENDIAN_PACK_HPP
-
-#ifdef BOOST_ENDIAN_LOG
-# include <iostream>
-#endif
-
-#if defined(__BORLANDC__) || defined( __CODEGEARC__)
-# pragma pack(push, 1)
-#endif
-
-#include <boost/config.hpp>
-#include <boost/type_traits/is_signed.hpp>
-#include <climits>
-#include <boost/integer_traits.hpp>
-#include <boost/cstdint.hpp>
-#include <boost/static_assert.hpp>
-#include <boost/detail/scoped_enum_emulation.hpp>
-//~ #include <iosfwd>
-#include <climits>
-#include <algorithm>
-
-# include <boost/endian/endianness.hpp>
-
-# 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 <typename T, std::size_t n_bytes,
- bool sign=boost::is_signed<T>::value >
- struct unrolled_byte_loops
- {
- typedef unrolled_byte_loops<T, n_bytes - 1, sign> 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<char>(value);
- next::store_big(bytes - 1, value >> 8);
- }
- static void store_little(char* bytes, T value)
- {
- *bytes = static_cast<char>(value);
- next::store_little(bytes + 1, value >> 8);
- }
- };
-
- template <typename T>
- struct unrolled_byte_loops<T, 1, false>
- {
- 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<char>(value); }
- static void store_little(char* bytes, T value)
- { *bytes = static_cast<char>(value); }
-
- };
-
- template <typename T>
- struct unrolled_byte_loops<T, 1, true>
- {
- static T load_big(const unsigned char* bytes)
- { return *reinterpret_cast<const signed char*>(bytes - 1); }
- static T load_little(const unsigned char* bytes)
- { return *reinterpret_cast<const signed char*>(bytes); }
- static void store_big(char* bytes, T value)
- { *(bytes - 1) = static_cast<char>(value); }
- static void store_little(char* bytes, T value)
- { *bytes = static_cast<char>(value); }
- };
-
- template <typename T, std::size_t n_bytes>
- inline
- T load_big_endian(const void* bytes)
- {
- return unrolled_byte_loops<T, n_bytes>::load_big
- (static_cast<const unsigned char*>(bytes) + n_bytes);
- }
-
- template <typename T, std::size_t n_bytes>
- inline
- T load_little_endian(const void* bytes)
- {
- return unrolled_byte_loops<T, n_bytes>::load_little
- (static_cast<const unsigned char*>(bytes));
- }
-
- template <typename T, std::size_t n_bytes>
- inline
- void store_big_endian(void* bytes, T value)
- {
- unrolled_byte_loops<T, n_bytes>::store_big
- (static_cast<char*>(bytes) + n_bytes, value);
- }
-
- template <typename T, std::size_t n_bytes>
- inline
- void store_little_endian(void* bytes, T value)
- {
- unrolled_byte_loops<T, n_bytes>::store_little
- (static_cast<char*>(bytes), value);
- }
-
- ///////////////////////
- template<std::size_t L> inline
- void unrolled_reverse_copy(char* dst, const char* src) {
- *dst = *src;
- unrolled_reverse_copy<L-1>(dst+1, src-1);
- } // unrolled_reverse_copy
-
- template<> inline void unrolled_reverse_copy<1>(char* dst, const char* src)
- { *dst = *src; }
-
- template<> inline void unrolled_reverse_copy<0>(char*, const char*) { }
-
- template<std::size_t L, bool>
- struct reverse_copy_helper {
- static void copy(char* dst, const char* src)
- { std::reverse_copy(src, src+L, dst); }
- };
-
- template<std::size_t L>
- struct reverse_copy_helper<L, true> {
- static void copy(char* dst, const char* src)
- { unrolled_reverse_copy<L>(dst, src+(L-1)); }
- };
-
- template<std::size_t L> inline
- void reverse_copy(void* dst, const void* src) {
- reverse_copy_helper< L, (L<=16) >::copy(static_cast<char*>(dst),
- static_cast<const char*>(src));
- }
-
- } // namespace detail
-
- namespace integer
- {
-
-# ifdef BOOST_ENDIAN_LOG
- bool endian_log(true);
-# endif
-
-
- BOOST_SCOPED_ENUM_START(alignment) { unaligned, aligned }; BOOST_SCOPED_ENUM_END
-
- template <typename E,
- typename T,
- std::size_t n_bits=sizeof(T)*8,
- BOOST_SCOPED_ENUM(alignment) A = alignment::aligned
- > class endian_pack;
-
- // 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 <typename T, std::size_t n_bits>
- class endian_pack<big_endian, T, n_bits, alignment::unaligned >
-
- {
- BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
- public:
- typedef big_endian endian_type;
- typedef T value_type;
- static const std::size_t width = n_bits;
- static const BOOST_SCOPED_ENUM(alignment) alignment_value = alignment::unaligned;
-# ifndef BOOST_ENDIAN_NO_CTORS
- endian_pack() BOOST_ENDIAN_DEFAULT_CONSTRUCT
- template <typename T2>
- explicit endian_pack(T2 val)
- //~ explicit endian_pack(T val)
- {
-# ifdef BOOST_ENDIAN_LOG
- if ( endian_log )
- std::clog << "big, unaligned, " << n_bits << "-bits, construct(" << val << ")\n";
-# endif
- boost::detail::store_big_endian<T, n_bits/8>(m_value, val);
- }
-# endif
- endian_pack & operator=(T val) { boost::detail::store_big_endian<T, n_bits/8>(m_value, val); return *this; }
- operator T() const
- {
-# ifdef BOOST_ENDIAN_LOG
- if ( endian_log )
- std::clog << "big, unaligned, " << n_bits << "-bits, convert(" << boost::detail::load_big_endian<T, n_bits/8>(m_value) << ")\n";
-# endif
- return boost::detail::load_big_endian<T, n_bits/8>(m_value);
- }
- const char* data() const { return m_value; }
- private:
- char m_value[n_bits/8];
- };
-
- // unaligned little endian specialization
- template <typename T, std::size_t n_bits>
- class endian_pack< little_endian, T, n_bits, alignment::unaligned >
- {
- BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
- public:
- typedef little_endian endian_type;
- typedef T value_type;
- static const std::size_t width = n_bits;
- static const BOOST_SCOPED_ENUM(alignment) alignment_value = alignment::unaligned;
-# ifndef BOOST_ENDIAN_NO_CTORS
- endian_pack() BOOST_ENDIAN_DEFAULT_CONSTRUCT
- explicit endian_pack(T val)
- {
-# ifdef BOOST_ENDIAN_LOG
- if ( endian_log )
- std::clog << "little, unaligned, " << n_bits << "-bits, construct(" << val << ")\n";
-# endif
- boost::detail::store_little_endian<T, n_bits/8>(m_value, val);
- }
-# endif
- endian_pack & operator=(T val) { detail::store_little_endian<T, n_bits/8>(m_value, val); return *this; }
- operator T() const
- {
-# ifdef BOOST_ENDIAN_LOG
- if ( endian_log )
- std::clog << "little, unaligned, " << n_bits << "-bits, convert(" << boost::detail::load_little_endian<T, n_bits/8>(m_value) << ")\n";
-# endif
- return boost::detail::load_little_endian<T, n_bits/8>(m_value);
- }
- 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.
-
-#if defined(BOOST_ENDIAN_ALLOWS_UDT)
- // aligned endian specialization
- template <typename E, typename T, std::size_t n_bits>
- class endian_pack< E, T, n_bits, alignment::aligned >
- {
- BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
- BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 );
- public:
- typedef E endian_type;
- typedef T value_type;
- private:
- void store(const value_type& v)
- { detail::reverse_copy<sizeof(value_type)>(m_value, &v); }
-
- void retrieve(value_type* result) const
- { detail::reverse_copy<sizeof(value_type)>(result, m_value); }
- public:
- static const std::size_t width = n_bits;
- static const BOOST_SCOPED_ENUM(alignment) alignment_value = alignment::aligned;
-# ifndef BOOST_ENDIAN_NO_CTORS
- endian_pack() BOOST_ENDIAN_DEFAULT_CONSTRUCT
- explicit endian_pack(T val) { store(val); }
-# endif
- endian_pack & operator=(T val) { store(val); return *this; }
- operator T() const { value_type rval; retrieve(&rval); return rval; }
- //~ const char* data() const { return reinterpret_cast<const char *>(&m_value); }
- const char* data() const { return m_value; }
- private:
- //~ T m_value;
- char m_value[sizeof(value_type)];
- };
-
- // aligned native endian specialization
- template <typename T, std::size_t n_bits>
- class endian_pack< native_endian, T, n_bits, alignment::aligned >
- {
- BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
- BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 );
- public:
- typedef native_endian endian_type;
- typedef T value_type;
- static const std::size_t width = n_bits;
- static const BOOST_SCOPED_ENUM(alignment) alignment_value = alignment::aligned;
-# ifndef BOOST_ENDIAN_NO_CTORS
- endian_pack() BOOST_ENDIAN_DEFAULT_CONSTRUCT
- explicit endian_pack(T val) : m_value(val) { }
-# endif
- endian_pack & operator=(T val) { m_value = val; return *this; }
- operator T() const { return m_value; }
- const char* data() const { return reinterpret_cast<const char *>(&m_value); }
- private:
- T m_value;
- };
-#else
- // aligned big endian specialization
- template <typename T, std::size_t n_bits>
- class endian_pack< big_endian, T, n_bits, alignment::aligned >
- {
- BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
- BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 );
- public:
- typedef big_endian endian_type;
- typedef T value_type;
- static const std::size_t width = n_bits;
- static const BOOST_SCOPED_ENUM(alignment) alignment_value = alignment::aligned;
-# ifndef BOOST_ENDIAN_NO_CTORS
- endian_pack() BOOST_ENDIAN_DEFAULT_CONSTRUCT
-# ifdef BOOST_BIG_ENDIAN
- explicit endian_pack(T val) : m_value(val) { }
-# else
- explicit endian_pack(T val) { boost::detail::store_big_endian<T, sizeof(T)>(&m_value, val); }
-# endif
-# endif
-# ifdef BOOST_BIG_ENDIAN
- endian_pack & operator=(T val) { m_value = val); return *this; }
- operator T() const { return m_value; }
-# else
- endian_pack & operator=(T val) { boost::detail::store_big_endian<T, sizeof(T)>(&m_value, val); return *this; }
- operator T() const { return boost::detail::load_big_endian<T, sizeof(T)>(&m_value); }
-# endif
- const char* data() const { return reinterpret_cast<const char *>(&m_value); }
- private:
- T m_value;
- };
-
- // aligned little endian specialization
- template <typename T, std::size_t n_bits>
- class endian_pack< little_endian, T, n_bits, alignment::aligned >
- {
- BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
- BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 );
- public:
- typedef little_endian endian_type;
- typedef T value_type;
- static const std::size_t width = n_bits;
- static const BOOST_SCOPED_ENUM(alignment) alignment_value = alignment::aligned;
-# ifndef BOOST_ENDIAN_NO_CTORS
- endian_pack() BOOST_ENDIAN_DEFAULT_CONSTRUCT
-# ifdef BOOST_LITTLE_ENDIAN
- explicit endian_pack(T val) : m_value(val) { }
-# else
- explicit endian_pack(T val) { boost::detail::store_little_endian<T, sizeof(T)>(&m_value, val); }
-# endif
-# endif
-# ifdef BOOST_LITTLE_ENDIAN
- endian_pack & operator=(T val) { m_value = val; return *this; }
- operator T() const { return m_value; }
- #else
- endian_pack & operator=(T val) { boost::detail::store_little_endian<T, sizeof(T)>(&m_value, val); return *this; }
- operator T() const { return boost::detail::load_little_endian<T, sizeof(T)>(&m_value); }
- #endif
- const char* data() const { return reinterpret_cast<const char *>(&m_value); }
- private:
- T m_value;
- };
-#endif
-
- // naming convention typedefs ------------------------------------------------------//
-
- // unaligned big endian_pack signed integer types
- typedef endian_pack< big_endian, int_least8_t, 8, alignment::unaligned > big8_pt;
- typedef endian_pack< big_endian, int_least16_t, 16, alignment::unaligned > big16_pt;
- typedef endian_pack< big_endian, int_least32_t, 24, alignment::unaligned > big24_pt;
- typedef endian_pack< big_endian, int_least32_t, 32, alignment::unaligned > big32_pt;
- typedef endian_pack< big_endian, int_least64_t, 40, alignment::unaligned > big40_pt;
- typedef endian_pack< big_endian, int_least64_t, 48, alignment::unaligned > big48_pt;
- typedef endian_pack< big_endian, int_least64_t, 56, alignment::unaligned > big56_pt;
- typedef endian_pack< big_endian, int_least64_t, 64, alignment::unaligned > big64_pt;
-
- // unaligned big endian_pack unsigned integer types
- typedef endian_pack< big_endian, uint_least8_t, 8, alignment::unaligned > ubig8_pt;
- typedef endian_pack< big_endian, uint_least16_t, 16, alignment::unaligned > ubig16_pt;
- typedef endian_pack< big_endian, uint_least32_t, 24, alignment::unaligned > ubig24_pt;
- typedef endian_pack< big_endian, uint_least32_t, 32, alignment::unaligned > ubig32_pt;
- typedef endian_pack< big_endian, uint_least64_t, 40, alignment::unaligned > ubig40_pt;
- typedef endian_pack< big_endian, uint_least64_t, 48, alignment::unaligned > ubig48_pt;
- typedef endian_pack< big_endian, uint_least64_t, 56, alignment::unaligned > ubig56_pt;
- typedef endian_pack< big_endian, uint_least64_t, 64, alignment::unaligned > ubig64_pt;
-
- // unaligned little endian_pack signed integer types
- typedef endian_pack< little_endian, int_least8_t, 8, alignment::unaligned > little8_pt;
- typedef endian_pack< little_endian, int_least16_t, 16, alignment::unaligned > little16_pt;
- typedef endian_pack< little_endian, int_least32_t, 24, alignment::unaligned > little24_pt;
- typedef endian_pack< little_endian, int_least32_t, 32, alignment::unaligned > little32_pt;
- typedef endian_pack< little_endian, int_least64_t, 40, alignment::unaligned > little40_pt;
- typedef endian_pack< little_endian, int_least64_t, 48, alignment::unaligned > little48_pt;
- typedef endian_pack< little_endian, int_least64_t, 56, alignment::unaligned > little56_pt;
- typedef endian_pack< little_endian, int_least64_t, 64, alignment::unaligned > little64_pt;
-
- // unaligned little endian_pack unsigned integer types
- typedef endian_pack< little_endian, uint_least8_t, 8, alignment::unaligned > ulittle8_pt;
- typedef endian_pack< little_endian, uint_least16_t, 16, alignment::unaligned > ulittle16_pt;
- typedef endian_pack< little_endian, uint_least32_t, 24, alignment::unaligned > ulittle24_pt;
- typedef endian_pack< little_endian, uint_least32_t, 32, alignment::unaligned > ulittle32_pt;
- typedef endian_pack< little_endian, uint_least64_t, 40, alignment::unaligned > ulittle40_pt;
- typedef endian_pack< little_endian, uint_least64_t, 48, alignment::unaligned > ulittle48_pt;
- typedef endian_pack< little_endian, uint_least64_t, 56, alignment::unaligned > ulittle56_pt;
- typedef endian_pack< little_endian, uint_least64_t, 64, alignment::unaligned > ulittle64_pt;
-
- // unaligned native endian_pack signed integer types
- typedef endian_pack< native_endian, int_least8_t, 8, alignment::unaligned > native8_pt;
- typedef endian_pack< native_endian, int_least16_t, 16, alignment::unaligned > native16_pt;
- typedef endian_pack< native_endian, int_least32_t, 24, alignment::unaligned > native24_pt;
- typedef endian_pack< native_endian, int_least32_t, 32, alignment::unaligned > native32_pt;
- typedef endian_pack< native_endian, int_least64_t, 40, alignment::unaligned > native40_pt;
- typedef endian_pack< native_endian, int_least64_t, 48, alignment::unaligned > native48_pt;
- typedef endian_pack< native_endian, int_least64_t, 56, alignment::unaligned > native56_pt;
- typedef endian_pack< native_endian, int_least64_t, 64, alignment::unaligned > native64_pt;
-
- // unaligned native endian_pack unsigned integer types
- typedef endian_pack< native_endian, uint_least8_t, 8, alignment::unaligned > unative8_pt;
- typedef endian_pack< native_endian, uint_least16_t, 16, alignment::unaligned > unative16_pt;
- typedef endian_pack< native_endian, uint_least32_t, 24, alignment::unaligned > unative24_pt;
- typedef endian_pack< native_endian, uint_least32_t, 32, alignment::unaligned > unative32_pt;
- typedef endian_pack< native_endian, uint_least64_t, 40, alignment::unaligned > unative40_pt;
- typedef endian_pack< native_endian, uint_least64_t, 48, alignment::unaligned > unative48_pt;
- typedef endian_pack< native_endian, uint_least64_t, 56, alignment::unaligned > unative56_pt;
- typedef endian_pack< native_endian, uint_least64_t, 64, alignment::unaligned > unative64_pt;
-
-#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_pack signed integer types
- // aligned big endian_pack unsigned integer types
- // aligned little endian_pack signed integer types
- // aligned little endian_pack unsigned integer types
-
- // aligned native endian_pack typedefs are not provided because
- // <cstdint> types are superior for this use case
-
-# if defined(BOOST_HAS_INT16_T)
- typedef endian_pack< big_endian, int16_t, 16, alignment::aligned > aligned_big16_pt;
- typedef endian_pack< big_endian, uint16_t, 16, alignment::aligned > aligned_ubig16_pt;
- typedef endian_pack< little_endian, int16_t, 16, alignment::aligned > aligned_little16_pt;
- typedef endian_pack< little_endian, uint16_t, 16, alignment::aligned > aligned_ulittle16_pt;
-# endif
-
-# if defined(BOOST_HAS_INT32_T)
- typedef endian_pack< big_endian, int32_t, 32, alignment::aligned > aligned_big32_pt;
- typedef endian_pack< big_endian, uint32_t, 32, alignment::aligned > aligned_ubig32_pt;
- typedef endian_pack< little_endian, int32_t, 32, alignment::aligned > aligned_little32_pt;
- typedef endian_pack< little_endian, uint32_t, 32, alignment::aligned > aligned_ulittle32_pt;
-# endif
-
-# if defined(BOOST_HAS_INT64_T)
- typedef endian_pack< big_endian, int64_t, 64, alignment::aligned > aligned_big64_pt;
- typedef endian_pack< big_endian, uint64_t, 64, alignment::aligned > aligned_ubig64_pt;
- typedef endian_pack< little_endian, int64_t, 64, alignment::aligned > aligned_little64_pt;
- typedef endian_pack< little_endian, uint64_t, 64, alignment::aligned > aligned_ulittle64_pt;
-# endif
-
- template<typename OSTREAM, typename E,
- typename T, std::size_t N,
- BOOST_SCOPED_ENUM(alignment) A>
- OSTREAM&
- operator<<(OSTREAM & os,
- const endian_pack< E,T,N,A > & aval) {
- os << T(aval);
- return os;
-
- }
-
- } // namespace integer
-} // namespace boost
-
-#if defined(__BORLANDC__) || defined( __CODEGEARC__)
-# pragma pack(pop)
-#endif
-
-#endif // BOOST_INTEGER_ENDIAN_PACK_HPP
Deleted: sandbox/endian_ext/boost/integer/endian_type.hpp
==============================================================================
--- sandbox/endian_ext/boost/integer/endian_type.hpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
+++ (empty file)
@@ -1,169 +0,0 @@
-// Boost endian_type.hpp header file -------------------------------------------------------//
-
-// (C) Copyright VicenteJ Botet Escriba 2010
-
-// 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_INTEGER_ENDIAN_TYPE_HPP
-#define BOOST_INTEGER_ENDIAN_TYPE_HPP
-
-#include <boost/integer/endian.hpp>
-
-#include <boost/type_traits/is_fundamental.hpp>
-#include <boost/type_traits/is_same.hpp>
-#include <boost/fusion/support/is_sequence.hpp>
-#include <boost/fusion/sequence/intrinsic/front.hpp>
-#include <boost/fusion/iterator/next.hpp>
-#include <boost/fusion/iterator/deref.hpp>
-#include <boost/fusion/sequence/intrinsic/begin.hpp>
-#include <boost/fusion/sequence/intrinsic/end.hpp>
-#include <boost/fusion/iterator/value_of_data.hpp>
-#include <boost/mpl/if.hpp>
-#include <boost/mpl/int.hpp>
-#include <boost/type_traits/is_same.hpp>
-#include <boost/type_traits/remove_cv.hpp>
-#include <boost/type_traits/remove_reference.hpp>
-
-
-namespace boost {
-namespace integer {
-
-namespace integer_detail {
-
-template <typename T,
- bool isFundamental = is_fundamental<T>::value,
- bool IsSeq = fusion::traits::is_sequence<T>::value
- >
-struct endian_type_impl;
-
-}
-
-template <typename T>
-struct endian_type : integer_detail::endian_type_impl<T> {
-};
-
-namespace integer_detail {
-
-//~ // fundamental types are native
-template <typename T, bool IsSeq>
-struct endian_type_impl<T, true, IsSeq> {
- typedef endianness::native type;
-};
-
-// we can consider that any other type which has not been explicitly declared is native, but it is more conservative to state that it could be mixted.
-template <typename T>
-struct endian_type_impl<T, false, false> {
- typedef endianness::mixed type;
-};
-
-// if temp is equal the endian_type of the *it continue otherwise mixed
-template <typename res, typename It, typename End
-> struct endian_type_loop {
-private:
- typedef
- typename remove_reference<
- typename remove_cv<
- typename fusion::result_of::deref<It>::type
- >::type
- >::type it_type;
-public:
- typedef typename mpl::if_<is_same<typename endian_type< it_type >::type,res>,
- typename endian_type_loop<res,typename fusion::result_of::next<It>::type, End>::type,
- endianness::mixed
- >::type type;
-};
-
-// endian_type of mixed is mixed
-template <typename It, typename End>
-struct endian_type_loop<endianness::mixed,It,End> {
- typedef endianness::mixed type;
-};
-
-// temp when iteration ends
-template <typename temp, typename End>
-struct endian_type_loop<temp,End,End> {
- typedef temp type;
-};
-
-// fusion sequences are mixed if not all the elements habve the same endianess,
-// otherwise the endianess of all the types.
-template <typename Seq>
-struct endian_type_impl<Seq, false, true> {
-private:
- typedef typename remove_reference<
- typename remove_cv<
- typename fusion::result_of::front<Seq>::type
- >::type
- >::type front_type;
-
-public:
- typedef typename endian_type_loop<typename endian_type< front_type >::type,
- typename fusion::result_of::begin<Seq>::type,
- typename fusion::result_of::end<Seq>::type
- >::type type;
-};
-
-
-}
-
-
-template <typename T>
-struct endian_type<T*> {
- // it is undefined the endianess of a pointer
-};
-
-template <typename T, std::size_t N>
-struct endian_type<T[N]> : endian_type<T> {};
-
-// endianess of endian<E,T,n_bits,A> is E
-template <
- typename E,
- typename T,
- std::size_t n_bits,
- BOOST_SCOPED_ENUM(alignment) A
-> struct endian_type<endian_pack<E,T,n_bits,A> >
-{
- typedef E type;
-};
-
-// endianess of endian<E,T,n_bits,A> is E
-template <
- typename E,
- typename T,
- std::size_t n_bits,
- BOOST_SCOPED_ENUM(alignment) A
-> struct endian_type<endian<E,T,n_bits,A> >
-{
- typedef E type;
-};
-
-template <typename T>
-struct is_native :
- is_same<typename endian_type<T>::type, endianness::native>
-{};
-
-template <typename T>
-struct is_big :
- is_same<typename endian_type<T>::type, endianness::big>
-{};
-
-template <typename T>
-struct is_little :
- is_same<typename endian_type<T>::type, endianness::little>
-{};
-
-template <typename T>
-struct is_mixed :
- is_same<typename endian_type<T>::type, endianness::mixed>
-{};
-
-
-} // namespace integer
-} // namespace boost
-
-#endif // BOOST_ENDIAN_HPP
Deleted: sandbox/endian_ext/boost/integer/endian_view.hpp
==============================================================================
--- sandbox/endian_ext/boost/integer/endian_view.hpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
+++ (empty file)
@@ -1,133 +0,0 @@
-// Boost endian_view.hpp header file -------------------------------------------------------//
-
-// (C) Copyright VicenteJ Botet Escriba 2010
-
-// 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_INTEGER_ENDIAN_VIEW_HPP
-#define BOOST_INTEGER_ENDIAN_VIEW_HPP
-
-#include <boost/integer/endian_pack.hpp>
-#include <boost/fusion/include/is_sequence.hpp>
-#include <boost/type_traits/is_fundamental.hpp>
-
-namespace boost {
-
-namespace integer {
-
- template <typename EndianSource, typename T>
- void convert_from(T& r);
- template <typename EndianTarget, typename T>
- void convert_to(T& r);
- template <typename EndianTarget, typename EndianSource, typename T>
- void convert_to_from(T& r);
-
- template <typename Endian, typename T,
- bool IsFundamental = is_fundamental<T>::value,
- bool IsSeq = fusion::traits::is_sequence<T>::value
- >
- class endian_view;
-
- template <typename Endian, typename T >
- class endian_view<Endian,T,true,false>
- {
- //~ typedef typename Endian::value_type T;
- //~ template friend
- public:
- typedef T value_type;
- value_type &ref_;
-
- typedef endian_pack<Endian,value_type> endian_t;
- endian_view(value_type& ref) : ref_(ref) {};
- operator value_type() const {
- endian_t& v=reinterpret_cast<endian_t&>(ref_);
- return v;
- }
- endian_view& operator=(value_type val) {
- endian_t& v=reinterpret_cast<endian_t&>(ref_);
- v=val;
- return *this;
- }
- endian_view& operator=(endian_view const& rhs) {
- if (this!=&rhs) {
- ref_=rhs.ref_;
- }
- return *this;
- }
- template <typename Endian2 >
- endian_view& operator=(endian_view<Endian2,T,true,false> const& rhs) {
- endian_t& v=reinterpret_cast<endian_t&>(ref_);
- endian_pack<Endian2,value_type>& val=reinterpret_cast<endian_pack<Endian2,value_type>&>(rhs.ref_);
- v=val;
- return *this;
- }
- };
-
- template <typename Endian, typename T >
- class endian_view<Endian,T,false,true>
- {
- public:
- typedef T value_type;
- value_type &ref_;
-
- endian_view(value_type& ref) : ref_(ref) {};
- operator value_type() const {
- value_type res=ref_;
- convert_from<Endian>(res);
- return res;
- }
- endian_view& operator=(value_type val) {
- ref_=val;
- convert_to<Endian>(ref_);
- return *this;
- }
- endian_view& operator=(endian_view const& rhs) {
- if (this!=&rhs) {
- ref_=rhs.ref_;
- }
- return *this;
- }
- template <typename Endian2 >
- endian_view& operator=(endian_view<Endian2,T,true,false> const& rhs) {
- ref_=rhs.ref_;
- convert_to_from<Endian2,Endian>(ref_);
- return *this;
- }
- };
-
- template <typename E, typename T>
- endian_view<E,T> as_endian(T& v) {
- return endian_view<E,T>(v);
- }
-
- template <typename T>
- endian_view<native_endian,T> as(T& v)
- {
- return as_endian<native_endian>(v);
- }
- template <typename T>
- endian_view<little_endian,T> as_little(T& v)
- {
- return as_endian<little_endian>(v);
- }
-
- template <typename T>
- endian_view<big_endian,T> as_big(T& v)
- {
- return as_endian<big_endian>(v);
- }
-
-
-} // namespace integer
-} // namespace boost
-
-#include <boost/integer/endian_conversion.hpp>
-
-
-#endif // BOOST_INTEGER_ENDIAN_VIEW_HPP
Added: sandbox/endian_ext/libs/integer/endian/doc/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/doc/Jamfile.v2 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,72 @@
+# Boost.Integer.Endian library documentation Jamfile ---------------------------------
+#
+# Copyright Vicente J. Botet Escriba 2009. Use, modification and
+# distribution is subject to the Boost Software License, Version
+# 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+#
+# See http://www.boost.org for updates, documentation, and revision history.
+
+#import doxygen ;
+import quickbook ;
+
+#doxygen autodoc
+# :
+# [ glob ../../../boost/interprocess/*.hpp ]
+# [ glob ../../../boost/interprocess/allocators/*.hpp ]
+# :
+# <doxygen:param>EXTRACT_ALL=NO
+# <doxygen:param>HIDE_UNDOC_MEMBERS=YES
+# <doxygen:param>EXTRACT_PRIVATE=NO
+# <doxygen:param>EXPAND_ONLY_PREDEF=YES
+# <doxygen:param>PREDEFINED=BOOST_INTERPROCESS_DOXYGEN_INVOKED
+# <xsl:param>"boost.doxygen.reftitle=Boost.Interprocess Reference"
+# ;
+
+xml integer_endian : integer_endian.qbk ;
+
+boostbook standalone
+ :
+ integer_endian
+ :
+ # HTML options first:
+ # Use graphics not text for navigation:
+ <xsl:param>navig.graphics=1
+ # How far down we chunk nested sections, basically all of them:
+ <xsl:param>chunk.section.depth=2
+ # Don't put the first section on the same page as the TOC:
+ <xsl:param>chunk.first.sections=1
+ # How far down sections get TOC's
+ <xsl:param>toc.section.depth=4
+ # Max depth in each TOC:
+ <xsl:param>toc.max.depth=2
+ # How far down we go with TOC's
+ <xsl:param>generate.section.toc.level=10
+ # Path for links to Boost:
+ <xsl:param>boost.root=../../../..
+ # Path for libraries index:
+ <xsl:param>boost.libraries=../../../../libs/libraries.htm
+ # Use the main Boost stylesheet:
+ <xsl:param>html.stylesheet=../../../../doc/html/boostbook.css
+
+ # PDF Options:
+ # TOC Generation: this is needed for FOP-0.9 and later:
+ #<xsl:param>fop1.extensions=1
+ # Or enable this if you're using XEP:
+ <xsl:param>xep.extensions=1
+ # TOC generation: this is needed for FOP 0.2, but must not be set to zero for FOP-0.9!
+ <xsl:param>fop.extensions=0
+ # No indent on body text:
+ <xsl:param>body.start.indent=0pt
+ # Margin size:
+ <xsl:param>page.margin.inner=0.5in
+ # Margin size:
+ <xsl:param>page.margin.outer=0.5in
+ # Yes, we want graphics for admonishments:
+ <xsl:param>admon.graphics=1
+ # Set this one for PDF generation *only*:
+ # default pnd graphics are awful in PDF form,
+ # better use SVG's instead:
+ <format>pdf:<xsl:param>admon.graphics.extension=".svg"
+ <format>pdf:<xsl:param>admon.graphics.path=$(boost-images)/
+ ;
Added: sandbox/endian_ext/libs/integer/endian/doc/endian.html
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/doc/endian.html 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,646 @@
+<html>
+
+<head>
+<meta http-equiv="Content-Language" content="en-us">
+<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
+<meta name="ProgId" content="FrontPage.Editor.Document">
+<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
+<title>Boost Endian Integers</title>
+<link rel="stylesheet" type="text/css" href="../../../doc/html/minimal.css">
+</head>
+
+<body>
+
+
+<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
+ <tr>
+ <td width="277">
+<a href="../../../index.html">
+<img src="../../../boost.png" alt="boost.png (6897 bytes)" align="middle" width="277" height="86" border="0"></a></td>
+ <td width="337" align="middle">
+ <font size="7">Endian Integers</font>
+ </td>
+ </tr>
+</table>
+
+<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" bgcolor="#D7EEFF" width="100%">
+ <tr>
+ <td>Boost Home Tutorial</td>
+ </tr>
+</table>
+
+<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" align="right">
+ <tr>
+ <td width="100%" bgcolor="#D7EEFF" align="center">
+ <i><b>Contents</b></i></td>
+ </tr>
+ <tr>
+ <td width="100%" bgcolor="#E8F5FF">
+ Introduction<br>
+ Hello endian world<br>
+ Limitations<br>
+ Feature set<br>
+ Typedefs<br>
+ Comment on naming<br>
+ Class template endian
<br>
+
+ Synopsis<br>
+ Members<br>
+ FAQ<br>
+ Binary I/O warnings and cautions<br>
+ Example<br>
+ Design<br>
+ Experience<br>
+ C++0x<br>
+ Compilation<br>
+ Acknowledgements
+ </td>
+ </tr>
+ <tr>
+ <td width="100%" bgcolor="#D7EEFF" align="center">
+ <b><i>Headers</i></b></td>
+ </tr>
+ <tr>
+ <td width="100%" bgcolor="#E8F5FF">
+ <boost/integer/endian.hpp><br>
+ <boost/integer/endian_binary_stream.hpp><br>
+ <boost/binary_stream.hpp></td>
+ </tr>
+</table>
+<h2><a name="Introduction">Introduction</a></h2>
+<p>Header
+ <boost/integer/endian.hpp> provides
+integer-like byte-holder binary types with explicit control over
+byte order, value type, size, and alignment. Typedefs provide easy-to-use names
+for common configurations.</p>
+<p>These types provide portable byte-holders for integer data, independent of
+particular computer architectures. Use cases almost always involve I/O, either via files or
+network connections. Although data portability is the primary motivation, these
+integer byte-holders may
+also be used to reduce memory use, file size, or network activity since they
+provide binary integer sizes not otherwise available.</p>
+<p>Such integer byte-holder types are traditionally called <b><i>
+endian</i></b> types. See the Wikipedia for
+a full
+exploration of <b><i>endianness</i></b>, including definitions of <i><b>big
+endian</b></i> and <i><b>little endian</b></i>.</p>
+<p>Boost endian integers provide the same full set of C++ assignment,
+arithmetic, and relational operators as C++ standard integral types, with
+the standard semantics.</p>
+<p>Unary arithmetic operators are <code>+</code>, <code>-</code>, <code>~</code>,
+<code>!</code>, prefix and postfix <code>--</code> and <code>++</code>. Binary
+arithmetic operators are <code>+</code>, <code>+=</code>, <code>-</code>, <code>
+-=</code>, <code>*</code>, <code>*=</code>, <code>/</code>, <code>/=</code>,
+<code>%/ %=</code>, <code>&</code>, <code>&=</code>, <code>|</code>, <code>|=</code>,
+<code>^</code>, <code>^=</code>, <code><<</code>, <code><<=</code>, <code>>></code>,
+<code>>>=</code>. Binary relational operators are <code>==</code>, <code>!=</code>,
+<code><</code>, <code><=</code>, <code>></code>, <code>>=</code>.</p>
+<p>Automatic conversion is provided to the underlying integer value type.</p>
+<p>Header <boost/integer/endian_binary_stream.hpp>
+provides operators <= and <code>=></code> for unformatted binary (as opposed to
+formatted character) stream insertion and extraction of endian types.</p>
+<p>Header <boost/binary_stream.hpp>
+provides operators <= and <code>=></code> for unformatted binary (as opposed to
+formatted character) stream insertion and extraction of built-in and std::string
+types.</p>
+<h2><a name="Hello-endian-world">Hello endian world</a></h2>
+<blockquote>
+ <pre>#include <boost/integer/endian.hpp>
+#include <boost/integer/endian_binary_stream.hpp>
+#include <boost/binary_stream.hpp>
+#include <iostream>
+
+using namespace boost;
+using namespace boost::integer;
+
+int main()
+{
+ int_least32_t v = 0x31323334L; // = ASCII { '1', '2', '3', '4' }
+ // value chosen to work on text stream
+ big32_t b(v);
+ little32_t l(v);
+
+ std::cout << "Hello, endian world!\n\n";
+
+ std::cout << v << ' ' << b << ' ' << l << '\n';
+ std::cout <= v <= ' ' <= b <= ' ' <= l <= '\n';
+}</pre>
+</blockquote>
+<p>On a little-endian CPU, this program outputs:</p>
+<blockquote>
+ <pre>Hello, endian world!
+
+825373492 825373492 825373492
+4321 1234 4321</pre>
+</blockquote>
+<h2><a name="Limitations">Limitations</a></h2>
+<p>Requires <code><climits></code> <code>CHAR_BIT == 8</code>. If <code>CHAR_BIT</code>
+is some other value, compilation will result in an <code>#error</code>. This
+restriction is in place because the design, implementation, testing, and
+documentation has only considered issues related to 8-bit bytes, and there have
+been no real-world use cases presented for other sizes.</p>
+<p>In C++03, <code>endian</code> does not meet the requirements for POD types
+because it has constructors, private data members, and a base class. This means
+that common use cases are relying on unspecified behavior in that the C++
+Standard does not guarantee memory layout for non-POD types. This has not been a
+problem in practice since all known C++ compilers do layout memory as if <code>
+endian</code> were a POD type. In C++0x, it will be possible to specify the
+default constructor as trivial, and private data members and base classes will
+no longer disqualify a type from being a POD. Thus under C++0x, <code>endian</code>
+will no longer be relying on unspecified behavior.</p>
+<h2><a name="Feature-set">Feature set</a></h2>
+<ul>
+ <li>Big endian| little endian | native endian byte ordering.</li>
+ <li>Signed | unsigned</li>
+ <li>Unaligned | aligned</li>
+ <li>1-8 byte (unaligned) | 2, 4, 8 byte (aligned)</li>
+ <li>Choice of integer value type</li>
+</ul>
+<h2><a name="Types">Typedefs</a></h2>
+<p>One class template is provided:</p>
+<blockquote>
+ <pre>template <endianness::enum_t E, typename T, std::size_t n_bytes,
+ alignment::enum_t A = alignment::unaligned>
+class endian;
+</pre>
+</blockquote>
+<p>Sixty typedefs, such as <code>big32_t</code>, provide convenient naming
+conventions for common use cases:</p>
+<blockquote>
+<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="49%">
+ <tr>
+ <td width="18%" align="center"><b><i>Name</i></b></td>
+ <td width="10%" align="center"><b><i>Endianness</i></b></td>
+ <td width="10%" align="center"><b><i>Sign</i></b></td>
+ <td width="15%" align="center"><b><i>Sizes in bits (n)</i></b></td>
+ <td width="49%" align="center"><b><i>Alignment</i></b></td>
+ </tr>
+ <tr>
+ <td width="18%"><code>big</code><b><i>n</i></b><code>_t</code></td>
+ <td width="10%"><code>big</code></td>
+ <td width="10%">signed</td>
+ <td width="15%">8,16,24,32,40,48,56,64</td>
+ <td width="49%"><code>unaligned</code></td>
+ </tr>
+ <tr>
+ <td width="18%"><code>ubig</code><i><b>n</b></i><code>_t</code></td>
+ <td width="10%"><code>big</code></td>
+ <td width="10%">unsigned</td>
+ <td width="15%">8,16,24,32,40,48,56,64</td>
+ <td width="49%"><code>unaligned</code></td>
+ </tr>
+ <tr>
+ <td width="18%"><code>little</code><i><b>n</b></i><code>_t</code></td>
+ <td width="10%"><code>little</code></td>
+ <td width="10%">signed</td>
+ <td width="15%">8,16,24,32,40,48,56,64</td>
+ <td width="49%"><code>unaligned</code></td>
+ </tr>
+ <tr>
+ <td width="18%"><code>ulittle</code><i><b>n</b></i><code>_t</code></td>
+ <td width="10%"><code>little</code></td>
+ <td width="10%">unsigned</td>
+ <td width="15%">8,16,24,32,40,48,56,64</td>
+ <td width="49%"><code>unaligned</code></td>
+ </tr>
+ <tr>
+ <td width="18%"><code>native</code><i><b>n</b></i><code>_t</code></td>
+ <td width="10%"><code>native</code></td>
+ <td width="10%">signed</td>
+ <td width="15%">8,16,24,32,40,48,56,64</td>
+ <td width="49%"><code>unaligned</code></td>
+ </tr>
+ <tr>
+ <td width="18%"><code>unative</code><i><b>n</b></i><code>_t</code></td>
+ <td width="10%"><code>native</code></td>
+ <td width="10%">unsigned</td>
+ <td width="15%">8,16,24,32,40,48,56,64</td>
+ <td width="49%"><code>unaligned</code></td>
+ </tr>
+ <tr>
+ <td width="18%"><code>aligned_big</code><i><b>n</b></i><code>_t</code></td>
+ <td width="10%"><code>big</code></td>
+ <td width="10%">signed</td>
+ <td width="15%">16,32,64</td>
+ <td width="49%"><code>aligned</code></td>
+ </tr>
+ <tr>
+ <td width="18%"><code>aligned_ubig</code><i><b>n</b></i><code>_t</code></td>
+ <td width="10%"><code>big</code></td>
+ <td width="10%">unsigned</td>
+ <td width="15%">16,32,64</td>
+ <td width="49%"><code>aligned</code></td>
+ </tr>
+ <tr>
+ <td width="18%"><code>aligned_little</code><i><b>n</b></i><code>_t</code></td>
+ <td width="10%"><code>little</code></td>
+ <td width="10%">signed</td>
+ <td width="15%">16,32,64</td>
+ <td width="49%"><code>aligned</code></td>
+ </tr>
+ <tr>
+ <td width="18%"><code>aligned_ulittle</code><i><b>n</b></i><code>_t</code></td>
+ <td width="10%"><code>little</code></td>
+ <td width="10%">unsigned</td>
+ <td width="15%">16,32,64</td>
+ <td width="49%"><code>aligned</code></td>
+ </tr>
+</table>
+</blockquote>
+<p>The unaligned types do not cause compilers to insert padding bytes in classes
+and structs. This is an important characteristic that can be exploited to minimize wasted space in
+memory, files, and network transmissions. </p>
+<p><font color="#FF0000"><b><i><span style="background-color: #FFFFFF">Warning:</span></i></b></font><span style="background-color: #FFFFFF">
+Code that uses a</span>ligned types is inherently non-portable because alignment
+requirements vary between hardware architectures and because alignment may be
+affected by compiler switches or pragmas. Furthermore, aligned types
+are only available on architectures with 16, 32, and 64-bit integer types.</p>
+<p><b><i>Note:</i></b> One-byte big-endian, little-endian, and native-endian types provide identical
+functionality. All three names are provided to improve code readability and searchability.</p>
+<h3><a name="Comment-on-naming">Comment on naming</a></h3>
+<p>When first exposed to endian types, programmers often fit them into a mental model
+based on the <code><cstdint></code> types. Using that model, it is natural to
+expect a 56-bit big-endian signed integer to be named <code>int_big56_t</code>
+rather than <code>big56_t</code>.</p>
+<p>As experience using these type grows, the realization creeps in that they are
+lousy arithmetic integers - they are really byte holders that for convenience
+support arithmetic operations - and that for use in internal interfaces or
+anything more than trivial arithmetic computations it is far better to convert
+values of these endian types to traditional integer types.</p>
+<p>That seems to lead to formation of a new mental model specific to endian byte-holder types. In that model, the endianness
+is the key feature, and the integer aspect is downplayed.
+Once that mental transition is made, a name like <code>big56_t</code> is a good
+reflection of the mental model</p>
+<h2><a name="Class_template_endian">Class template <code>endian</code></a></h2>
+<p>An endian is an integer byte-holder with user-specified <a href="#endianness">
+endianness</a>, value type, size, and alignment. The
+usual operations on integers are supplied.</p>
+<h3><a name="Synopsis">Synopsis</a></h3>
+<pre>namespace boost
+{
+ namespace integer
+ {
+
+ enum class <a name="endianness">endianness</a> { big, little, native }; // scoped enum emulated on C++03
+ enum class <a name="alignment">alignment</a> { unaligned, aligned }; // scoped enum emulated on C++03
+
+ template <endianness E, typename T, std::size_t n_bits,
+ alignment A = alignment::unaligned>
+ class endian : integer_cover_operators< endian<E, T, n_bits, A>, T >
+ {
+ public:
+ typedef T value_type;
+ endian() = default; // = default replaced by {} on C++03
+ explicit endian(T v);
+ endian & operator=(T v);
+ operator T() const;
+ };
+
+ // 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;
+
+ // These types only present if platform has exact size integers:
+
+ // aligned big endian signed integer types
+ typedef endian< endianness::big, int16_t, 16, alignment::aligned > aligned_big16_t;
+ typedef endian< endianness::big, int32_t, 32, alignment::aligned > aligned_big32_t;
+ typedef endian< endianness::big, int64_t, 64, alignment::aligned > aligned_big64_t;
+
+ // aligned big endian unsigned integer types
+ typedef endian< endianness::big, uint16_t, 16, alignment::aligned > aligned_ubig16_t;
+ typedef endian< endianness::big, uint32_t, 32, alignment::aligned > aligned_ubig32_t;
+ typedef endian< endianness::big, uint64_t, 64, alignment::aligned > aligned_ubig64_t;
+
+ // aligned little endian signed integer types
+ typedef endian< endianness::little, int16_t, 16, alignment::aligned > aligned_little2_t;
+ typedef endian< endianness::little, int32_t, 32, alignment::aligned > aligned_little4_t;
+ typedef endian< endianness::little, int64_t, 64, alignment::aligned > aligned_little8_t;
+
+ // aligned little endian unsigned integer types
+ typedef endian< endianness::little, uint16_t, 16, alignment::aligned > aligned_ulittle2_t;
+ typedef endian< endianness::little, uint32_t, 32, alignment::aligned > aligned_ulittle4_t;
+ typedef endian< endianness::little, uint64_t, 64, alignment::aligned > aligned_ulittle8_t;
+
+
+ // aligned native endian typedefs are not provided because
+ // <cstdint> types are superior for this use case
+
+ } // namespace integer
+} // namespace boost</pre>
+<h3><a name="Members">Members</a></h3>
+<p><code><a name="endian">endian</a>() = default; // C++03: endian(){}</code></p>
+<blockquote>
+<p><i>Effects:</i> Constructs an object of type <code>endian<E, T, n_bits, A></code>.</p>
+</blockquote>
+<p><code><a name="explicit-endian">explicit endian</a>(T v);</code></p>
+<blockquote>
+<p><i>Effects:</i> Constructs an object of type <code>endian<E, T, n_bits, A></code>.</p>
+<p><i>Postcondition:</i> <code>x == v,</code> where <code>x</code> is the
+constructed object.</p>
+</blockquote>
+<p><code>endian & <a name="operator-eq">operator=</a>(T v);</code></p>
+<blockquote>
+ <p><i>Postcondition:</i> <code>x == v,</code> where <code>x</code> is the
+ constructed object.</p>
+ <p><i>Returns:</i> <code>*this</code>.</p>
+</blockquote>
+<p><code><a name="operator-T">operator T</a>() const;</code></p>
+<blockquote>
+<p><i>Returns:</i> The current value stored in <code>*this</code>, converted to
+<code>value_type</code>.</p>
+</blockquote>
+<h3>Other operators</h3>
+<p>Other operators on endian objects are forwarded to the equivalent
+operator on <code>value_type</code>.</p>
+<h2><a name="FAQ">FAQ</a></h2>
+<p><b>Why bother with endian types?</b> External data portability and both speed
+and space efficiency. Availability
+of additional binary integer sizes and alignments is important in some
+applications.</p>
+<p><b>Why not just use Boost.Serialization?</b> Serialization involves a
+conversion for every object involved in I/O. Endian objects require no
+conversion or copying. They are already in the desired format for binary I/O.
+Thus they can be read or written in bulk.</p>
+<p><b>Why bother with binary I/O? Why not just use C++ Standard Library stream
+inserters and extractors?</b> Using binary rather than character representations
+can be more space efficient, with a side benefit of faster I/O. CPU time is
+minimized because conversions to and from string are eliminated.
+Furthermore, binary integers are fixed size, and so fixed-size disk records
+are possible, easing sorting and allowing direct access. Disadvantages, such as the inability to use
+text utilities on the resulting files, limit usefulness to applications where
+the
+binary I/O advantages are paramount.</p>
+<p><b>Do these types have any uses outside of I/O?</b> Probably not, except for
+native endianness which can be used for fine grained control over size and
+alignment.</p>
+<p><b>Is there is a performance hit when doing arithmetic using these types?</b> Yes, for sure,
+compared to arithmetic operations on native integer types. However, these types
+are usually be faster, and sometimes much faster, for I/O compared to stream
+inserters and extractors, or to serialization.</p>
+<p><b>Are endian types POD's?</b> Yes for C++0x. No for C++03, although several
+macros are available to force PODness in all cases.</p>
+<p><b>What are the implications endian types not being POD's of C++03?</b> They
+can't be used in unions. In theory, compilers aren't required to align or lay
+out storage in portable ways, although this problem has never been observed in a
+real compiler.</p>
+<p><b>Which is better, big-endian or little-endian?</b> Big-endian tends to be a
+bit more of an industry standard, but little-endian may be preferred for
+applications that run primarily on x86 (Intel/AMD) and other little-endian
+CPU's. The Wikipedia article
+gives more pros and cons.</p>
+<p><b>What good is <i>native </i>endianness?</b> It provides alignment and
+size guarantees not available from the built-in types. It eases generic
+programming.</p>
+<p><b>Why bother with the aligned endian types?</b> Aligned integer operations
+may be faster (20 times, in one measurement) if the endianness and alignment of
+the type matches the endianness and alignment requirements of the machine. On
+common CPU architectures, that optimization is only available for aligned types.
+That allows I/O of maximally efficient types on an application's primary
+platform, yet produces data files are portable to all platforms. The code,
+however, is
+likely to be more fragile and less portable than with the unaligned types.</p>
+<p><b>These types are really just byte-holders. Why provide the arithmetic
+operations at all?</b> Providing a full set of operations reduces program
+clutter and makes code both easier to write and to read. Consider
+incrementing a variable in a record. It is very convenient to write:</p>
+<pre wrap> ++record.foo;</pre>
+<p wrap>Rather than:</p>
+<pre wrap> int temp( record.foo);
+ ++temp;
+ record.foo = temp;</pre>
+<p wrap><b>Why do binary stream insertion and extraction use operators <= and >=
+rather than <<= and >>=?</b> <<= and >>= associate right-to-left, which is the
+opposite of << and >>, so would be very confusing and error prone. <= and >=
+associate left-to-right. </p>
+<h2><a name="Binary-I-O-cautions">Binary I/O warnings and cautions</a></h2>
+<p><font color="#FF0000"><b><i><span style="background-color: #FFFFFF">Warning:</span></i></b></font><span style="background-color: #FFFFFF"> </span> Use
+only on streams opened with filemode <code>std::ios_base::binary</code>. Thus
+unformatted binary I/O should not be with the standard streams (cout, cin, etc.)
+since they are opened in text mode. Use on text streams may produce incorrect
+results, such as insertion of unwanted characters or premature end-of-file. For
+example, on Windows 0x0D would become 0x0D, 0x0A.</p>
+<p><i><b><font color="#FF0000">Caution:</font><font color="#FFFF00"> </font></b>
+</i>When mixing formatted (i.e. operator << or >>) and unformatted (i.e.
+operator <= or >=) stream I/O, be aware that << and >> take precedence over <=
+and >=. Use parentheses to force correct order of evaluation. For example:</p>
+<blockquote>
+ <pre>my_stream << foo <= bar; // no parentheses needed
+(my_stream <= foo) << bar; // parentheses required </pre>
+</blockquote>
+<p>As a practical matter, it may be easier and safer to never mix the character
+and binary insertion or extraction operators in the same statement.</p>
+<h2><a name="Example">Example</a></h2>
+<p>The endian_example.cpp program writes a
+binary file containing four byte big-endian and little-endian integers:</p>
+<blockquote>
+ <pre>#include <iostream>
+#include <cassert>
+#include <cstdio>
+#include <boost/integer/endian.hpp>
+
+using namespace boost::integer;
+
+namespace
+{
+ // This is an extract from a very widely used GIS file format. I have no idea
+ // why a designer would mix big and little endians in the same file - but
+ // this is a real-world format and users wishing to write low level code
+ // manipulating these files have to deal with the mixed endianness.
+
+ struct header
+ {
+ big32_t file_code;
+ big32_t file_length;
+ little32_t version;
+ little32_t shape_type;
+ };
+
+ const char * filename = "test.dat";
+}
+
+int main()
+{
+ assert( sizeof( header ) == 16 ); // requirement for interoperability
+
+ header h;
+
+ h.file_code = 0x04030201;
+ h.file_length = sizeof( header );
+ h.version = -1;
+ h.shape_type = 0x04030201;
+
+ // Low-level I/O such as POSIX read/write or <cstdio> fread/fwrite is sometimes
+ // used for binary file operations when ultimate efficiency is important.
+ // Such I/O is often performed in some C++ wrapper class, but to drive home the
+ // point that endian integers are often used in fairly low-level code that
+ // does bulk I/O operations, <cstdio> fopen/fwrite is used for I/O in this example.
+
+ std::FILE * fi;
+
+ if ( !(fi = std::fopen( filename, "wb" )) ) // MUST BE BINARY
+ {
+ std::cout << "could not open " << filename << '\n';
+ return 1;
+ }
+
+ if ( std::fwrite( &h, sizeof( header ), 1, fi ) != 1 )
+ {
+ std::cout << "write failure for " << filename << '\n';
+ return 1;
+ }
+
+ std::fclose( fi );
+
+ std::cout << "created file " << filename << '\n';
+ return 0;
+}</pre>
+</blockquote>
+<p>After compiling and executing endian_example.cpp, a hex dump of <code>test.dat</code> shows:</p>
+<blockquote>
+ <pre>0403 0201 0000 0010 ffff ffff 0102 0304</pre>
+</blockquote>
+<h2><a name="Design">Design</a> considerations for Boost.Endian</h2>
+<ul>
+ <li>Must be suitable for I/O - in other words, must be memcpyable.</li>
+ <li>Must provide exactly the size and internal byte ordering specified.</li>
+ <li>Must work correctly when the internal integer representation has more bits
+ that the sum of the bits in the external byte representation. Sign extension
+ must work correctly when the internal integer representation type has more
+ bits than the sum of the bits in the external bytes. For example, using
+ a 64-bit integer internally to represent 40-bit (5 byte) numbers must work for
+ both positive and negative values.</li>
+ <li>Must work correctly (including using the same defined external
+ representation) regardless of whether a compiler treats char as signed or
+ unsigned.</li>
+ <li>Unaligned types must not cause compilers to insert padding bytes.</li>
+ <li>The implementation should supply optimizations only in very limited
+ circumstances. Experience has shown that optimizations of endian
+ integers often become pessimizations. While this may be obvious when changing
+ machines or compilers, it also happens when changing compiler switches,
+ compiler versions, or CPU models of the same architecture.</li>
+ <li>It is better software engineering if the same implementation works regardless
+ of the CPU endianness. In other words, #ifdefs should be avoided where
+ possible.</li>
+</ul>
+<h2><a name="Experience">Experience</a></h2>
+<p>Classes with similar functionality have been independently developed by
+several Boost programmers and used very successful in high-value, high-use
+applications for many years. These independently developed endian libraries
+often evolved from C libraries that were also widely used. Endian integers have proven widely useful across a wide
+range of computer architectures and applications.</p>
+<h2><a name="C++0x">C++0x</a></h2>
+<p>The availability of the C++0x
+<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2346.htm">
+Defaulted Functions</a> feature is detected automatically, and will be used if
+present to ensure that objects of <code>class endian</code> are trivial, and
+thus POD's.</p>
+<h2><a name="Compilation">Compilation</a></h2>
+<p>Boost.Endian is implemented entirely within headers, with no need to link to
+any Boost object libraries.</p>
+<p>Several macros allow user control over features:</p>
+<ul>
+ <li>BOOST_ENDIAN_NO_CTORS causes <code>class endian</code> to have no
+ constructors. The intended use is for compiling user code that must be
+ portable between compilers regardless of C++0x
+ <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2346.htm">
+ Defaulted Functions</a> support. Use of constructors will always fail, <br>
+ </li>
+ <li>BOOST_ENDIAN_FORCE_PODNESS causes BOOST_ENDIAN_NO_CTORS to be defined if
+ the compiler does not support C++0x
+ <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2346.htm">
+ Defaulted Functions</a>. This is ensures that , and so can be used in unions.
+ In C++0x, <code>class endian</code> objects are POD's even though they have
+ constructors.</li>
+</ul>
+<h2><a name="Acknowledgements">Acknowledgements</a></h2>
+<p>Original design developed by Darin Adler based on classes developed by Mark
+Borgerding. Four original class templates combined into a single <code>endian</code>
+class template by Beman Dawes, who put the library together, provided
+documentation, and added the typedefs. He also added the <code>unrolled_byte_loops</code>
+sign partial specialization to correctly extend the sign when cover integer size
+differs from endian representation size.</p>
+<p>Comments and suggestions were
+received from
+Benaka Moorthi,
+Christopher Kohlhoff,
+Cliff Green,
+Gennaro Proto,
+Jeff Flinn,
+John Maddock,
+Kim Barrett,
+Marsh Ray,
+Martin Bonner,
+Matias Capeletto,
+Rene Rivera,
+Scott McMurray,
+Sebastian Redl,
+Tomas Puverle, and
+Yuval Ronen.</p>
+<hr>
+<p>Last revised:
+<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->19 March, 2009<!--webbot bot="Timestamp" endspan i-checksum="29039" --></p>
+<p>© Copyright Beman Dawes, 2006-2009</p>
+<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
+file LICENSE_1_0.txt or copy at
+www.boost.org/ LICENSE_1_0.txt)</p>
+
+</body>
+
+</html>
\ No newline at end of file
Added: sandbox/endian_ext/libs/integer/endian/doc/index.html
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/doc/index.html 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,9 @@
+<html>
+<head>
+<meta http-equiv="refresh" content="0; URL=html/index.html">
+</head>
+<body>
+Automatic redirection failed, please go to
+../../doc/html/integer_endian.html
+</body>
+</html>
Added: sandbox/endian_ext/libs/integer/endian/doc/integer_endian.qbk
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/doc/integer_endian.qbk 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,1986 @@
+[/
+ / Copyright (c) 2006-2009 Beman Dawes
+ / Copyright (c) 2010 Vicente J. Botet Escriba
+ /
+ / Distributed under the Boost Software License, Version 1.0. (See accompanying
+ / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ /]
+
+[article Toward Boost.Integer.Endian
+ [quickbook 1.4]
+ [authors [Dawes, Beman]]
+ [authors [Botet Escriba, Vicente J.]]
+ [copyright 2006-2009 Beman Dawes]
+ [copyright 2010 Vicente J. Botet Escriba]
+ [purpose Endian Integers]
+ [license
+ Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file LICENSE_1_0.txt or copy at
+ [@http://www.boost.org/LICENSE_1_0.txt])
+ ]
+]
+
+[/
+[section Preface]
+
+[:[".]]
+[:[*['-- ]]]
+
+[endsect]
+/]
+
+[warning Integer.Endian is not a part of the Boost libraries.]
+
+
+[/========================]
+[section Overview]
+[/========================]
+
+[/==================]
+[heading Description]
+[/==================]
+
+This is an extension of the Beman's Boost.Integer.Endian, which was able to work with endian aware types, used to convert between types with different endian or even to carry on with arithmetic operations, by spliting the endian part from integer part and by adding support for aligned endian unaware types.
+
+[*Boost.Integer.Endian.Ext] provides:
+
+* Endian packs
+ * Big endian | little endian | native endian byte ordering.
+ * Signed | unsigned
+ * Unaligned | aligned
+ * 1-8 byte (unaligned) | 2, 4, 8 byte (aligned)
+ * Choice of integer value type
+
+* Endian integers with the whole set of arithmetics operators.
+
+* Operators <= and => for unformatted binary (as opposed to formatted character) stream insertion and extraction of built-in, std::string types and of endian types.
+
+* Views of aligned endian unaware integer types as endian packs or endian integers so we can make endian conversion.
+
+* Generic in place conversion between different endian formats.
+ * Very simple interface: convert_to/from<endiannes domain>(),
+ * Support for built-in and user-defined data types view as fusion sequences.
+
+
+[/====================================]
+[heading How to Use This Documentation]
+[/====================================]
+
+This documentation makes use of the following naming and formatting conventions.
+
+* Code is in `fixed width font` and is syntax-highlighted.
+* Replaceable text that you will need to supply is in [~italics].
+* If a name refers to a free function, it is specified like this:
+ `free_function()`; that is, it is in code font and its name is followed by `()` to indicate that it is a free function.
+* If a name refers to a class template, it is specified like this: `class_template<>`; that is, it is in code font and its name is followed by `<>` to indicate that it is a class template.
+* If a name refers to a function-like macro, it is specified like this: `MACRO()`;
+ that is, it is uppercase in code font and its name is followed by `()` to indicate that it is a function-like macro. Object-like macros appear without the trailing `()`.
+* Names that refer to /concepts/ in the generic programming sense are specified in CamelCase.
+
+[note In addition, notes such as this one specify non-essential information that provides additional background or rationale.]
+
+Finally, you can mentally add the following to any code fragments in this document:
+
+ // Include all of endian files
+ #include <boost/integer/endian.hpp>
+
+[/=================]
+[section Motivation]
+[/=================]
+
+The original Beman's version provided through the boost::integer::endian<> class an integer-like class that providing arithmetics operations on
+
+* Big endian | little endian | native endian byte ordering.
+* Signed | unsigned
+* Unaligned | aligned
+* 1-8 byte (unaligned) | 2, 4, 8 byte (aligned)
+* Choice of integer value type
+
+This endain aware design seems to be unappropiated to work with endian unaware types, but as we will see this is not completly true, as we can construct on top of the Beman's design endian unaware operation. Next follows some of the main critics that have been done recently.
+
+[heading Intrusive verus non-intrusive]
+[/====================================]
+
+Endian conversion must be possible to any type even if you can't modify the original source code. Many people think that originel Beman's library requires the data types which need to be converted to be coded using his endian types as members.
+
+We will see that this is not true, as the user can always use casting to reinterpret a given structure on another one, as the proposed extension does with the endian_views.
+
+ struct endian_unaware_structure {
+ int32_t a;
+ int16_t b;
+ };
+ endian_unaware_structure st_a;
+
+ endian_unaware_structure st_b;
+ as_endian<native>(st_b) = as_endian<big>(st_a);
+
+[heading Physical versus Logical data]
+[/===================================]
+
+The typical use case is to use native endianness until ready to read/write using wire format. It is only when ready to do I/O that there is a need to account for endianness.
+
+Beman's original library requires two types one to specify the physical data and the other representing the logical data.
+Many people think that this means that the user has to maintain two separate structs/classes when only one is needed. This could be sometimes the case, but in other cases, the user will store the information elements include in the message on local variables and specific contexts that don't follow the external format.
+
+Applications that don't separate the physical and the logical data structures don't scale well as any change on the external format will mean a refactoring of the whole application. Also, the wire structures cannot maintain invariants, so having a separate class is often useful even if its contents are essentially identical to the wire version.
+
+In addition a single and efficient view is only possible when the pysical view can be represented by native aligned integers. But when the physical view contains unaliged integers with sizes not supported by the platform, the need to separate both view becomes anavoidable. Here the Beman's design is the best adapted.
+
+[heading Inherent inefficient arithmetic operations]
+[/=================================================]
+
+The fact that the endian types provide operators gives the impression that it's ok to operate on them, as these operations can potentially require two endian conversions when the endianness is different.
+
+Some people don't agree with that design choice, as they think the operation of endian conversion and operating on the data should be divorced from each other. A less experienced user that you may end up not realizing what the hidden costs are and use the endian aware integer-like types throughout the application, paying unnecessary overheads. They prefer a library that makes hard to misuse in that way; borrowing a phrase from python, "explicit is better than implicit". They believe that forcing the user to do the explicit endian conversion leads to better separation of concerns for the application, but they don't propose any mean to force this conversion.
+
+The extension proposal separates the endian aware byte-holder type from the one able to make arithmetic operations so the user will be forced to convert for one to/from the native type, and avoid unfortunate costly atithmetic operations.
+
+ struct endian_aware_structure {
+ endian_pack<big,int32_t> a;
+ endian_pack<big,int16_t> b;
+ };
+
+
+Structure endian_aware_structure can not be used without converting to native types, as endian_pack don't provide other operations than conversion.
+
+ endian_aware_structure st;
+ // ...
+ st.a=i;
+ st.b=j;
+
+But don't removes the inefficient and endian safe class, as less demanding applications would benefit from the safe and transparent approach.
+
+[heading In-place conversion]
+[/==========================]
+
+Other contexts force the user to make in place conversions. While this could be dangerous, there are context on which a funtional conversion is not possible, mainly because the duplicated space could not be an option. These in-place conversions are only possible for aligned endian unaware types.
+
+ struct endian_unaware_structure {
+ int32_t a;
+ int16_t b;
+ };
+ endian_unaware_structure st;
+
+ as_endian<native>(st) = as_endian<big>(st);
+
+The fact that some context need this in-place conversion doesn't mean that every application should use this approach.
+
+
+[heading UDT endianness]
+[/=====================]
+
+boost::integer::endian class didn't accept a UDT. We have updated the library so now UDT can be used for endian aligned types.
+
+ struct UserMessage {
+ endian_pack<little, system_clock::time_point > timestamp;
+ ulittle32_pt aircraft_id;
+ struct Position {
+ endian_pack<little, quantity<si::length, boost::int_least32_t> > x;
+ endian_pack<little, quantity<si::length, boost::int_least32_t> > y;
+ endian_pack<little, quantity<si::length, boost::int_least32_t> > z;
+ } position;
+ struct Attitude {
+ endian_pack<little, quantity<si::plane_angle, boost::int_least8_t> > heading;
+ endian_pack<little, quantity<si::plane_angle, boost::int_least8_t> > pitch;
+ endian_pack<little, quantity<si::plane_angle, boost::int_least8_t> > roll;
+ } attitude;
+ }; // UserMessage
+
+
+[heading Mixed endianness]
+[/=======================]
+
+Sometimes we need to deal with messages with mixed endianness.
+A functional approach means the programmer has to "know" which endianess the data he wants to convert has.
+
+ struct UdpHeader {
+ ubig16_pt source_port;
+ ubig16_pt destination_port;
+ ubig16_pt length;
+ ubig16_pt checksum;
+ }; // UdpHeader
+
+ struct Packet {
+ internet::UdpHeader udpHeader;
+ UserMessage userMessage;
+ }; // Packet
+
+
+
+[/A real-world use-case that uses multiple endians and has
+different protocol layers.
+That is one over-the-wire packet has several layers of headers, possibly
+with different endian alignment than the user payload contained. This is
+common on PC's which often have big-endian IP headers and then have a
+little-endian user payload. The whole packet is read in from a socket at
+once into a data buffer owned by a unique_ptr, so the message is not copied
+from layer-to-layer. I work on proprietary, non-internet networks, so I'm
+not sure which protocol headers we should use for a use-case. In my
+wireless applications, the headers are usually padded to an integral number
+of bytes, but fields within the headers are sometimes not byte-aligned.
+]
+
+
+[heading Floating point]
+[/====================================]
+
+From my understanding floating point types are not only concerned by endianness, but also by a multitude of standard on not standard formats.
+
+[heading Conclusion]
+[/=================]
+
+The library must support applications needing to work safely with endian aware types and efficiently with in place endian conversions.
+
+Conversions between native and big/little endian formats must be simple.
+
+[endsect]
+[endsect]
+
+[/==============================]
+[section:users_guide Users'Guide]
+[/==============================]
+
+[/======================================]
+[section:getting_started Getting Started]
+[/======================================]
+
+[/======================================]
+[section:install Installing Integer.Endian]
+[/======================================]
+
+[/=================================]
+[heading Getting Boost.Integer.Endian]
+[/=================================]
+
+You can get the last stable release of Boost.Integer.Endian by downloading [^integer_endian.zip] from the
+[@http://www.boost-consulting.com/vault/index.php?directory=Portability%20Programming Boost Vault]
+
+You can also access the latest (unstable?) state from the [@https://svn.boost.org/svn/boost/sandbox/endian_split Boost Sandbox].
+
+[heading Building Boost.Integer.Endian]
+[/====================================]
+
+Boost.Integer.Endian is implemented entirely within headers, with no need to link to any Boost object libraries.
+
+Several macros allow user control over features:
+
+* BOOST_ENDIAN_NO_CTORS causes class endian to have no constructors. The intended use is for compiling user code that must be portable between compilers regardless of C++0x Defaulted Functions support. Use of constructors will always fail,
+
+* BOOST_ENDIAN_FORCE_PODNESS causes BOOST_ENDIAN_NO_CTORS to be defined if the compiler does not support C++0x Defaulted Functions. This is ensures that , and so can be used in unions. In C++0x, class endian objects are POD's even though they have constructors.
+
+
+
+[/=========================]
+[heading Requirements]
+[/=========================]
+
+[*Boost.Integer.Endian] depends on some Boost library. The library has been tested with version 1.43.0 but an older version should works also.
+
+
+[/========================]
+[heading Exceptions safety]
+[/========================]
+
+All functions in the library are exception-neutral and provide strong guarantee of exception safety as long as the underlying parameters provide it.
+
+[/====================]
+[heading Thread safety]
+[/====================]
+
+All functions in the library are thread-unsafe except when noted explicitly.
+
+[/=======================]
+[heading Tested compilers]
+[/=======================]
+
+Currently, [*Boost.Integer.Endian] has been tested in the following compilers/platforms:
+
+* GCC 3.4.4 Cygwin
+* GCC 4.4.0 MinGw
+* MSV9 9 EXpress Windows
+
+[/* GCC 4.3.2 Cygwin]
+[/* GCC 4.1.2 Linux]
+
+[note Please send any questions, comments and bug reports to boost <at> lists <dot> boost <dot> org.]
+
+[endsect]
+[/=============================]
+[section Hello Endian World! ]
+[/=============================]
+
+
+ #include <boost/integer/endian.hpp>
+ #include <boost/integer/endian_binary_stream.hpp>
+ #include <boost/binary_stream.hpp>
+ #include <iostream>
+
+ using namespace boost;
+ using namespace boost::integer;
+
+ int main()
+ {
+ int_least32_t v = 0x31323334L; // = ASCII { '1', '2', '3', '4' }
+ // value chosen to work on text stream
+ big32_t b(v);
+ little32_t l(v);
+
+ std::cout << "Hello, endian world!\n\n";
+
+ std::cout << v << ' ' << b << ' ' << l << '\n';
+ std::cout <= v <= ' ' <= b <= ' ' <= l <= '\n';
+ }
+
+On a little-endian CPU, this program outputs:
+
+ Hello, endian world!
+
+ 825373492 825373492 825373492
+ 4321 1234 4321
+
+[endsect]
+
+[/===================]
+[section Limitations ]
+[/===================]
+
+Requires `<climits> CHAR_BIT == 8`. If `CHAR_BIT` is some other value, compilation will result in an `#error`. This restriction is in place because the design, implementation, testing, and documentation has only considered issues related to 8-bit bytes, and there have been no real-world use cases presented for other sizes.
+
+In C++03, endian does not meet the requirements for POD types because it has constructors, private data members, and a base class. This means that common use cases are relying on unspecified behavior in that the C++ Standard does not guarantee memory layout for non-POD types. This has not been a problem in practice since all known C++ compilers do layout memory as if endian were a POD type. In C++0x, it will be possible to specify the default constructor as trivial, and private data members and base classes will no longer disqualify a type from being a POD. Thus under C++0x, endian will no longer be relying on unspecified behavior.
+
+[heading Binary I/O warnings and cautions]
+
+[warning Use only on streams opened with filemode `std::ios_base::binary`. Thus unformatted binary I/O should not be with the standard streams (`cout`, `cin`, etc.) since they are opened in text mode. Use on text streams may produce incorrect results, such as insertion of unwanted characters or premature end-of-file. For example, on Windows `0x0D` would become `0x0D`, `0x0A`.]
+
+[warning Caution: When mixing formatted (i.e. operator `<<` or `>>`) and unformatted (i.e. operator `<=` or `>=`) stream I/O, be aware that `<<` and `>>` take precedence over `<=` and `>=`. Use parentheses to force correct order of evaluation. For example:
+
+```
+ my_stream << foo <= bar; // no parentheses needed
+ (my_stream <= foo) << bar; // parentheses required
+```
+As a practical matter, it may be easier and safer to never mix the character and binary insertion or extraction operators in the same statement.
+]
+
+[endsect]
+[endsect]
+
+[/===============]
+[section Tutorial]
+[/===============]
+
+[/=========================]
+[section Endian aware types]
+[/=========================]
+
+[heading basic endian holders]
+
+Boost.Integer.Endian provides an endian aware byte-holder class template:
+
+ template <endianness::enum_t E, typename T, std::size_t n_bytes=8*sizeof(T),
+ alignment::enum_t A = alignment::aligned>
+ class endian_pack;
+
+This class provide portable byte-holders for data, independent of particular computer architectures. Use cases almost always involve I/O, either via files or network connections. Although data portability is the primary motivation, these byte-holders may also be used to reduce memory use, file size, or network activity since they provide binary integer sizes not otherwise available.
+
+Such byte-holder types are traditionally called endian types. See the Wikipedia for a full exploration of endianness, including definitions of big endian and little endian.
+
+This class doesn't provides arithmetic operators, but of course automatic conversion to and assignment from the underlying integer value type are provided.
+
+ #include <boost/integer/endian_pack.hpp>
+ #include <iostream>
+
+ using namespace boost;
+ using namespace boost::integer;
+ using namespace boost::endianness;
+
+
+ int main()
+ {
+ int_least32_t v = 0x31323334L; // = ASCII { '1', '2', '3', '4' }
+ // value chosen to work on text stream
+
+ endian_pack<big, int_least32_t> b(v);
+ endian_pack<little, int_least32_t> l(v);
+
+ std::cout << v << ' ' << b << ' ' << l << '\n';
+ return 0;
+ }
+
+On a little-endian CPU, this program outputs:
+
+ 825373492 825373492 825373492
+
+[heading Binary streams]
+
+Header <boost/binary_stream.hpp> provides operators `<=` and `=>` for unformatted binary (as opposed to formatted character) stream insertion and extraction of built-in and std::string types.
+
+Header <boost/integer/endian_binary_stream.hpp> provides operators `<=` and `=>` for unformatted binary (as opposed to formatted character) stream insertion and extraction of endian types.
+
+ #include <boost/integer/endian_pack.hpp>
+ #include <boost/integer/endian_binary_stream.hpp>
+ #include <boost/binary_stream.hpp>
+ #include <iostream>
+
+ using namespace boost;
+ using namespace boost::integer;
+ using namespace boost::endianness;
+
+
+ int main()
+ {
+ int_least32_t n = 0x31323334L; // = ASCII { '1', '2', '3', '4' }
+ // value chosen to work on text stream
+
+ endian_pack<big, int_least32_t> b(n);
+ endian_pack<little, int_least32_t> l(n);
+
+ std::cout << n << ' ' << b << ' ' << l << '\n';
+ std::cout <= n <= ' ' <= b <= ' ' <= l <= '\n';
+ return 0;
+ }
+
+On a little-endian CPU, this program outputs:
+
+ Hello, endian world!
+
+ 825373492 825373492 825373492
+ 4321 1234 4321
+
+
+[heading endian aware unaligned byte holders]
+
+
+ #include <boost/integer/endian_pack.hpp>
+ #include <iostream>
+
+ using namespace boost;
+ using namespace boost::integer;
+ using namespace boost::endianness;
+
+
+ int main()
+ {
+ int_least32_t v = 0x313233L; // = ASCII { '1', '2', '3' }
+ // value chosen to work on text stream
+
+ endian_pack<big, int_least32_t, 24, unaligned> b(v);
+ endian_pack<little, int_least32_t, 24, unaligned> l(v);
+
+ std::cout << v << ' ' << b << ' ' << l << '\n';
+ std::cout <= b <= ' ' <= l <= '\n';
+ return 0;
+ }
+
+On a little-endian CPU, this program outputs:
+
+ 3224115 3224115 3224115
+ 123 321
+
+
+[heading endian holders common typedefs]
+
+
+Sixty typedefs, such as big32_t, provide convenient naming conventions for common use cases:
+
+
+[table
+ [[Name] [Endianness] [Sign] [Sizes in bits (n)] [Alignment]]
+ [[`big`*n*`_t`] [`big`] [signed] [8,16,24,32,40,48,56,64] [`unaligned`]]
+ [[`ubig`*n*`_t`] [`big`] [unsigned] [8,16,24,32,40,48,56,64] [`unaligned`]]
+ [[`little`*n*`_t`] [`little`] [signed] [8,16,24,32,40,48,56,64] [`unaligned`]]
+ [[`ulittle`*n*`_t`] [`little`] [unsigned] [8,16,24,32,40,48,56,64] [`unaligned`]]
+ [[`ulittle`*n*`_t`] [`native`] [signed] [8,16,24,32,40,48,56,64] [`unaligned`]]
+ [[`unative`*n*`_t`] [`native`] [unsigned] [16,32,64] [`aligned`]]
+ [[`aligned_big`*n*`_t`] [`big`] [signed] [16,32,64] [`aligned`]]
+ [[`aligned_ubig`*n*`_t`] [`big`] [unsigned] [16,32,64] [`aligned`]]
+ [[`aligned_little`*n*`_t`] [`big`] [signed] [16,32,64] [`aligned`]]
+ [[`aligned_ulittle`*n*`_t`] [`big`] [unsigned] [16,32,64] [`aligned`]]
+]
+
+The unaligned types do not cause compilers to insert padding bytes in classes and structs. This is an important characteristic that can be exploited to minimize wasted space in memory, files, and network transmissions.
+
+[warning Code that uses aligned types is inherently non-portable because alignment requirements vary between hardware architectures and because alignment may be affected by compiler switches or pragmas. Furthermore, aligned types are only available on architectures with 16, 32, and 64-bit integer types.]
+
+[note One-byte big-endian, little-endian, and native-endian types provide identical functionality. All three names are provided to improve code readability and searchability.
+]
+
+[*Comment on naming]
+
+When first exposed to endian types, programmers often fit them into a mental model based on the <cstdint> types. Using that model, it is natural to expect a 56-bit big-endian signed integer to be named `int_big56_t`. But these byte-hodlers are not realy integers.
+
+That seems to lead to formation of a new mental model specific to endian byte-holder types. In that model, the endianness is the key feature, and the integer aspect is downplayed. Once that mental transition is made, a name like `big56_t` is a good reflection of the mental model.
+
+
+
+ #include <boost/integer/endian_pack.hpp>
+ #include <iostream>
+
+ using namespace boost;
+ using namespace boost::integer;
+
+
+ int main()
+ {
+ int_least32_t v = 0x31323334L; // = ASCII { '1', '2', '3', '4' }
+ // value chosen to work on text stream
+ big32_t b(v);
+ little32_t l(v);
+
+ std::cout << v << ' ' << b << ' ' << l << '\n';
+ return 0;
+ }
+
+On a little-endian CPU, this program outputs:
+
+ 825373492 825373492 825373492
+
+
+[heading endian holders of UDT]
+
+The user can define wrappers to integer types that behave as integers, as it is the case for
+quantity<> class. This UDT can be packaged on an endian holder to take care of endian issues, as show the following example.
+
+ #include <boost/integer/endian_pack.hpp>
+ #include <boost/integer/endian_binary_stream.hpp>
+ #include <boost/binary_stream.hpp>
+ #include <iostream>
+ #include <boost/units/io.hpp>
+ #include <boost/units/quantity.hpp>
+ #include <boost/units/systems/si/length.hpp>
+ #include <boost/units/systems/si/plane_angle.hpp>
+
+ using namespace boost;
+ using namespace boost::integer;
+ using namespace boost::endianness;
+ using namespace boost::units;
+
+ int main()
+ {
+ quantity<si::length, boost::int_least32_t> q = 825373492 * si::meter;
+ endian_pack<big, quantity<si::length, boost::int_least32_t> > b;
+ endian_pack<little, quantity<si::length, boost::int_least32_t> > l;
+ b=q;
+ l=q;
+ std::cout << q << ' ' << b << ' ' << l << '\n';
+ std::cout <= b <= ' ' <= l <= '\n';
+ return 0;
+ }
+
+On a little-endian CPU, this program outputs:
+
+ 825373492 m 825373492 m 825373492 m
+ 1234 4321
+
+[heading Arrays of endian holders]
+
+Up to now we have see how to work with endian aware byte holders variables. In this section we will see how to work with arrays of endian aware byte holders.
+
+ #include <boost/integer/endian_pack.hpp>
+ #include <boost/integer/endian_binary_stream.hpp>
+ #include <boost/binary_stream.hpp>
+ #include <iostream>
+
+ using namespace boost;
+ using namespace boost::integer;
+
+ int main()
+ {
+ int_least32_t an[100] = { 0x31323334L }; // = ASCII { '1', '2', '3', '4' }
+ // value chosen to work on text stream
+ big32_t ab[100];
+ little32_t al[100];
+
+ for_each
+
+ std::cout << an[3] << ' ' << ab[3] << ' ' << al[3] << '\n';
+ std::cout <= an[3] <= ' ' <= ab[3] <= ' ' <= al[3] <= '\n';
+ return 0;
+ }
+
+
+[heading Structures of endian holders]
+
+ struct UdpHeader {
+ ubig16_pt source_port;
+ ubig16_pt destination_port;
+ ubig16_pt length;
+ ubig16_pt checksum;
+ }; // UdpHeader
+
+ UdpHeader header;
+ header.source_port = 1111;
+ header.destination_port = 1234;
+ header.length = get_length(p);
+ header.checksum = checksum_of(p);
+
+
+[/===========================]
+[section Endian unaware integers]
+[/===========================]
+
+Boost endian integers are based on the byte_holder endian_pack class template and provide in addition the same full set of C++ assignment, arithmetic, and relational operators as C++ standard integral types, with the standard semantics.
+
+One class template is provided:
+
+ template <endianness::enum_t E, typename T, std::size_t n_bytes=8*sizeof(T),
+ alignment::enum_t A = alignment::aligned>
+ class endian;
+
+Unary arithmetic operators are `+`, `-`, `~`, `!`, prefix and postfix `--` and `++`. Binary arithmetic operators are `+`, `+=`, `-`, `-=`, `*`, `*=`, `/`, `/=`, `%`, `%=`, `&`, `&=`, `|`, `|=`, `^`, `^=`, `<<`, `<<=`, `>>`, `>>=`. Binary relational operators are `==`, `!=`, `<`, `<=`, `>`, `>=`.
+
+Automatic conversion is provided to the underlying integer value type.
+
+[heading Typedefs]
+
+
+Sixty typedefs, such as big32_t, provide convenient naming conventions for common use cases:
+
+
+[table
+ [[Name] [Endianness] [Sign] [Sizes in bits (n)] [Alignment]]
+ [[`int_big`*n*`_t`] [`big`] [signed] [8,16,24,32,40,48,56,64] [`unaligned`]]
+ [[`uint_big`*n*`_t`] [`big`] [unsigned] [8,16,24,32,40,48,56,64] [`unaligned`]]
+ [[`int_little`*n*`_t`] [`little`] [signed] [8,16,24,32,40,48,56,64] [`unaligned`]]
+ [[`uint_little`*n*`_t`] [`little`] [unsigned] [8,16,24,32,40,48,56,64] [`unaligned`]]
+ [[`uint_little`*n*`_t`] [`native`] [signed] [8,16,24,32,40,48,56,64] [`unaligned`]]
+ [[`uint_native`*n*`_t`] [`native`] [unsigned] [16,32,64] [`aligned`]]
+ [[`aligned_int_big`*n*`_t`] [`big`] [signed] [16,32,64] [`aligned`]]
+ [[`aligned_uint_big`*n*`_t`] [`big`] [unsigned] [16,32,64] [`aligned`]]
+ [[`aligned_int_little`*n*`_t`] [`little`] [signed] [16,32,64] [`aligned`]]
+ [[`aligned_uint_little`*n*`_t`] [`little`] [unsigned] [16,32,64] [`aligned`]]
+]
+
+
+[heading Comment on naming]
+
+When first exposed to endian types, programmers often fit them into a mental model based on the <cstdint> types. Using that model, it is natural to expect a 56-bit big-endian signed integer to be named `int_big56_t`.
+
+As experience using these types grows, the realization creeps in that they are lousy arithmetic integers - they are really byte holders that for convenience support arithmetic operations - and that for use in internal interfaces or anything more than trivial arithmetic computations it is far better to convert values of these endian types to traditional integer types.
+
+
+[endsect]
+[endsect]
+
+[/===========================]
+[section Endian unaware types]
+[/===========================]
+
+[heading Working with third party structures]
+
+
+[heading Domain map]
+
+[heading In-place conversions]
+
+[endsect]
+
+
+
+[endsect]
+
+
+[/================================]
+[section:ext_references References]
+[/================================]
+
+[/variablelist
+
+[
+ [[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2346.htm [*C++0X N2346 - Defaulted and Deleted Functions]]]
+ [syntax and semantics for explicitly using the default definition of a function. We also propose a syntax and semantics for deleting the definition of an otherwise visible function, from Lawrence Crowl]
+]
+
+
+]
+
+
+
+[endsect]
+
+[endsect]
+
+
+[/================]
+[section Reference]
+[/================]
+
+[/==========================================================================================]
+[section:alignment_hpp Header `<boost/alignment.hpp>`]
+[/==========================================================================================]
+
+[heading Synopsis]
+
+ namespace boost
+ {
+ enum class alignment { unaligned, aligned }; // scoped enum emulated on C++03
+ }
+
+
+[/==========================================================================================]
+[section:endian_alignment Enum Class `alignment`]
+[/==========================================================================================]
+
+ // scoped enum emulated on C++03
+ enum class alignment { unaligned, aligned };
+
+
+[endsect]
+
+[endsect]
+
+[/==========================================================================================]
+[section:integer_endianness_hpp Header `<boost/integer/endiannes.hpp>`]
+[/==========================================================================================]
+
+Header <boost/endian/endianness.hpp> provides the endianness tags.
+
+[heading Synopsis]
+
+ namespace boost {
+ namespace endianness {
+ struct big;
+ struct little;
+ struct middle;
+ struct mixed;
+ typedef <platform dependent> native ;
+ }
+ }
+
+[/
+ // scoped enum emulated on C++03
+ enum class endianness { big, little, middle, mixed, native=<platform dependent> };
+
+
+[/==========================================================================================]
+[section:endian_endianness Enum Class `endianness`]
+[/==========================================================================================]
+
+ enum class endianness { big, little, middle, mixed, native=<platform dependent> };
+
+[endsect]
+]
+
+[/==========================================================================================]
+[section:endian_big Class `big`]
+[/==========================================================================================]
+
+Big endian tag.
+
+ struct big {};
+
+
+[endsect]
+[/==========================================================================================]
+[section:endian_little Class `little`]
+[/==========================================================================================]
+
+Little endian tag.
+
+ struct little {};
+
+
+[endsect]
+[/==========================================================================================]
+[section:endian_middle Class `middle`]
+[/==========================================================================================]
+
+Middle endian tag.
+
+ struct middle {};
+
+[endsect]
+[/==========================================================================================]
+[section:endian_mixed Class `mixed`]
+[/==========================================================================================]
+
+Mixed endian tag.
+
+ struct mixed {};
+
+
+[endsect]
+[/==========================================================================================]
+[section:endian_native Class `native`]
+[/==========================================================================================]
+
+Native endian tag.
+
+ typedef <platform dependent> native ;
+
+
+[endsect]
+
+[endsect]
+
+[/==========================================================================================]
+[section:endian_domain_map_hpp Header `<boost/endian/domain_map.hpp>`]
+[/==========================================================================================]
+
+This file contains the default implementation ofr the `domaain_map` metafunction.
+
+[heading Synopsis]
+
+ namespace boost {
+ namespace endian {
+ template <typename Domain, typename T>
+ struct domain_map;
+ }}
+
+
+[/==========================================================================================]
+[section:domain_map Meta Function `domain_map<>`]
+[/==========================================================================================]
+
+ template <typename Domain, typename T>
+ struct domain_map {
+ typedef <see below> type;
+ };
+
+* [*Requires:]
+
+ * `Domain` any class. Can be also `endianness::big` or `endianness::little`.
+
+* [*Result:] The member typedef `type` names a mpl tree of sequence of `endianness` types as view from the point of view of the `Domain`. The default definition is a mpl tree having as leaves the `Domain` class for `T` fundamental types, and fusion sequences.
+
+* [*Example:]
+
+ is_same<domain_map<endianness::big, int>::type, endianness::big>::value == true
+
+ struct ifA {};
+
+
+The user needs to specialize this metafunction for specific domains.
+
+[/warning It is undefined any specialization of this class for the `endianness` `big` and `little`.]
+
+[endsect]
+
+[endsect]
+
+[/==========================================================================================]
+[section:binary_stream_hpp Header `<boost/binary_stream.hpp>`]
+[/==========================================================================================]
+
+Header <boost/binary_stream.hpp> provides operators `<=` and `=>` for unformatted binary (as opposed to formatted character) stream insertion and extraction of built-in and std::string types.
+
+[heading Synopsis]
+
+ namespace boost
+ {
+
+ // built-in types ------------------------------------------------------------------//
+
+ std::ostream& operator<=(std::ostream& os, short v);
+ std::istream& operator>=(std::istream& is, short& v);
+
+ std::ostream& operator<=(std::ostream& os, unsigned short v);
+ std::istream& operator>=(std::istream& is, unsigned short& v);
+
+ std::ostream& operator<=(std::ostream& os, int v);
+ std::istream& operator>=(std::istream& is, int& v);
+
+ std::ostream& operator<=(std::ostream& os, unsigned int v);
+ std::istream& operator>=(std::istream& is, unsigned int& v);
+
+ std::ostream& operator<=(std::ostream& os, long v);
+ std::istream& operator>=(std::istream& is, long& v);
+
+ std::ostream& operator<=(std::ostream& os, unsigned long v);
+ std::istream& operator>=(std::istream& is, unsigned long& v);
+
+ std::ostream& operator<=(std::ostream& os, long long v);
+ std::istream& operator>=(std::istream& is, long long& v);
+
+ std::ostream& operator<=(std::ostream& os, unsigned long long v);
+ std::istream& operator>=(std::istream& is, unsigned long long& v);
+
+ std::ostream& operator<=(std::ostream& os, float v);
+ std::istream& operator>=(std::istream& is, float& v);
+
+ std::ostream& operator<=(std::ostream& os, double v);
+ std::istream& operator>=(std::istream& is, double& v);
+
+ std::ostream& operator<=(std::ostream& os, long double v);
+ std::istream& operator>=(std::istream& is, long double& v);
+
+ std::ostream& operator<=(std::ostream& os, char c);
+ std::istream& operator>=(std::istream& is, char& c);
+
+ std::ostream& operator<=(std::ostream& os, signed char c);
+ std::istream& operator>=(std::istream& is, signed char& c);
+
+ std::ostream& operator<=(std::ostream& os, unsigned char c);
+ std::istream& operator>=(std::istream& is, unsigned char& c);
+
+ std::ostream& operator<=(std::ostream& os, wchar_t v);
+ std::istream& operator>=(std::istream& is, wchar_t& v);
+
+ // strings -------------------------------------------------------------------------//
+
+ std::ostream& operator<=(std::ostream& os, const char* p);
+
+ std::ostream& operator<=(std::ostream& os, const signed char* p);
+
+ std::ostream& operator<=(std::ostream& os, const unsigned char* p);
+
+ #ifndef BOOST_NO_CWCHAR
+ std::ostream& operator<=(std::ostream& os, const wchar_t* p);
+ #endif
+
+ std::ostream& operator<=(std::ostream& os, const std::string& s);
+ std::istream& operator>=(std::istream& is, std::string& s);
+
+ #ifndef BOOST_NO_STD_WSTRING
+ std::ostream& operator<=(std::ostream& os, const std::wstring& s);
+ std::istream& operator>=(std::istream& is, std::wstring& s);
+ #endif
+
+ } // namespace boost
+
+[note Omission of bool and void* is deliberate; any semantics would be questionable]
+
+[warning
+Note the asymmetry between output and input; a string with embedded
+nulls will be output with the embedded nulls, but input will stop at the first null.
+So it probably isn't a good idea to use these functions for strings with nulls.
+]
+
+[endsect]
+
+
+[/==========================================================================================]
+[section:integer_endian_pack_hpp Header `<boost/integer/endian_pack.hpp>`]
+[/==========================================================================================]
+
+This file contains the core class template of Boost.Integer.Endian. Provides byte-holder binary types with explicit control over byte order, value type, size, and alignment. Typedefs provide easy-to-use names for common configurations.
+
+[heading Synopsis]
+
+ namespace boost {
+ namespace integer {
+ BOOST_SCOPED_ENUM_START(alignment) { unaligned, aligned }; BOOST_SCOPED_ENUM_END
+
+ template <typename E,
+ typename T,
+ std::size_t n_bits=sizeof(T)*8,
+ BOOST_SCOPED_ENUM(alignment) A = alignment::aligned
+ > class endian_pack;
+
+ // unaligned big endian_pack signed integer types
+ typedef endian_pack< endianness::big, int_least8_t, 8, alignment::unaligned > big8_pt;
+ typedef endian_pack< endianness::big, int_least16_t, 16, alignment::unaligned > big16_pt;
+ typedef endian_pack< endianness::big, int_least32_t, 24, alignment::unaligned > big24_pt;
+ typedef endian_pack< endianness::big, int_least32_t, 32, alignment::unaligned > big32_pt;
+ typedef endian_pack< endianness::big, int_least64_t, 40, alignment::unaligned > big40_pt;
+ typedef endian_pack< endianness::big, int_least64_t, 48, alignment::unaligned > big48_pt;
+ typedef endian_pack< endianness::big, int_least64_t, 56, alignment::unaligned > big56_pt;
+ typedef endian_pack< endianness::big, int_least64_t, 64, alignment::unaligned > big64_pt;
+
+ // unaligned big endian_pack unsigned integer types
+ typedef endian_pack< endianness::big, uint_least8_t, 8, alignment::unaligned > ubig8_pt;
+ typedef endian_pack< endianness::big, uint_least16_t, 16, alignment::unaligned > ubig16_pt;
+ typedef endian_pack< endianness::big, uint_least32_t, 24, alignment::unaligned > ubig24_pt;
+ typedef endian_pack< endianness::big, uint_least32_t, 32, alignment::unaligned > ubig32_pt;
+ typedef endian_pack< endianness::big, uint_least64_t, 40, alignment::unaligned > ubig40_pt;
+ typedef endian_pack< endianness::big, uint_least64_t, 48, alignment::unaligned > ubig48_pt;
+ typedef endian_pack< endianness::big, uint_least64_t, 56, alignment::unaligned > ubig56_pt;
+ typedef endian_pack< endianness::big, uint_least64_t, 64, alignment::unaligned > ubig64_pt;
+
+ // unaligned little endian_pack signed integer types
+ typedef endian_pack< endianness::little, int_least8_t, 8, alignment::unaligned > little8_pt;
+ typedef endian_pack< endianness::little, int_least16_t, 16, alignment::unaligned > little16_pt;
+ typedef endian_pack< endianness::little, int_least32_t, 24, alignment::unaligned > little24_pt;
+ typedef endian_pack< endianness::little, int_least32_t, 32, alignment::unaligned > little32_pt;
+ typedef endian_pack< endianness::little, int_least64_t, 40, alignment::unaligned > little40_pt;
+ typedef endian_pack< endianness::little, int_least64_t, 48, alignment::unaligned > little48_pt;
+ typedef endian_pack< endianness::little, int_least64_t, 56, alignment::unaligned > little56_pt;
+ typedef endian_pack< endianness::little, int_least64_t, 64, alignment::unaligned > little64_pt;
+
+ // unaligned little endian_pack unsigned integer types
+ typedef endian_pack< endianness::little, uint_least8_t, 8, alignment::unaligned > ulittle8_pt;
+ typedef endian_pack< endianness::little, uint_least16_t, 16, alignment::unaligned > ulittle16_pt;
+ typedef endian_pack< endianness::little, uint_least32_t, 24, alignment::unaligned > ulittle24_pt;
+ typedef endian_pack< endianness::little, uint_least32_t, 32, alignment::unaligned > ulittle32_pt;
+ typedef endian_pack< endianness::little, uint_least64_t, 40, alignment::unaligned > ulittle40_pt;
+ typedef endian_pack< endianness::little, uint_least64_t, 48, alignment::unaligned > ulittle48_pt;
+ typedef endian_pack< endianness::little, uint_least64_t, 56, alignment::unaligned > ulittle56_pt;
+ typedef endian_pack< endianness::little, uint_least64_t, 64, alignment::unaligned > ulittle64_pt;
+
+ // unaligned native endian_pack signed integer types
+ typedef endian_pack< endianness::native, int_least8_t, 8, alignment::unaligned > native8_pt;
+ typedef endian_pack< endianness::native, int_least16_t, 16, alignment::unaligned > native16_pt;
+ typedef endian_pack< endianness::native, int_least32_t, 24, alignment::unaligned > native24_pt;
+ typedef endian_pack< endianness::native, int_least32_t, 32, alignment::unaligned > native32_pt;
+ typedef endian_pack< endianness::native, int_least64_t, 40, alignment::unaligned > native40_pt;
+ typedef endian_pack< endianness::native, int_least64_t, 48, alignment::unaligned > native48_pt;
+ typedef endian_pack< endianness::native, int_least64_t, 56, alignment::unaligned > native56_pt;
+ typedef endian_pack< endianness::native, int_least64_t, 64, alignment::unaligned > native64_pt;
+
+ // unaligned native endian_pack unsigned integer types
+ typedef endian_pack< endianness::native, uint_least8_t, 8, alignment::unaligned > unative8_pt;
+ typedef endian_pack< endianness::native, uint_least16_t, 16, alignment::unaligned > unative16_pt;
+ typedef endian_pack< endianness::native, uint_least32_t, 24, alignment::unaligned > unative24_pt;
+ typedef endian_pack< endianness::native, uint_least32_t, 32, alignment::unaligned > unative32_pt;
+ typedef endian_pack< endianness::native, uint_least64_t, 40, alignment::unaligned > unative40_pt;
+ typedef endian_pack< endianness::native, uint_least64_t, 48, alignment::unaligned > unative48_pt;
+ typedef endian_pack< endianness::native, uint_least64_t, 56, alignment::unaligned > unative56_pt;
+ typedef endian_pack< endianness::native, uint_least64_t, 64, alignment::unaligned > unative64_pt;
+
+ #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_pack signed integer types
+ // aligned big endian_pack unsigned integer types
+ // aligned little endian_pack signed integer types
+ // aligned little endian_pack unsigned integer types
+
+ // aligned native endian_pack typedefs are not provided because
+ // <cstdint> types are superior for this use case
+
+ # if defined(BOOST_HAS_INT16_T)
+ typedef endian_pack< endianness::big, int16_t, 16, alignment::aligned > aligned_big16_pt;
+ typedef endian_pack< endianness::big, uint16_t, 16, alignment::aligned > aligned_ubig16_pt;
+ typedef endian_pack< endianness::little, int16_t, 16, alignment::aligned > aligned_little16_pt;
+ typedef endian_pack< endianness::little, uint16_t, 16, alignment::aligned > aligned_ulittle16_pt;
+ # endif
+
+ # if defined(BOOST_HAS_INT32_T)
+ typedef endian_pack< endianness::big, int32_t, 32, alignment::aligned > aligned_big32_pt;
+ typedef endian_pack< endianness::big, uint32_t, 32, alignment::aligned > aligned_ubig32_pt;
+ typedef endian_pack< endianness::little, int32_t, 32, alignment::aligned > aligned_little32_pt;
+ typedef endian_pack< endianness::little, uint32_t, 32, alignment::aligned > aligned_ulittle32_pt;
+ # endif
+
+ # if defined(BOOST_HAS_INT64_T)
+ typedef endian_pack< endianness::big, int64_t, 64, alignment::aligned > aligned_big64_pt;
+ typedef endian_pack< endianness::big, uint64_t, 64, alignment::aligned > aligned_ubig64_pt;
+ typedef endian_pack< endianness::little, int64_t, 64, alignment::aligned > aligned_little64_pt;
+ typedef endian_pack< endianness::little, uint64_t, 64, alignment::aligned > aligned_ulittle64_pt;
+ # endif
+
+ }
+ }
+
+[/==========================================================================================]
+[section:endian_pack Template class `endian_pack<>`]
+[/==========================================================================================]
+
+An `endian_pack` is an byte-holder with user-specified endianness, value type, size, and alignment.
+
+ template <
+ typename E,
+ typename T,
+ std::size_t n_bits=8*sizeof(T),
+ alignment A = alignment::aligned>
+ class endian_pack {
+ public:
+ typedef E endian_type;
+ typedef T value_type;
+ static const std::size_t width = n_bits;
+ static const alignment alignment_value = A;
+
+ endian_pack() = default; // = default replaced by {} on C++03
+ explicit endian_pack(T v);
+ endian_pack & operator=(T v);
+ operator T() const;
+ const char* data() const;
+ };
+
+
+* [*Requires:]
+
+ * `E` is one of `endianness::big` or `endianness::little`.
+ * `T` must be a POD with value semantics.
+ * `nbits` is a multiple of `8`
+ * If `A` is `alignment::aligned` then `nbits` must be equal to `8*sizeof(T)`
+
+[note if BOOST_ENDIAN_FORCE_PODNESS is defined && C++0x POD's are not
+available then these two constructors will not be present]
+
+
+[/==========================================================================================]
+[section:endian Default Contructor `endian_pack()`]
+[/==========================================================================================]
+
+ endian_pack() = default; // C++03: endian(){}
+
+* [*Effects:] Constructs an object of type `endian<E, T, n_bits, A>`.
+
+[endsect]
+
+[/==========================================================================================]
+[section:endianT Contructor from value_type `endian_pack(T)`]
+[/==========================================================================================]
+
+ explicit endian_pack(T v);
+
+* [*Effects:] Constructs an object of type `endian_pack<E, T, n_bits, A>`.
+* [*Postcondition:] `x == v`, where `x` is the constructed object.
+
+[endsect]
+
+[/==========================================================================================]
+[section:assignment Assignment Operator from value_type `operator=(T)`]
+[/==========================================================================================]
+
+ endian & operator=(T v);
+
+* [*Postcondition:] `x == v`, where `x` is the constructed object.
+* [*Returns:] `*this`.
+
+[endsect]
+
+[/==========================================================================================]
+[section:conversion Conversion Operator `operator T()`]
+[/==========================================================================================]
+
+ operator T() const;
+
+* [*Returns:] The current value stored in `*this`, converted to `value_type`.
+
+[endsect]
+
+[/==========================================================================================]
+[section:data Member Function `data()`]
+[/==========================================================================================]
+
+ const char* data() const;
+
+* [*Returns:] The current value stored in `*this`, converted to `value_type`.
+
+[endsect]
+
+[endsect]
+
+[/==========================================================================================]
+[section:typedefs Common typedefs]
+[/==========================================================================================]
+
+[endsect]
+
+[endsect]
+[/==========================================================================================]
+[section:integer_endian_hpp Header `<boost/integer/endian.hpp>`]
+[/==========================================================================================]
+
+Header `<boost/integer/endian.hpp>` provides integer-like byte-holder binary types with explicit control over byte order, value type, size, and alignment. Typedefs provide easy-to-use names for common configurations.
+
+
+[heading Synopsis]
+
+ namespace boost {
+ namespace integer {
+
+ template <typename E, typename T, std::size_t n_bits,
+ alignment A = alignment::unaligned>
+ class endian;
+
+ // unaligned big endian signed integer types
+ typedef endian< endianness::big, int_least8_t, 8, alignment::unaligned > big8_t;
+ typedef endian< endianness::big, int_least16_t, 16, alignment::unaligned > big16_t;
+ typedef endian< endianness::big, int_least32_t, 24, alignment::unaligned > big24_t;
+ typedef endian< endianness::big, int_least32_t, 32, alignment::unaligned > big32_t;
+ typedef endian< endianness::big, int_least64_t, 40, alignment::unaligned > big40_t;
+ typedef endian< endianness::big, int_least64_t, 48, alignment::unaligned > big48_t;
+ typedef endian< endianness::big, int_least64_t, 56, alignment::unaligned > big56_t;
+ typedef endian< endianness::big, int_least64_t, 64, alignment::unaligned > big64_t;
+
+ // unaligned big endian unsigned integer types
+ typedef endian< endianness::big, uint_least8_t, 8, alignment::unaligned > ubig8_t;
+ typedef endian< endianness::big, uint_least16_t, 16, alignment::unaligned > ubig16_t;
+ typedef endian< endianness::big, uint_least32_t, 24, alignment::unaligned > ubig24_t;
+ typedef endian< endianness::big, uint_least32_t, 32, alignment::unaligned > ubig32_t;
+ typedef endian< endianness::big, uint_least64_t, 40, alignment::unaligned > ubig40_t;
+ typedef endian< endianness::big, uint_least64_t, 48, alignment::unaligned > ubig48_t;
+ typedef endian< endianness::big, uint_least64_t, 56, alignment::unaligned > ubig56_t;
+ typedef endian< endianness::big, uint_least64_t, 64, alignment::unaligned > ubig64_t;
+
+ // unaligned little endian signed integer types
+ typedef endian< endianness::little, int_least8_t, 8, alignment::unaligned > little8_t;
+ typedef endian< endianness::little, int_least16_t, 16, alignment::unaligned > little16_t;
+ typedef endian< endianness::little, int_least32_t, 24, alignment::unaligned > little24_t;
+ typedef endian< endianness::little, int_least32_t, 32, alignment::unaligned > little32_t;
+ typedef endian< endianness::little, int_least64_t, 40, alignment::unaligned > little40_t;
+ typedef endian< endianness::little, int_least64_t, 48, alignment::unaligned > little48_t;
+ typedef endian< endianness::little, int_least64_t, 56, alignment::unaligned > little56_t;
+ typedef endian< endianness::little, int_least64_t, 64, alignment::unaligned > little64_t;
+
+ // unaligned little endian unsigned integer types
+ typedef endian< endianness::little, uint_least8_t, 8, alignment::unaligned > ulittle8_t;
+ typedef endian< endianness::little, uint_least16_t, 16, alignment::unaligned > ulittle16_t;
+ typedef endian< endianness::little, uint_least32_t, 24, alignment::unaligned > ulittle24_t;
+ typedef endian< endianness::little, uint_least32_t, 32, alignment::unaligned > ulittle32_t;
+ typedef endian< endianness::little, uint_least64_t, 40, alignment::unaligned > ulittle40_t;
+ typedef endian< endianness::little, uint_least64_t, 48, alignment::unaligned > ulittle48_t;
+ typedef endian< endianness::little, uint_least64_t, 56, alignment::unaligned > ulittle56_t;
+ typedef endian< endianness::little, uint_least64_t, 64, alignment::unaligned > ulittle64_t;
+
+ // unaligned native endian signed integer types
+ typedef endian< endianness::native, int_least8_t, 8, alignment::unaligned > native8_t;
+ typedef endian< endianness::native, int_least16_t, 16, alignment::unaligned > native16_t;
+ typedef endian< endianness::native, int_least32_t, 24, alignment::unaligned > native24_t;
+ typedef endian< endianness::native, int_least32_t, 32, alignment::unaligned > native32_t;
+ typedef endian< endianness::native, int_least64_t, 40, alignment::unaligned > native40_t;
+ typedef endian< endianness::native, int_least64_t, 48, alignment::unaligned > native48_t;
+ typedef endian< endianness::native, int_least64_t, 56, alignment::unaligned > native56_t;
+ typedef endian< endianness::native, int_least64_t, 64, alignment::unaligned > native64_t;
+
+ // unaligned native endian unsigned integer types
+ typedef endian< endianness::native, uint_least8_t, 8, alignment::unaligned > unative8_t;
+ typedef endian< endianness::native, uint_least16_t, 16, alignment::unaligned > unative16_t;
+ typedef endian< endianness::native, uint_least32_t, 24, alignment::unaligned > unative24_t;
+ typedef endian< endianness::native, uint_least32_t, 32, alignment::unaligned > unative32_t;
+ typedef endian< endianness::native, uint_least64_t, 40, alignment::unaligned > unative40_t;
+ typedef endian< endianness::native, uint_least64_t, 48, alignment::unaligned > unative48_t;
+ typedef endian< endianness::native, uint_least64_t, 56, alignment::unaligned > unative56_t;
+ typedef endian< endianness::native, uint_least64_t, 64, alignment::unaligned > unative64_t;
+
+ // These types only present if platform has exact size integers:
+
+ // aligned big endian signed integer types
+ typedef endian< endianness::big, int16_t, 16, alignment::aligned > aligned_big16_t;
+ typedef endian< endianness::big, int32_t, 32, alignment::aligned > aligned_big32_t;
+ typedef endian< endianness::big, int64_t, 64, alignment::aligned > aligned_big64_t;
+
+ // aligned big endian unsigned integer types
+ typedef endian< endianness::big, uint16_t, 16, alignment::aligned > aligned_ubig16_t;
+ typedef endian< endianness::big, uint32_t, 32, alignment::aligned > aligned_ubig32_t;
+ typedef endian< endianness::big, uint64_t, 64, alignment::aligned > aligned_ubig64_t;
+
+ // aligned little endian signed integer types
+ typedef endian< endianness::little, int16_t, 16, alignment::aligned > aligned_little2_t;
+ typedef endian< endianness::little, int32_t, 32, alignment::aligned > aligned_little4_t;
+ typedef endian< endianness::little, int64_t, 64, alignment::aligned > aligned_little8_t;
+
+ // aligned little endian unsigned integer types
+ typedef endian< endianness::little, uint16_t, 16, alignment::aligned > aligned_ulittle2_t;
+ typedef endian< endianness::little, uint32_t, 32, alignment::aligned > aligned_ulittle4_t;
+ typedef endian< endianness::little, uint64_t, 64, alignment::aligned > aligned_ulittle8_t;
+
+
+ // aligned native endian typedefs are not provided because
+ // <cstdint> types are superior for this use case
+
+ } // namespace integer
+ } // namespace boost
+
+
+
+[/==========================================================================================]
+[section:endian Template class `endian<>`]
+[/==========================================================================================]
+
+An endian integer is an integer byte-holder with user-specified endianness, value type, size, and alignment. The usual operations on integers are supplied.
+
+ template <
+ typename E,
+ typename T,
+ std::size_t n_bits=8*sizeof(T),
+ alignment A = alignment::aligned>
+ class endian : integer_cover_operators< endian<E, T, n_bits, A>, T > {
+ public:
+ typedef E endian_type;
+ typedef T value_type;
+ static const std::size_t width = n_bits;
+ static const alignment alignment_value = A;
+
+ endian() = default; // = default replaced by {} on C++03
+ explicit endian(T v);
+ endian & operator=(T v);
+ operator T() const;
+ const char* data() const;
+ };
+
+* [*Requires:]
+
+ * `E` is one of `endianness::big` or `endianness::little`.
+ * `T` must be a POD with value semantics.
+ * `nbits` is a multiple of `8`
+ * If `A` is `alignment::aligned` then `nbits` must be equal to `8*sizeof(T)`
+
+[note if BOOST_ENDIAN_FORCE_PODNESS is defined && C++0x POD's are not
+available then these two constructors will not be present]
+
+
+[/==========================================================================================]
+[section:endian Default Contructor `endian()`]
+[/==========================================================================================]
+
+ endian() = default; // C++03: endian(){}
+
+* [*Effects:] Constructs an object of type `endian<E, T, n_bits, A>`.
+
+[endsect]
+
+[/==========================================================================================]
+[section:endianT Contructor from value_type `endian(T)`]
+[/==========================================================================================]
+
+ explicit endian(T v);
+
+* [*Effects:] Constructs an object of type `endian<E, T, n_bits, A>`.
+* [*Postcondition:] `x == v`, where `x` is the constructed object.
+
+[endsect]
+
+[/==========================================================================================]
+[section:assignment Assignment Operator from value_type `operator=(T)`]
+[/==========================================================================================]
+
+ endian & operator=(T v);
+
+* [*Postcondition:] `value_type(*this) == v`.
+* [*Returns:] `*this`.
+
+[endsect]
+
+[/==========================================================================================]
+[section:conversion Conversion Operator `operator T()`]
+[/==========================================================================================]
+
+ operator T() const;
+
+* [*Returns:] The current value stored in `*this`, converted to `value_type`.
+
+[endsect]
+
+[/==========================================================================================]
+[section:data Member Function `data()`]
+[/==========================================================================================]
+
+ const char* data() const;
+
+* [*Returns:] The current value stored in `*this`, converted to `value_type`.
+
+[endsect]
+
+[/==========================================================================================]
+[section:other Other operators ]
+[/==========================================================================================]
+
+Other operators on endian objects are forwarded to the equivalent operator on `value_type`.
+
+[endsect]
+
+[endsect]
+
+[/==========================================================================================]
+[section:typedefs Common typedefs]
+[/==========================================================================================]
+
+[endsect]
+
+[endsect]
+
+[/==========================================================================================]
+[section:integer_endian_binary_stream_hpp Header `<boost/integer/endian_binary_stream.hpp>`]
+[/==========================================================================================]
+
+Header <boost/integer/endian_binary_stream.hpp> provides operators `<=` and `=>` for unformatted binary (as opposed to formatted character) stream insertion and extraction of endian types.
+
+[heading Synopsis]
+
+ namespace boost
+ {
+ namespace integer
+ {
+ template< class T >
+ struct is_endian { static const bool value = false; };
+ template< typename E, typename T, std::size_t n_bits, alignment A >
+ struct is_endian<endian_pack<E,T,n_bits,A> { static const bool value = true; };
+ template< typename E, typename T, std::size_t n_bits, alignment A >
+ struct is_endian<endian<E,T,n_bits,A> { static const bool value = true; };
+
+ template < class Endian >
+ typename boost::enable_if< is_endian<Endian>, std::ostream & >::type
+ operator<=( std::ostream & os, const Endian & e );
+
+ template < class Endian >
+ typename boost::enable_if< is_endian<Endian>, std::istream & >::type
+ operator>=( std::istream & is, Endian & e );
+ }
+ }
+
+[endsect]
+
+[/==========================================================================================]
+[section:integer_endian_type_hpp Header `<boost/integer/endian_type.hpp>`]
+[/==========================================================================================]
+
+[heading Synopsis]
+
+ namespace boost {
+ namespace integer {
+ template <typename T>
+ struct endian_type;
+ }
+ }
+
+[/==========================================================================================]
+[section:integer_endian_type Meta Function `endian_type<>`]
+[/==========================================================================================]
+
+ template <typename Domain, typename T>
+ struct endian_type {
+ typedef type;
+ }
+
+The member typedef `type` names one of the `endianness` types `big`, `little` or `mixed`. If all the leaves of the type T are of the same endianness type is this endiannes, otherwise it is `mixed`.
+
+The default behavior works for all the endian aware types, fundamental types and any type that is a fusion sequence.
+
+The user can specialize this metafunction for specific clases.
+
+[heading Example]
+
+ is_same<endian_type<endian<endianness::big, int> >::type, endianness::big>::value == true
+ is_same<endian_type<int>::type, endianness::native>::value == true
+
+
+
+[endsect]
+
+[endsect]
+[/==========================================================================================]
+[section:integer_endian_view_hpp Header `<boost/integer/endian_view.hpp>`]
+[/==========================================================================================]
+
+This file provides the `endian_view<>` class template as well as some factory helper functions.
+
+[heading Synopsis]
+
+ namespace boost {
+ namespace integer {
+
+ template <typename Endian>
+ class endian_view;
+
+ template <typename E, typename T>
+ endian_view<endian_pack<E,T> > as_endian(T& v);
+ template <typename T>
+ endian_view<endian_pack<endianness::native, T> > as(T& v);
+ template <typename T>
+ endian_view<endian_pack<endianness::little,T> > as_little(T& v);
+ template <typename T>
+ endian_view<endian_pack<endianness::big,T> > as_big(T& v);
+
+
+ } // namespace integer
+ } // namespace boost
+
+[/==========================================================================================]
+[section:endian_view Template class `endian_view<>`]
+[/==========================================================================================]
+
+ template <typename Endian, typename T>
+ class endian_view {
+ public:
+ typedef T value_type;
+ endian_view()=delete;
+ endian_view(value_type& ref);
+ operator value_type() const;
+ endian_view& operator=(value_type val);
+ endian_view& operator=(endian_view const& rhs);
+ template <typename Endian2 >
+ endian_view& operator=(endian_view<Endian2,T> const& rhs) {
+ };
+
+[/==========================================================================================]
+[section:endian_view Constructor `endian_view`]
+[/==========================================================================================]
+
+ endian_view(value_type& ref);
+
+* [*Effects:] Constructs an object of type `endian_view<E, T, n_bits, A>`.
+
+[endsect]
+
+[/==========================================================================================]
+[section:operator_value_type Conversion `operator value_type()`]
+[/==========================================================================================]
+
+ operator value_type() const;
+
+* [*Returns:] The converted `value_type` of the referenced type as it was seen as an endian aware type.
+
+[endsect]
+
+[/==========================================================================================]
+[section:assignement Assignement `operator =(endian_view const& )`]
+[/==========================================================================================]
+
+ endian_view& operator=(endian_view const& rhs);
+
+* [*Postcondition:] `this->ref_ == rhs.ref_`.
+* [*Returns:] `*this`.
+
+[endsect]
+
+[/==========================================================================================]
+[section:assignement2 Assignement from different endianness`operator =(endian_view<Endian2,T> const& )`]
+[/==========================================================================================]
+
+ template <typename Endian2 >
+ endian_view& operator=(endian_view<Endian2,T> const& rhs) {
+
+* [*Postcondition:] `value_type(this->ref_) == value_type(rhs.ref_)`.
+* [*Returns:] `*this`.
+
+[endsect]
+
+
+[/==========================================================================================]
+[section:assignement_value_type Assignement from value_type `operator =(value_type)`]
+[/==========================================================================================]
+
+ endian_view& operator=(value_type val);
+
+* [*Postcondition:] `value_type(this->ref_) == v`.
+* [*Returns:] `*this`.
+
+[endsect]
+
+
+
+[endsect]
+
+[/==========================================================================================]
+[section:as_endian Non-Member Function Template `as_endian<>`]
+[/==========================================================================================]
+
+ template <typename E, typename T>
+ endian_view<endian<E,T> > as_endian(T& v);
+
+[endsect]
+
+[/==========================================================================================]
+[section:as Non-Member Function Template `as<>`]
+[/==========================================================================================]
+
+ template <typename T>
+ endian_view<endian<endian::native, T> > as(T& v);
+
+[endsect]
+
+[/==========================================================================================]
+[section:as_little Non-Member Function Template `as_little<>`]
+[/==========================================================================================]
+
+ template <typename T>
+ endian_view<endian<endian::little, T> > as_little(T& v);
+
+[endsect]
+
+[/==========================================================================================]
+[section:as_big Non-Member Function Template `as_big<>`]
+[/==========================================================================================]
+
+ template <typename T>
+ endian_view<endian<endian::big, T> > as_big(T& v);
+
+[endsect]
+
+
+[endsect]
+
+[/==========================================================================================]
+[section:integer_endian_conversion_hpp Header `<boost/integer/endian_conversion.hpp>`]
+[/==========================================================================================]
+
+[heading Synopsis]
+
+ namespace boost {
+ namespace integer {
+
+ template <typename TargetDomain, typename SourceDomain, typename T>
+ void convert_to_from(T& r);
+
+ template <typename SourceDomain, typename T>
+ void convert_from(T& r);
+
+ template <typename TargetDomain, typename T>
+ void convert_to(T& r);
+
+ template <typename Endian> struct to;
+ template <typename Endian> struct from;
+ template <typename Endian> struct is_to;
+ template <typename Endian> struct is_from;
+
+ template <typename Endian1, typename Endian2, typename T>
+ void convert(T& r);
+
+
+ } // namespace integer
+ } // namespace boost
+
+
+
+[/==========================================================================================]
+[section:convert_to_from Non-Member Function Template `convert_to_from<>`]
+[/==========================================================================================]
+
+ template <typename TargetDomain, typename SourceDomain, typename T>
+ void convert_to_from(T& r);
+
+[endsect]
+
+[/==========================================================================================]
+[section:convert_from Non-Member Function Template `convert_from<>`]
+[/==========================================================================================]
+
+ template <typename SourceDomain, typename T>
+ void convert_from(T& r);
+
+[endsect]
+
+[/==========================================================================================]
+[section:convert_to Non-Member Function Template `convert_to<>`]
+[/==========================================================================================]
+
+ template <typename TargetDomain, typename T>
+ void convert_to(T& r);
+
+[endsect]
+
+[/==========================================================================================]
+[section:to Class Template `to<>`]
+[/==========================================================================================]
+
+
+ template <typename Endian>
+ struct to {
+ typedef Endian type;
+ };
+
+[endsect]
+
+[/==========================================================================================]
+[section:from Class Template `from<>`]
+[/==========================================================================================]
+
+ template <typename Endian>
+ struct from {
+ typedef Endian type;
+ };
+
+[endsect]
+
+[/==========================================================================================]
+[section:is_to Class Template `is_to<>`]
+[/==========================================================================================]
+
+ template <typename Endian>
+ struct is_to : mpl::false_ {};
+ template <typename Endian>
+ struct is_to< to<Endian> > : mpl::true_ {};
+
+[endsect]
+
+[/==========================================================================================]
+[section:is_from Class Template `is_from<>`]
+[/==========================================================================================]
+
+ template <typename Endian>
+ struct is_from : mpl::false_ {};
+ template <typename Endian>
+ struct is_from< from<Endian> > : mpl::true_ {};
+
+[endsect]
+
+[/==========================================================================================]
+[section:convert Non-Member Function Template `convert<>`]
+[/==========================================================================================]
+
+ template <typename Endian1, typename Endian2, typename T>
+ void convert(T& r);
+
+[endsect]
+
+[endsect]
+
+[endsect]
+[section Examples]
+
+[section: Endian Aware]
+
+The endian_example.cpp program writes a binary file containing four byte big-endian and little-endian integers.
+
+This is an extract from a very widely used GIS file format. I have no idea
+why a designer would mix big and little endians in the same file - but
+this is a real-world format and users wishing to write low level code
+manipulating these files have to deal with the mixed endianness.
+
+Low-level I/O such as POSIX read/write or <cstdio> fread/fwrite is sometimes
+used for binary file operations when ultimate efficiency is important.
+Such I/O is often performed in some C++ wrapper class, but to drive home the
+point that endian integers are often used in fairly low-level code that
+does bulk I/O operations, <cstdio> fopen/fwrite is used for I/O in this example.
+
+
+ #include <iostream>
+ #include <cassert>
+ #include <cstdio>
+ #include <boost/integer/endian.hpp>
+
+ using namespace boost::integer;
+
+ namespace
+ {
+
+ struct header
+ {
+ big32_t file_code;
+ big32_t file_length;
+ little32_t version;
+ little32_t shape_type;
+ };
+
+ const char * filename = "test.dat";
+ }
+
+ int main()
+ {
+ assert( sizeof( header ) == 16 ); // requirement for interoperability
+
+ header h;
+
+ h.file_code = 0x04030201;
+ h.file_length = sizeof( header );
+ h.version = -1;
+ h.shape_type = 0x04030201;
+
+ std::FILE * fi;
+
+ if ( !(fi = std::fopen( filename, "wb" )) ) // MUST BE BINARY
+ {
+ std::cout << "could not open " << filename << '\n';
+ return 1;
+ }
+
+ if ( std::fwrite( &h, sizeof( header ), 1, fi ) != 1 )
+ {
+ std::cout << "write failure for " << filename << '\n';
+ return 1;
+ }
+
+ std::fclose( fi );
+
+ std::cout << "created file " << filename << '\n';
+ return 0;
+ }
+
+After compiling and executing endian_example.cpp, a hex dump of test.dat shows:
+
+ 0403 0201 0000 0010 ffff ffff 0102 0304
+
+
+
+[endsect]
+
+[/=============================]
+[section:receiver_makes_right "receiver makes right"]
+[/=============================]
+
+[endsect]
+[endsect]
+
+
+[/=================]
+[section Appendices]
+[/=================]
+[section:history Appendix A: History]
+[section [*Version 0.1.0, June 15, 2010] ['Split of Boost.Integer.Endian + Added Endian views]]
+
+[*Features:]
+
+* Endian packs
+ * Big endian | little endian | native endian byte ordering.
+ * Signed | unsigned
+ * Unaligned | aligned
+ * 1-8 byte (unaligned) | 2, 4, 8 byte (aligned)
+ * Choice of integer value type
+
+* Endian integers with the whole set of arithmetics operators based on endian pack.
+
+* Operators <= and => for unformatted binary (as opposed to formatted character) stream insertion and extraction of built-in, std::string types and of endian types.
+
+* Views of aligned endian unaware integer types as endian packs or endian integers so we can make endian conversion.
+
+* Generic in place conversion between different endian formats.
+ * Very simple interface: convert_to/from<endiannes domain>(),
+ * Support for built-in and user-defined data types view as fusion sequences.
+
+[endsect]
+[endsect]
+
+[section:rationale Appendix B: Rationale]
+
+[heading Design considerations for Boost.Integer.Endian]
+
+* Must be suitable for I/O - in other words, must be memcpyable.
+* Must provide exactly the size and internal byte ordering specified.
+* Must work correctly when the internal integer representation has more bits that the sum of the bits in the external byte representation. Sign extension must work correctly when the internal integer representation type has more bits than the sum of the bits in the external bytes. For example, using a 64-bit integer internally to represent 40-bit (5 byte) numbers must work for both positive and negative values.
+* Must work correctly (including using the same defined external representation) regardless of whether a compiler treats char as signed or unsigned.
+* Unaligned types must not cause compilers to insert padding bytes.
+* The implementation should supply optimizations only in very limited circumstances. Experience has shown that optimizations of endian integers often become pessimizations. While this may be obvious when changing machines or compilers, it also happens when changing compiler switches, compiler versions, or CPU models of the same architecture.
+* It is better software engineering if the same implementation works regardless of the CPU endianness. In other words, #ifdefs should be avoided where possible.
+
+[heading Experience]
+
+Classes with similar functionality have been independently developed by several Boost programmers and used very successful in high-value, high-use applications for many years. These independently developed endian libraries often evolved from C libraries that were also widely used. Endian integers have proven widely useful across a wide range of computer architectures and applications.
+
+[heading Motivating use cases]
+
+Neil Mayhew writes: "I can also provide a meaningful use-case for this library: reading TrueType font files from disk and processing the contents. The data format has fixed endianness (big) and has unaligned values in various places. Using Boost.Integer.Endian simplifies and cleans the code wonderfully."
+
+[heading C++0x]
+
+The availability of the C++0x Defaulted Functions feature is detected automatically, and will be used if present to ensure that objects of class endian are trivial, and thus POD's.
+
+[endsect]
+
+
+[section:implementation Appendix C: Implementation Notes]
+
+[heading FAQ]
+
+* *Why bother with endian types?* External data portability and both speed and space efficiency. Availability of additional binary integer sizes and alignments is important in some applications.
+
+* *Why not just use Boost.Serialization?* Serialization involves a conversion for every object involved in I/O. Endian objects require no conversion or copying. They are already in the desired format for binary I/O. Thus they can be read or written in bulk.
+
+* *Why bother with binary I/O? Why not just use C++ Standard Library stream inserters and extractors?* Using binary rather than character representations can be more space efficient, with a side benefit of faster I/O. CPU time is minimized because conversions to and from string are eliminated. Furthermore, binary integers are fixed size, and so fixed-size disk records are possible, easing sorting and allowing direct access. Disadvantages, such as the inability to use text utilities on the resulting files, limit usefulness to applications where the binary I/O advantages are paramount.
+
+* *Do these types have any uses outside of I/O?* Probably not, except for native endianness which can be used for fine grained control over size and alignment.
+
+* *Is there a performance hit when doing arithmetic using integer endian types?* Yes, for sure, compared to arithmetic operations on native integer types. However, these types are usually be faster, and sometimes much faster, for I/O compared to stream inserters and extractors, or to serialization.
+
+* *Are endian types POD's?* Yes for C++0x. No for C++03, although several macros are available to force PODness in all cases.
+
+* *What are the implications endian types not being POD's with C++03 compilers?* They can't be used in unions. Also, compilers aren't required to align or lay out storage in portable ways, although this potential problem hasn't prevented use of Boost.Integer.Endian with real compilers.
+
+* *Which is better, big-endian or little-endian?* Big-endian tends to be a bit more of an industry standard, but little-endian may be preferred for applications that run primarily on x86 (Intel/AMD) and other little-endian CPU's. The [@http://en.wikipedia.org/wiki/Endian Wikipedia] article gives more pros and cons.
+
+* *What good is native endianness?* It provides alignment and size guarantees not available from the built-in types. It eases generic programming.
+
+* *Why bother with the aligned endian types?* Aligned integer operations may be faster (20 times, in one measurement) if the endianness and alignment of the type matches the endianness and alignment requirements of the machine. On common CPU architectures, that optimization is only available for aligned types. That allows I/O of maximally efficient types on an application's primary platform, yet produces data files are portable to all platforms. The code, however, is likely to be more fragile and less portable than with the unaligned types.
+
+* *Endian types are really just byte-holders. Why provide the arithmetic operations at all?* Providing a full set of operations reduces program clutter and makes code both easier to write and to read. Consider incrementing a variable in a record. It is very convenient to write:
+
+ ++record.foo;
+
+Rather than:
+
+ int temp( record.foo);
+ ++temp;
+ record.foo = temp;
+
+* *Why do binary stream insertion and extraction use operators <= and >= rather than <<= and >>=?* <<= and >>= associate right-to-left, which is the opposite of << and >>, so would be very confusing and error prone. <= and >= associate left-to-right.
+
+[endsect]
+
+[section:acknowledgements Appendix D: Acknowledgements]
+
+Original design developed by Darin Adler based on classes developed by Mark Borgerding. Four original class templates combined into a single endian class template by Beman Dawes, who put the library together, provided documentation, and added the typedefs. He also added the unrolled_byte_loops sign partial specialization to correctly extend the sign when cover integer size differs from endian representation size.
+
+Comments and suggestions were received from Benaka Moorthi, Christopher Kohlhoff, Cliff Green, Gennaro Proto, Giovanni Piero Deretta, dizzy, Jeff Flinn, John Maddock, Kim Barrett, Marsh Ray, Martin Bonner, Matias Capeletto, Neil Mayhew, Phil Endecott, Rene Rivera, Roland Schwarz, Scott McMurray, Sebastian Redl, Tomas Puverle and Yuval Ronen.
+
+
+[endsect]
+
+[section Appendix E: Tests]
+
+[section binary_stream_test]
+
+[table
+ [[Name] [kind] [Description] [Result] [Ticket]]
+ [[check_op] [run] [checl binary streams operations on builtin types] [Pass] [#]]
+]
+
+[endsect]
+
+
+[section integer_endian_pack_test]
+
+[table
+ [[Name] [kind] [Description] [Result] [Ticket]]
+ [[detect_endianness] [run] [detect endianness] [Pass] [#]]
+ [[check_size] [run] [check size for different endian types] [Pass] [#]]
+ [[check_alignment] [run] [check alignement for different endian types] [Pass] [#]]
+ [[check_representation_and_range_and_ops] [run] [check representation and range and operations] [Pass] [#]]
+]
+
+[endsect]
+
+[section integer_endian_test]
+
+[table
+ [[Name] [kind] [Description] [Result] [Ticket]]
+ [[detect_endianness] [run] [detect endianness] [Pass] [#]]
+ [[check_size] [run] [check size for different endian types] [Pass] [#]]
+ [[check_alignment] [run] [check alignement for different endian types] [Pass] [#]]
+ [[check_representation_and_range_and_ops] [run] [check representation and range and operations] [Pass] [#]]
+ [[check_data] [run] [check data starts at the same address] [Pass] [#]]
+]
+
+[endsect]
+
+[section integer_endian_arithmetic_operation_test]
+
+[table
+ [[Name] [kind] [Description] [Result] [Ticket]]
+ [[check_op] [run] [check arithmethic operations on integer endian types] [Pass] [#]]
+]
+
+[endsect]
+
+[section integer_endian_view_test]
+
+[table
+ [[Name] [kind] [Description] [Result] [Ticket]]
+ [[check_read] [run] [check read access] [Pass] [#]]
+ [[check_write] [run] [check write access] [Pass] [#]]
+]
+
+[endsect]
+
+
+[section integer_endian_convert_test]
+
+[table
+ [[Name] [kind] [Description] [Result] [Ticket]]
+ [[check_in_place_conversion] [run] [check in place conversion] [Pass] [#]]
+]
+
+[endsect]
+
+
+[endsect]
+
+[section Appendix F: Tickets]
+
+[endsect]
+
+
+[/=====================================]
+[section:todo Appendix G: Future plans]
+[/=====================================]
+
+[heading Tasks to do before review]
+
+* Support for 'pure' endian conversion for endian unaware UDT.
+
+* Support for 'in place' endian conversion for ranges of endian unaware types.
+
+* endian iterator, which will iterate across a range endian converting values as necessary. It works with any type supporting the convert_to/from functions.
+
+[heading For later releases]
+
+* The library doesn't take advantage of special instructions on architectures which natively support endian conversion. This functionality could, however, be part of future releases.
+
+[endsect]
+
+
+
+[endsect]
Added: sandbox/endian_ext/libs/integer/endian/example/endian_example.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/example/endian_example.cpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,74 @@
+// endian_example.cpp -------------------------------------------------------//
+
+// Copyright Beman Dawes, 2006
+
+// 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/integer/endian
+
+//----------------------------------------------------------------------------//
+
+#define _CRT_SECURE_NO_DEPRECATE // quiet VC++ 8.0 foolishness
+
+#include <iostream>
+#include <cassert>
+#include <cstdio>
+#include <boost/integer/endian/endian.hpp>
+
+using namespace boost::integer;
+
+namespace
+{
+ // This is an extract from a very widely used GIS file format. I have no idea
+ // why a designer would mix big and little endians in the same file - but
+ // this is a real-world format and users wishing to write low level code
+ // manipulating these files have to deal with the mixed endianness.
+
+ struct header
+ {
+ big32_t file_code;
+ big32_t file_length;
+ little32_t version;
+ little32_t shape_type;
+ };
+
+ const char * filename = "test.dat";
+}
+
+int main()
+{
+ assert( sizeof( header ) == 16 ); // requirement for interoperability
+
+ header h;
+
+ h.file_code = 0x04030201;
+ h.file_length = sizeof( header );
+ h.version = -1;
+ h.shape_type = 0x04030201;
+
+ // Low-level I/O such as POSIX read/write or <cstdio> fread/fwrite is sometimes
+ // used for binary file operations when ultimate efficiency is important.
+ // Such I/O is often performed in some C++ wrapper class, but to drive home the
+ // point that endian integers are often used in fairly low-level code that
+ // does bulk I/O operations, <cstdio> fopen/fwrite is used for I/O in this example.
+
+ std::FILE * fi;
+
+ if ( !(fi = std::fopen( filename, "wb" )) ) // MUST BE BINARY
+ {
+ std::cout << "could not open " << filename << '\n';
+ return 1;
+ }
+
+ if ( std::fwrite( &h, sizeof( header ), 1, fi ) != 1 )
+ {
+ std::cout << "write failure for " << filename << '\n';
+ return 1;
+ }
+
+ std::fclose( fi );
+
+ std::cout << "created file " << filename << '\n';
+ return 0;
+}
Added: sandbox/endian_ext/libs/integer/endian/example/endian_hello_world.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/example/endian_hello_world.cpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,31 @@
+// endian_io_test.cpp ----------------------------------------------------------------//
+
+// Copyright Beman Dawes, 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/integer/endian
+
+#include <boost/integer/endian/endian.hpp>
+#include <boost/integer/endian/endian_binary_stream.hpp>
+#include <boost/binary_stream.hpp>
+#include <iostream>
+
+using namespace boost;
+using namespace boost::integer;
+
+int main()
+{
+ int_least32_t v = 0x31323334L; // = ASCII { '1', '2', '3', '4' }
+ // value chosen to work on text stream
+ big32_pt b(v);
+ little32_pt l(v);
+
+ std::cout << "Hello, endian world!\n\n";
+
+ std::cout << v << ' ' << b << ' ' << l << '\n';
+ std::cout <= v <= ' ' <= b <= ' ' <= l <= '\n';
+ return 0;
+}
+
Added: sandbox/endian_ext/libs/integer/endian/example/endian_hello_world_1.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/example/endian_hello_world_1.cpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,31 @@
+// endian_hello_world_1.cpp ----------------------------------------------------------------//
+
+// Copyright Beman Dawes, 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/integer/endian
+
+#include <boost/integer/endian/endian_pack.hpp>
+#include <boost/integer/endian/endian_binary_stream.hpp>
+#include <boost/binary_stream.hpp>
+#include <iostream>
+
+using namespace boost;
+using namespace boost::integer;
+
+int main()
+{
+ int_least32_t v = 0x31323334L; // = ASCII { '1', '2', '3', '4' }
+ // value chosen to work on text stream
+ endian_pack<big_endian, int_least32_t> b(v);
+ endian_pack<little_endian, int_least32_t> l(v);
+
+ std::cout << "Hello, endian world!\n\n";
+
+ std::cout << v << ' ' << b << ' ' << l << '\n';
+ std::cout <= v <= '*' <= b <= '*' <= l <= '\n';
+ return 0;
+}
+
Added: sandbox/endian_ext/libs/integer/endian/example/endian_hello_world_2.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/example/endian_hello_world_2.cpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,32 @@
+// endian_hello_world_2.cpp ----------------------------------------------------------------//
+
+// Copyright Beman Dawes, 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/integer/endian
+
+#include <boost/integer/endian/endian_pack.hpp>
+#include <boost/integer/endian/endian.hpp>
+#include <boost/integer/endian/endian_binary_stream.hpp>
+#include <boost/binary_stream.hpp>
+#include <iostream>
+
+using namespace boost;
+using namespace boost::integer;
+
+int main()
+{
+ int_least32_t v = 0x313233L; // = ASCII { '1', '2', '3'}
+ // value chosen to work on text stream
+ endian_pack<big_endian, int_least32_t, 24, alignment::unaligned> b(v);
+ endian_pack<little_endian, int_least32_t, 24, alignment::unaligned> l(v);
+
+ std::cout << "Hello, endian world!\n\n";
+
+ std::cout << v << ' ' << b << ' ' << l << '\n';
+ std::cout <= b <= ' ' <= l <= '\n';
+ return 0;
+}
+
Added: sandbox/endian_ext/libs/integer/endian/example/endian_quantity.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/example/endian_quantity.cpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,44 @@
+// endian_hello_world_2.cpp ----------------------------------------------------------------//
+
+// Copyright Beman Dawes, 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/integer/endian
+
+#include <boost/integer/endian/endian_pack.hpp>
+#include <boost/integer/endian/endian_binary_stream.hpp>
+#include <boost/binary_stream.hpp>
+#include <iostream>
+#include <boost/units/io.hpp>
+#include <boost/units/quantity.hpp>
+#include <boost/units/systems/si/length.hpp>
+#include <boost/units/systems/si/plane_angle.hpp>
+
+using namespace boost;
+using namespace boost::integer;
+using namespace boost::integer::endianness;
+using namespace boost::units;
+
+int main()
+{
+ quantity<si::length, boost::int_least32_t> q = 825373492 * si::meter;
+ endian_pack<big, quantity<si::length, boost::int_least32_t> > b;
+ endian_pack<little, quantity<si::length, boost::int_least32_t> > l;
+ b=q;
+ l=q;
+
+ //~ quantity<si::length, boost::int_least32_t> q2 = b;
+
+ std::cout << "Hello, endian quantity!\n\n";
+
+ //~ std::cout << q << '\n';
+ //~ std::cout << q2 << '\n';
+ std::cout << q << ' ' << b << ' ' << l << '\n';
+ std::cout <= b <= ' ' <= l <= '\n';
+ //~ std::cout <= q <= ' ' <= b <= ' ' <= l <= '\n';
+
+ return 0;
+}
+
Added: sandbox/endian_ext/libs/integer/endian/example/packet_example.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/example/packet_example.cpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,154 @@
+// packet_example.cpp -------------------------------------------------------//
+
+// (C) Copyright VicenteJ Botet Escriba 2010
+
+// 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/integer/endian
+
+//----------------------------------------------------------------------------//
+
+//~ #define _CRT_SECURE_NO_DEPRECATE // quiet VC++ 8.0 foolishness
+#define BOOST_NO_STATIC_ASSERT
+//~ #include <iostream>
+//~ #include <cassert>
+
+#include <boost/integer/endian/endian_pack.hpp>
+#include <boost/chrono/chrono.hpp>
+#include <boost/units/quantity.hpp>
+#include <boost/units/systems/si/length.hpp>
+#include <boost/units/systems/si/plane_angle.hpp>
+
+using namespace boost::integer;
+using namespace boost::chrono;
+using namespace boost::integer::endianness;
+using namespace boost::units;
+
+namespace bitfield {
+template <typename T, typename Tag, std::size_t Width>
+struct member {
+ static const std::size_t width=Width;
+};
+
+template <std::size_t Width>
+struct filler {
+ static const std::size_t width=Width;
+};
+
+template <typename T>
+struct width {
+ static const std::size_t value=T::width;
+};
+
+
+template<typename Storage,
+ typename T1,
+ typename T2=filler<0>,
+ typename T3=filler<0>,
+ typename T4=filler<0>,
+ typename T5=filler<0>
+>
+struct tuple {
+ char placeholder[
+ (
+ width<T1>::value +
+ width<T2>::value +
+ width<T3>::value +
+ width<T4>::value +
+ width<T5>::value +
+ 7
+ )/8];
+}; // bitfield
+
+}
+
+namespace internet {
+
+
+struct IpHeader {
+ struct version {};
+ struct header_length {};
+ struct precedence {};
+ struct low_delay {};
+ struct high_thruput {};
+ struct high_reliability {};
+ struct minimize_cost {};
+ struct dont_frag {};
+ struct more_frag {};
+ struct frag_offset {};
+
+ /////////////////////////////
+ bitfield::tuple<ubig8_pt,
+ bitfield::member<int, version, 4>,
+ bitfield::member<unsigned int, header_length, 4>
+ > version_headerLength;
+
+ bitfield::tuple<ubig8_pt,
+ bitfield::member<unsigned int, precedence, 3>,
+ bitfield::member<bool, low_delay, 1>,
+ bitfield::member<bool, high_thruput, 1>,
+ bitfield::member<bool, high_reliability, 1>,
+ bitfield::member<bool, minimize_cost, 1>
+ > differentiated_services;
+
+ ubig16_pt total_length;
+ /////////////////////////////
+ ubig16_pt identification;
+ bitfield::tuple<ubig16_pt,
+ bitfield::filler<1>,
+ bitfield::member<bool, dont_frag, 1>,
+ bitfield::member<bool, more_frag, 1>,
+ bitfield::member<int, frag_offset, 13>
+ > flags_frag;
+ /////////////////////////////
+ ubig8_pt time_to_live;
+ ubig8_pt protocol;
+ ubig16_pt header_checksum;
+ /////////////////////////////
+ ubig32_pt source_address;
+ /////////////////////////////
+ ubig32_pt destination_address;
+}; // IpHeader
+
+struct UdpHeader {
+ ubig16_pt source_port;
+ ubig16_pt destination_port;
+ ubig16_pt length;
+ ubig16_pt checksum;
+}; // UdpHeader
+
+
+} // internet
+
+
+struct UserMessage {
+ endian_pack<little, system_clock::time_point > timestamp;
+ ulittle32_pt aircraft_id;
+ struct Position {
+ endian_pack<little, quantity<si::length, boost::int_least32_t> > x;
+ endian_pack<little, quantity<si::length, boost::int_least32_t> > y;
+ endian_pack<little, quantity<si::length, boost::int_least32_t> > z;
+ } position;
+ struct Attitude {
+ endian_pack<little, quantity<si::plane_angle, boost::int_least8_t> > heading;
+ endian_pack<little, quantity<si::plane_angle, boost::int_least8_t> > pitch;
+ endian_pack<little, quantity<si::plane_angle, boost::int_least8_t> > roll;
+ } attitude;
+}; // UserMessage
+
+struct Packet {
+ internet::IpHeader ipHeader;
+ internet::UdpHeader udpHeader;
+ UserMessage userMessage;
+}; // Packet
+
+
+int main() {
+ Packet packet;
+ packet.ipHeader.source_address = 0x12345678;
+ packet.udpHeader.destination_port = 1234;
+ packet.userMessage.timestamp = system_clock::now();
+ packet.userMessage.position.y = 17 * si::meter;
+} // main
+
Added: sandbox/endian_ext/libs/integer/endian/test/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/test/Jamfile.v2 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,67 @@
+# Boost Endian Library test Jamfile
+
+# Copyright Beman Dawes 2006
+# Copyright Vicente J. Botet Escriba 2010-2011
+
+# 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/integer/doc/endian.html
+
+ import testing ;
+
+project
+ : requirements
+ <library>/boost/chrono//boost_chrono
+ <library>/boost/system//boost_system
+ <define>BOOST_RATIO_USES_MPL_ASSERT
+ <warnings>all
+ <toolset>gcc:<cxxflags>-Wextra
+ <toolset>gcc:<cxxflags>-Wno-long-long
+ <toolset>gcc:<cxxflags>-pedantic
+ <toolset>darwin:<cxxflags>-Wextra
+ <toolset>darwin:<cxxflags>-Wno-long-long
+ <toolset>darwin:<cxxflags>-pedantic
+ #<toolset>pathscale:<cxxflags>-Wextra
+ <toolset>pathscale:<cxxflags>-Wno-long-long
+ <toolset>pathscale:<cxxflags>-pedantic
+ <toolset>clang:<cxxflags>-Wextra
+ <toolset>clang:<cxxflags>-pedantic
+ <toolset>clang:<cxxflags>-Wno-long-long
+
+ <toolset>gcc-mingw-4.5.0:<cxxflags>-fdiagnostics-show-option
+ <toolset>gcc-mingw-4.6.0:<cxxflags>-fdiagnostics-show-option
+
+ #<toolset>gcc-3.4.4:<linkflags>-Wl,--enable-auto-import
+ #<toolset>gcc-4.3.4:<linkflags>-Wl,--enable-auto-import
+ #<toolset>gcc-mingw-4.4.0:<linkflags>--enable-auto-import
+ #<toolset>gcc-mingw-4.5.0:<linkflags>-Wl,--enable-auto-import
+ ;
+
+ test-suite "endian"
+ :
+ [ run binary_stream_test.cpp ]
+ [ run endian_binary_stream_test.cpp ]
+ [ run endian_pack_test.cpp ]
+ [ run endian_test.cpp ]
+ [ run endian_operations_test.cpp
+ : : : <toolset>gcc:<cxxflags>-Wno-sign-compare ]
+ #[ run endian_in_union_test.cpp ]
+ [ run scoped_enum_emulation_test.cpp ]
+ [ run endian_flip_test.cpp
+ : : : <toolset>gcc:<cxxflags>-Wno-sign-compare ]
+ [ run endian_view_test.cpp ]
+ [ run endian_type_test.cpp ]
+ [ run endian_convert_test.cpp ]
+ [ run endian_convert_unique_endian_test.cpp ]
+ ;
+
+ test-suite "examples"
+ :
+ [ run ../example/endian_example.cpp ]
+ [ run ../example/endian_hello_world.cpp ]
+ [ run ../example/endian_hello_world_1.cpp ]
+ [ run ../example/endian_hello_world_2.cpp ]
+ [ run ../example/endian_quantity.cpp ]
+ [ run ../example/packet_example.cpp ]
+ ;
Added: sandbox/endian_ext/libs/integer/endian/test/binary_stream_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/test/binary_stream_test.cpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,122 @@
+// binary_stream_test.cpp ------------------------------------------------------------//
+
+// Copyright Beman Dawes 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/integer/endian
+
+#include <boost/binary_stream.hpp>
+#include <string>
+#include <iostream>
+#include <sstream>
+
+using namespace boost;
+using namespace std;
+
+namespace
+{
+ int errors = 0;
+
+ void verify( bool x, const char * file, int line )
+ {
+ if ( x ) return;
+ ++errors;
+ cout << file << "(" << line << ") : error: predicate is false\n" << endl;
+ }
+
+}
+
+#define BOOST_VERIFY(predicate) verify( predicate, __FILE__, __LINE__ )
+
+
+int main()
+{
+ std::stringstream ss( std::ios_base::in | std::ios_base::out | std::ios_base::binary );
+
+ short short_1(0x0102), short_2;
+ ss <= short_1;
+ ss >= short_2;
+ BOOST_VERIFY( short_1 == short_2 );
+
+ unsigned short ushort_1(0x0102), ushort_2;
+ ss <= ushort_1;
+ ss >= ushort_2;
+ BOOST_VERIFY( ushort_1 == ushort_2 );
+
+ int int_1(0x01020304), int_2;
+ ss <= int_1;
+ ss >= int_2;
+ BOOST_VERIFY( int_1 == int_2 );
+
+ unsigned int uint_1(0x01020304), uint_2;
+ ss <= uint_1;
+ ss >= uint_2;
+ BOOST_VERIFY( uint_1 == uint_2 );
+
+ long long_1(0x01020304L), long_2;
+ ss <= long_1;
+ ss >= long_2;
+ BOOST_VERIFY( long_1 == long_2 );
+
+ unsigned long ulong_1(0x01020304UL), ulong_2;
+ ss <= ulong_1;
+ ss >= ulong_2;
+ BOOST_VERIFY( ulong_1 == ulong_2 );
+
+ long long long_long_1(0x0102030405060708LL), long_long_2;
+ ss <= long_long_1;
+ ss >= long_long_2;
+ BOOST_VERIFY( long_long_1 == long_long_2 );
+
+ unsigned long long ulong_long_1(0x0102030405060708ULL), ulong_long_2;
+ ss <= ulong_long_1;
+ ss >= ulong_long_2;
+ BOOST_VERIFY( ulong_long_1 == ulong_long_2 );
+
+ float float_1(1.2F), float_2;
+ ss <= float_1;
+ ss >= float_2;
+ BOOST_VERIFY( float_1 == float_2 );
+
+ double double_1(1.2), double_2;
+ ss <= double_1;
+ ss >= double_2;
+ BOOST_VERIFY( double_1 == double_2 );
+
+ long double long_double_1(1.2), long_double_2;
+ ss <= long_double_1;
+ ss >= long_double_2;
+ BOOST_VERIFY( long_double_1 == long_double_2 );
+
+ char char_1(0x01), char_2;
+ ss <= char_1;
+ ss >= char_2;
+ BOOST_VERIFY( char_1 == char_2 );
+
+ signed char schar_1(0x01), schar_2;
+ ss <= schar_1;
+ ss >= schar_2;
+ BOOST_VERIFY( schar_1 == schar_2 );
+
+ unsigned char uchar_1(0x01), uchar_2;
+ ss <= uchar_1;
+ ss >= uchar_2;
+ BOOST_VERIFY( uchar_1 == uchar_2 );
+
+ wchar_t wchar_t_1(L'1'), wchar_t_2;
+ ss <= wchar_t_1;
+ ss >= wchar_t_2;
+ BOOST_VERIFY( wchar_t_1 == wchar_t_2 );
+
+ string string_1("foobar"), string_2;
+ ss <= string_1.c_str();
+ ss >= string_2;
+ BOOST_VERIFY( string_1 == string_2 );
+ ss <= string_1;
+ ss >= string_2;
+ BOOST_VERIFY( string_1 == string_2 );
+
+ cout << errors << " error(s) detected\n";
+ return errors;
+}
Added: sandbox/endian_ext/libs/integer/endian/test/endian_binary_stream_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/test/endian_binary_stream_test.cpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,304 @@
+// endian_binary_stream_test.cpp -----------------------------------------------------//
+
+// Copyright Beman Dawes 2009
+// Copyright VicenteJ Botet Escriba 2010-2011
+
+// 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/integer/endian
+
+#include <boost/integer/endian/endian.hpp>
+#include <boost/integer/endian/endian_binary_stream.hpp>
+#include <boost/binary_stream.hpp>
+#include <iostream>
+#include <sstream>
+
+using namespace boost;
+using namespace boost::integer;
+using namespace std;
+
+namespace
+{
+ int errors = 0;
+
+ void verify( bool x, const char * file, int line )
+ {
+ if ( x ) return;
+ ++errors;
+ cout << file << "(" << line << ") : error: predicate is false\n" << endl;
+ }
+
+}
+
+#define BOOST_VERIFY(predicate) verify( predicate, __FILE__, __LINE__ )
+
+int main()
+{
+ std::stringstream ss( std::ios_base::in | std::ios_base::out | std::ios_base::binary );
+
+ // big tests
+
+ big8_t big8_t_1(0x01), big8_t_2;
+ ss <= big8_t_1;
+ ss >= big8_t_2;
+ BOOST_VERIFY( big8_t_1 == big8_t_2 );
+
+ big16_t big16_t_1(0x0102), big16_t_2;
+ ss <= big16_t_1;
+ ss >= big16_t_2;
+ BOOST_VERIFY( big16_t_1 == big16_t_2 );
+
+ big24_t big24_t_1(0x313233L), big24_t_2;
+ std::cout << '*' ;
+ std::cout <= big24_t_1;
+ std::cout << std::endl;
+ little24_t little24_t_133(big24_t_1);
+ little24_t little24_t_134;
+ //~ little24_t_134=big24_t_1;
+ std::cout << '*' ;
+ std::cout <= little24_t_133;
+ std::cout << std::endl;
+
+ ss <= big24_t_1;
+ ss >= big24_t_2;
+ BOOST_VERIFY( big24_t_1 == big24_t_2 );
+
+ big32_t big32_t_1(0x01020304L), big32_t_2;
+ ss <= big32_t_1;
+ ss >= big32_t_2;
+ BOOST_VERIFY( big32_t_1 == big32_t_2 );
+
+ big40_t big40_t_1(0x0102030405LL), big40_t_2;
+ ss <= big40_t_1;
+ ss >= big40_t_2;
+ BOOST_VERIFY( big40_t_1 == big40_t_2 );
+
+ big48_t big48_t_1(0x010203040506LL), big48_t_2;
+ ss <= big48_t_1;
+ ss >= big48_t_2;
+ BOOST_VERIFY( big48_t_1 == big48_t_2 );
+
+ big56_t big56_t_1(0x01020304050607LL), big56_t_2;
+ ss <= big56_t_1;
+ ss >= big56_t_2;
+ BOOST_VERIFY( big56_t_1 == big56_t_2 );
+
+ big64_t big64_t_1(0x0102030405060808LL), big64_t_2;
+ ss <= big64_t_1;
+ ss >= big64_t_2;
+ BOOST_VERIFY( big64_t_1 == big64_t_2 );
+
+ // ubig tests
+
+ ubig8_t ubig8_t_1(0x01), ubig8_t_2;
+ ss <= ubig8_t_1;
+ ss >= ubig8_t_2;
+ BOOST_VERIFY( ubig8_t_1 == ubig8_t_2 );
+
+ ubig16_t ubig16_t_1(0x0102), ubig16_t_2;
+ ss <= ubig16_t_1;
+ ss >= ubig16_t_2;
+ BOOST_VERIFY( ubig16_t_1 == ubig16_t_2 );
+
+ ubig24_t ubig24_t_1(0x010203L), ubig24_t_2;
+ ss <= ubig24_t_1;
+ ss >= ubig24_t_2;
+ BOOST_VERIFY( ubig24_t_1 == ubig24_t_2 );
+
+ ubig32_t ubig32_t_1(0x01020304L), ubig32_t_2;
+ ss <= ubig32_t_1;
+ ss >= ubig32_t_2;
+ BOOST_VERIFY( ubig32_t_1 == ubig32_t_2 );
+
+ ubig40_t ubig40_t_1(0x0102030405LL), ubig40_t_2;
+ ss <= ubig40_t_1;
+ ss >= ubig40_t_2;
+ BOOST_VERIFY( ubig40_t_1 == ubig40_t_2 );
+
+ ubig48_t ubig48_t_1(0x010203040506LL), ubig48_t_2;
+ ss <= ubig48_t_1;
+ ss >= ubig48_t_2;
+ BOOST_VERIFY( ubig48_t_1 == ubig48_t_2 );
+
+ ubig56_t ubig56_t_1(0x01020304050607LL), ubig56_t_2;
+ ss <= ubig56_t_1;
+ ss >= ubig56_t_2;
+ BOOST_VERIFY( ubig56_t_1 == ubig56_t_2 );
+
+ ubig64_t ubig64_t_1(0x0102030405060808LL), ubig64_t_2;
+ ss <= ubig64_t_1;
+ ss >= ubig64_t_2;
+ BOOST_VERIFY( ubig64_t_1 == ubig64_t_2 );
+
+ // little tests
+
+ little8_t little8_t_1(0x01), little8_t_2;
+ ss <= little8_t_1;
+ ss >= little8_t_2;
+ BOOST_VERIFY( little8_t_1 == little8_t_2 );
+
+ little16_t little16_t_1(0x0102), little16_t_2;
+ ss <= little16_t_1;
+ ss >= little16_t_2;
+ BOOST_VERIFY( little16_t_1 == little16_t_2 );
+
+ little24_t little24_t_1(0x010203L), little24_t_2;
+ ss <= little24_t_1;
+ ss >= little24_t_2;
+ BOOST_VERIFY( little24_t_1 == little24_t_2 );
+
+ little32_t little32_t_1(0x01020304L), little32_t_2;
+ ss <= little32_t_1;
+ ss >= little32_t_2;
+ BOOST_VERIFY( little32_t_1 == little32_t_2 );
+
+ little40_t little40_t_1(0x0102030405LL), little40_t_2;
+ ss <= little40_t_1;
+ ss >= little40_t_2;
+ BOOST_VERIFY( little40_t_1 == little40_t_2 );
+
+ little48_t little48_t_1(0x010203040506LL), little48_t_2;
+ ss <= little48_t_1;
+ ss >= little48_t_2;
+ BOOST_VERIFY( little48_t_1 == little48_t_2 );
+
+ little56_t little56_t_1(0x01020304050607LL), little56_t_2;
+ ss <= little56_t_1;
+ ss >= little56_t_2;
+ BOOST_VERIFY( little56_t_1 == little56_t_2 );
+
+ little64_t little64_t_1(0x0102030405060808LL), little64_t_2;
+ ss <= little64_t_1;
+ ss >= little64_t_2;
+ BOOST_VERIFY( little64_t_1 == little64_t_2 );
+
+ // ulittle tests
+
+ ulittle8_t ulittle8_t_1(0x01), ulittle8_t_2;
+ ss <= ulittle8_t_1;
+ ss >= ulittle8_t_2;
+ BOOST_VERIFY( ulittle8_t_1 == ulittle8_t_2 );
+
+ ulittle16_t ulittle16_t_1(0x0102), ulittle16_t_2;
+ ss <= ulittle16_t_1;
+ ss >= ulittle16_t_2;
+ BOOST_VERIFY( ulittle16_t_1 == ulittle16_t_2 );
+
+ ulittle24_t ulittle24_t_1(0x010203L), ulittle24_t_2;
+ ss <= ulittle24_t_1;
+ ss >= ulittle24_t_2;
+ BOOST_VERIFY( ulittle24_t_1 == ulittle24_t_2 );
+
+ ulittle32_t ulittle32_t_1(0x01020304L), ulittle32_t_2;
+ ss <= ulittle32_t_1;
+ ss >= ulittle32_t_2;
+ BOOST_VERIFY( ulittle32_t_1 == ulittle32_t_2 );
+
+ ulittle40_t ulittle40_t_1(0x0102030405LL), ulittle40_t_2;
+ ss <= ulittle40_t_1;
+ ss >= ulittle40_t_2;
+ BOOST_VERIFY( ulittle40_t_1 == ulittle40_t_2 );
+
+ ulittle48_t ulittle48_t_1(0x010203040506LL), ulittle48_t_2;
+ ss <= ulittle48_t_1;
+ ss >= ulittle48_t_2;
+ BOOST_VERIFY( ulittle48_t_1 == ulittle48_t_2 );
+
+ ulittle56_t ulittle56_t_1(0x01020304050607LL), ulittle56_t_2;
+ ss <= ulittle56_t_1;
+ ss >= ulittle56_t_2;
+ BOOST_VERIFY( ulittle56_t_1 == ulittle56_t_2 );
+
+ ulittle64_t ulittle64_t_1(0x0102030405060808LL), ulittle64_t_2;
+ ss <= ulittle64_t_1;
+ ss >= ulittle64_t_2;
+ BOOST_VERIFY( ulittle64_t_1 == ulittle64_t_2 );
+
+ // native tests
+
+ native8_t native8_t_1(0x01), native8_t_2;
+ ss <= native8_t_1;
+ ss >= native8_t_2;
+ BOOST_VERIFY( native8_t_1 == native8_t_2 );
+
+ native16_t native16_t_1(0x0102), native16_t_2;
+ ss <= native16_t_1;
+ ss >= native16_t_2;
+ BOOST_VERIFY( native16_t_1 == native16_t_2 );
+
+ native24_t native24_t_1(0x010203L), native24_t_2;
+ ss <= native24_t_1;
+ ss >= native24_t_2;
+ BOOST_VERIFY( native24_t_1 == native24_t_2 );
+
+ native32_t native32_t_1(0x01020304L), native32_t_2;
+ ss <= native32_t_1;
+ ss >= native32_t_2;
+ BOOST_VERIFY( native32_t_1 == native32_t_2 );
+
+ native40_t native40_t_1(0x0102030405LL), native40_t_2;
+ ss <= native40_t_1;
+ ss >= native40_t_2;
+ BOOST_VERIFY( native40_t_1 == native40_t_2 );
+
+ native48_t native48_t_1(0x010203040506LL), native48_t_2;
+ ss <= native48_t_1;
+ ss >= native48_t_2;
+ BOOST_VERIFY( native48_t_1 == native48_t_2 );
+
+ native56_t native56_t_1(0x01020304050607LL), native56_t_2;
+ ss <= native56_t_1;
+ ss >= native56_t_2;
+ BOOST_VERIFY( native56_t_1 == native56_t_2 );
+
+ native64_t native64_t_1(0x0102030405060808LL), native64_t_2;
+ ss <= native64_t_1;
+ ss >= native64_t_2;
+ BOOST_VERIFY( native64_t_1 == native64_t_2 );
+
+ // unative tests
+
+ unative8_t unative8_t_1(0x01), unative8_t_2;
+ ss <= unative8_t_1;
+ ss >= unative8_t_2;
+ BOOST_VERIFY( unative8_t_1 == unative8_t_2 );
+
+ unative16_t unative16_t_1(0x0102), unative16_t_2;
+ ss <= unative16_t_1;
+ ss >= unative16_t_2;
+ BOOST_VERIFY( unative16_t_1 == unative16_t_2 );
+
+ unative24_t unative24_t_1(0x010203L), unative24_t_2;
+ ss <= unative24_t_1;
+ ss >= unative24_t_2;
+ BOOST_VERIFY( unative24_t_1 == unative24_t_2 );
+
+ unative32_t unative32_t_1(0x01020304L), unative32_t_2;
+ ss <= unative32_t_1;
+ ss >= unative32_t_2;
+ BOOST_VERIFY( unative32_t_1 == unative32_t_2 );
+
+ unative40_t unative40_t_1(0x0102030405LL), unative40_t_2;
+ ss <= unative40_t_1;
+ ss >= unative40_t_2;
+ BOOST_VERIFY( unative40_t_1 == unative40_t_2 );
+
+ unative48_t unative48_t_1(0x010203040506LL), unative48_t_2;
+ ss <= unative48_t_1;
+ ss >= unative48_t_2;
+ BOOST_VERIFY( unative48_t_1 == unative48_t_2 );
+
+ unative56_t unative56_t_1(0x01020304050607LL), unative56_t_2;
+ ss <= unative56_t_1;
+ ss >= unative56_t_2;
+ BOOST_VERIFY( unative56_t_1 == unative56_t_2 );
+
+ unative64_t unative64_t_1(0x0102030405060808LL), unative64_t_2;
+ ss <= unative64_t_1;
+ ss >= unative64_t_2;
+ BOOST_VERIFY( unative64_t_1 == unative64_t_2 );
+
+ cout << errors << " error(s) detected\n";
+ return errors;
+ //~ return 1;
+}
Added: sandbox/endian_ext/libs/integer/endian/test/endian_convert_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/test/endian_convert_test.cpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,214 @@
+// endian_type_test.cpp ---------------------------------------------------------//
+
+// (C) Copyright VicenteJ Botet Escriba 2010-2011
+
+// 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/integer/endian
+
+//----------------------------------------------------------------------------//
+
+// This test probes for correct endianess, size, and value.
+
+// See endian_operations_test for tests of operator correctness and interaction
+// between operand types.
+
+//----------------------------------------------------------------------------//
+
+#include <boost/detail/lightweight_test.hpp> // for main
+
+#include <iostream>
+#include <boost/type_traits/remove_cv.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+#include <boost/integer/endian/endian_type.hpp>
+#include <boost/integer/endian/endian_conversion.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/list.hpp>
+#include <boost/fusion/adapted/struct/adapt_struct.hpp>
+#include <boost/mpl/push_front.hpp>
+#include <boost/mpl/front.hpp>
+
+#include <boost/static_assert.hpp>
+//~ #include <netinet/in.h>
+
+#define htons(nValue) \
+ ((((nValue)>> 8)) | ((nValue) << 8));
+
+#define htonl(nLongNumber) \
+ ((((nLongNumber)&0x000000FF)<<24)+(((nLongNumber)&0x0000FF00)<<8)+ \
+ (((nLongNumber)&0x00FF0000)>>8)+(((nLongNumber)&0xFF000000)>>24))
+
+using namespace std; // Not the best programming practice, but I
+using namespace boost; // want to verify this combination of using
+using namespace boost::integer; // namespaces works. See endian_operations_test
+// // for tests that don't do "using namespace".
+
+namespace X {
+
+struct big_c {
+ uint32_t a;
+ uint16_t b;
+};
+
+
+struct little_c {
+ int32_t a;
+ int16_t b;
+};
+
+struct mixed_c {
+ big_c a;
+ little_c b;
+};
+
+}
+
+struct network {};
+
+namespace boost {
+namespace integer {
+namespace endianness {
+
+ template <>
+ struct domain_map <network, X::big_c> {
+ typedef mpl::vector<big,big> type;
+ };
+ template <>
+ struct domain_map <network, X::little_c> {
+ typedef mpl::vector<little,little> type;
+ };
+
+}
+}
+}
+
+BOOST_FUSION_ADAPT_STRUCT(
+ X::big_c,
+ (uint32_t, a)
+ (uint16_t, b)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ X::little_c,
+ (int32_t, a)
+ (int16_t, b)
+)
+
+
+BOOST_FUSION_ADAPT_STRUCT(
+ X::mixed_c,
+ (X::big_c, a)
+ (X::little_c, b)
+)
+
+BOOST_MPL_ASSERT_MSG((boost::is_same<boost::integer::endianness::domain_map<network, X::big_c>::type,
+ boost::mpl::vector<boost::integer::endianness::big,boost::integer::endianness::big> >::value),
+ SS, (network,boost::integer::endianness::domain_map<network, X::big_c>::type));
+
+BOOST_MPL_ASSERT_MSG((boost::is_same<endianness::domain_map<network, X::little_c>::type,
+ mpl::vector<endianness::little,endianness::little> >::value),
+ RR, (network,endianness::domain_map<network, X::little_c>::type));
+
+typedef mpl::list<> floats;
+typedef mpl::push_front<floats,int>::type types;
+
+BOOST_MPL_ASSERT(( boost::is_same< boost::mpl::front<types>::type, int > ));
+
+BOOST_MPL_ASSERT_MSG((
+ boost::is_same<
+ mpl::front<
+ endianness::domain_map<network, X::mixed_c>::type
+ >::type,
+ endianness::domain_map<network, X::big_c>::type
+ >::value),
+ SS,
+ ( network,
+ mpl::front<
+ endianness::domain_map<network, X::mixed_c>::type
+ >::type,
+ endianness::domain_map<network,X::big_c>::type
+ ));
+
+
+BOOST_MPL_ASSERT_MSG((
+ boost::is_same<
+ mpl::front<
+ endianness::domain_map<network, X::big_c>::type
+ >::type,
+ endianness::big
+ >::value),
+ SS,
+ ( network,
+ mpl::front<
+ endianness::domain_map<network, X::big_c>::type
+ >::type,
+ endianness::domain_map<network,X::big_c>::type
+ ));
+
+typedef endianness::domain_map<network, X::mixed_c>::type endian_mixed_c;
+
+typedef mpl::begin<endian_mixed_c>::type begin_endian_mixed_c;
+typedef mpl::deref<begin_endian_mixed_c>::type deref_begin_endian_mixed_c;
+
+BOOST_MPL_ASSERT_MSG((
+ boost::is_same<
+ deref_begin_endian_mixed_c,
+ boost::integer::endianness::domain_map<network, X::big_c>::type
+ >::value),
+ SS,
+ ( deref_begin_endian_mixed_c,
+ boost::integer::endianness::domain_map<network, X::big_c>::type
+ ));
+
+
+namespace
+{
+ X::mixed_c m;
+ //~ Y::mixed_c m2;
+
+void check_endian_send()
+{
+
+
+ //~ std::cout << std::hex << m.a.a << std::endl;
+ //~ std::cout << std::hex << m.a.b << std::endl;
+ //~ std::cout << std::hex << m.b.a << std::endl;
+ //~ std::cout << std::hex << m.b.b << std::endl;
+
+ //~ integer::convert_from<network>(m.a);
+ //~ m.a.a=htonl(m.a.a);
+ //~ m.a.b=htons(m.a.b);
+ //~ integer::convert_from<network>(m.b);
+ convert<from<network>, to<native_endian> >(m);
+ //~ convert_from<network>(m);
+ //~ std::cout << std::hex << m.a.a << std::endl;
+ //~ std::cout << std::hex << m.a.b << std::endl;
+ //~ std::cout << std::hex << m.b.a << std::endl;
+ //~ std::cout << std::hex << m.b.b << std::endl;
+
+ //~ convert_to<network>(m);
+ //~ std::cout << std::hex << m.a.a << std::endl;
+ //~ std::cout << std::hex << m.a.b << std::endl;
+ //~ std::cout << std::hex << m.b.a << std::endl;
+ //~ std::cout << std::hex << m.b.b << std::endl;
+
+ //~ return m.a.a+m.a.b+ m.b.a+m.b.b;
+ //~ return 0;
+
+
+}
+} // unnamed namespace
+
+int main( )
+{
+ m.b.a=0x01020304;
+ m.b.b=0x0A0B;
+ m.a.a=0x04030201;
+ m.a.b=0x0B0A;
+
+ check_endian_send();
+ return boost::report_errors();
+ //~ return 1;
+} // main
Added: sandbox/endian_ext/libs/integer/endian/test/endian_convert_unique_endian_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/test/endian_convert_unique_endian_test.cpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,127 @@
+// endian_conversion_same_endian_test.cpp ---------------------------------------------------------//
+
+// (C) Copyright VicenteJ Botet Escriba 2010-2011
+
+// 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/integer/endian
+
+//----------------------------------------------------------------------------//
+
+
+#include <boost/detail/lightweight_test.hpp> // for main
+
+#include <iostream>
+#include <boost/type_traits/remove_cv.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+#include <boost/integer/endian/endian_type.hpp>
+#include <boost/integer/endian/endian_conversion.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/fusion/adapted/struct/adapt_struct.hpp>
+
+
+using namespace std; // Not the best programming practice, but I
+using namespace boost; // want to verify this combination of using
+using namespace boost::integer; // namespaces works. See endian_operations_test
+// // for tests that don't do "using namespace".
+
+namespace X {
+
+struct big_c {
+ uint32_t a;
+ uint16_t b;
+};
+
+
+struct little_c {
+ int32_t a;
+ int16_t b;
+};
+
+struct mixed_c {
+ big_c a;
+ little_c b;
+};
+
+}
+
+struct network {};
+
+namespace boost {
+namespace integer {
+namespace endianness {
+
+ template <>
+ struct domain_map <network, X::big_c> {
+ typedef mpl::vector<little,little> type;
+ };
+ template <>
+ struct domain_map <network, X::little_c> {
+ typedef mpl::vector<little,little> type;
+ };
+
+}
+}
+}
+
+BOOST_FUSION_ADAPT_STRUCT(
+ X::big_c,
+ (uint32_t, a)
+ (uint16_t, b)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ X::little_c,
+ (int32_t, a)
+ (int16_t, b)
+)
+
+
+BOOST_FUSION_ADAPT_STRUCT(
+ X::mixed_c,
+ (X::big_c, a)
+ (X::little_c, b)
+)
+
+
+namespace
+{
+void check_endian_send()
+{
+
+ X::mixed_c m;
+ m.a.a=0x01020304;
+ m.a.b=0x0A0B;
+ m.b.a=0x01020304;
+ m.b.b=0x0A0B;
+
+ //~ std::cout << std::hex << m.a.a << std::endl;
+ //~ std::cout << std::hex << m.a.b << std::endl;
+ //~ std::cout << std::hex << m.b.a << std::endl;
+ //~ std::cout << std::hex << m.b.b << std::endl;
+
+ integer::convert_from<network>(m);
+ //~ std::cout << std::hex << m.a.a << std::endl;
+ //~ std::cout << std::hex << m.a.b << std::endl;
+ //~ std::cout << std::hex << m.b.a << std::endl;
+ //~ std::cout << std::hex << m.b.b << std::endl;
+
+ integer::convert_to<network>(m);
+ //~ std::cout << std::hex << m.a.a << std::endl;
+ //~ std::cout << std::hex << m.a.b << std::endl;
+ //~ std::cout << std::hex << m.b.a << std::endl;
+ //~ std::cout << std::hex << m.b.b << std::endl;
+
+ //~ return m.a.a+m.a.b+ m.b.a+m.b.b;
+
+}
+} // unnamed namespace
+
+int main( )
+{
+ check_endian_send();
+ return boost::report_errors();
+} // main
+
Added: sandbox/endian_ext/libs/integer/endian/test/endian_flip_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/test/endian_flip_test.cpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,75 @@
+// endian_flip_test.cpp --------------------------------------------------------------//
+
+// Copyright Beman Dawes 2010
+// Copyright VicenteJ Botet Escriba 2010-2011
+
+// 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/integer/endian
+
+//--------------------------------------------------------------------------------------//
+
+#include <boost/integer/endian/endian_flip.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+namespace bi = boost::integer;
+
+int main()
+{
+ boost::int64_t i64 = 0x0102030405060708LL;
+ bi::endian_flip(i64);
+ BOOST_TEST_EQ(i64, 0x0807060504030201LL);
+ bi::endian_flip(i64);
+ BOOST_TEST_EQ(i64, 0x0102030405060708LL);
+
+ i64 = 0xfefdfcfbfaf9f8f7LL;
+ bi::endian_flip(i64);
+ BOOST_TEST_EQ(i64, 0xf7f8f9fafbfcfdfeLL);
+ bi::endian_flip(i64);
+ BOOST_TEST_EQ(i64, 0xfefdfcfbfaf9f8f7LL);
+
+ boost::int32_t i32 = 0x01020304;
+ bi::endian_flip(i32);
+ BOOST_TEST_EQ(i32, 0x04030201);
+ bi::endian_flip(i32);
+ BOOST_TEST_EQ(i32, 0x01020304);
+
+ i32 = 0xfefdfcfb;
+ bi::endian_flip(i32);
+ BOOST_TEST_EQ(i32, 0xfbfcfdfe);
+ bi::endian_flip(i32);
+ BOOST_TEST_EQ(i32, 0xfefdfcfb);
+
+ boost::int16_t i16 = 0x0102;
+ bi::endian_flip(i16);
+ BOOST_TEST_EQ(i16, 0x0201);
+ bi::endian_flip(i16);
+ BOOST_TEST_EQ(i16, 0x0102);
+
+ i16 = (boost::int16_t)0xfefd;
+ bi::endian_flip(i16);
+ BOOST_TEST_EQ(i16, (boost::int16_t)0xfdfe);
+ bi::endian_flip(i16);
+ BOOST_TEST_EQ(i16, (boost::int16_t)0xfefd);
+
+ boost::uint64_t ui64 = 0x0102030405060708LL;
+ bi::endian_flip(ui64);
+ BOOST_TEST_EQ(ui64, 0x0807060504030201LL);
+ bi::endian_flip(ui64);
+ BOOST_TEST_EQ(ui64, 0x0102030405060708LL);
+
+ boost::uint32_t ui32 = 0x01020304;
+ bi::endian_flip(ui32);
+ BOOST_TEST_EQ(ui32, 0x04030201);
+ bi::endian_flip(ui32);
+ BOOST_TEST_EQ(ui32, 0x01020304);
+
+ boost::uint16_t ui16 = 0x0102;
+ bi::endian_flip(ui16);
+ BOOST_TEST_EQ(ui16, 0x0201);
+ bi::endian_flip(ui16);
+ BOOST_TEST_EQ(ui16, 0x0102);
+
+
+ return ::boost::report_errors();
+}
Added: sandbox/endian_ext/libs/integer/endian/test/endian_in_union_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/test/endian_in_union_test.cpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,84 @@
+// endian_in_union_test.cpp -------------------------------------------------//
+
+// Copyright Beman Dawes 2008
+// Copyright VicenteJ Botet Escriba 2010-2011
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See library home page at http://www.boost.org/libs/integer/endian
+
+//----------------------------------------------------------------------------//
+
+#define BOOST_ENDIAN_FORCE_PODNESS
+
+#include <boost/integer/endian/endian.hpp>
+#include <cassert>
+
+using namespace boost::integer;
+
+union U
+{
+ big8_t big8;
+ big16_t big16;
+ big24_t big24;
+ big32_t big32;
+ big40_t big40;
+ big48_t big48;
+ big56_t big56;
+ big64_t big64;
+
+ ubig8_t ubig8;
+ ubig16_t ubig16;
+ ubig24_t ubig24;
+ ubig32_t ubig32;
+ ubig40_t ubig40;
+ ubig48_t ubig48;
+ ubig56_t ubig56;
+ ubig64_t ubig64;
+
+ little8_t little8;
+ little16_t little16;
+ little24_t little24;
+ little32_t little32;
+ little40_t little40;
+ little48_t little48;
+ little56_t little56;
+ little64_t little64;
+
+ ulittle8_t ulittle8;
+ ulittle16_t ulittle16;
+ ulittle24_t ulittle24;
+ ulittle32_t ulittle32;
+ ulittle40_t ulittle40;
+ ulittle48_t ulittle48;
+ ulittle56_t ulittle56;
+ ulittle64_t ulittle64;
+
+ native8_t native8;
+ native16_t native16;
+ native24_t native24;
+ native32_t native32;
+ native40_t native40;
+ native48_t native48;
+ native56_t native56;
+ native64_t native64;
+
+ unative8_t unative8;
+ unative16_t unative16;
+ unative24_t unative24;
+ unative32_t unative32;
+ unative40_t unative40;
+ unative48_t unative48;
+ unative56_t unative56;
+ unative64_t unative64;
+};
+
+U foo;
+
+int main()
+{
+
+ return 0;
+}
+
Added: sandbox/endian_ext/libs/integer/endian/test/endian_operations_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/test/endian_operations_test.cpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,371 @@
+// endian_operations_test.cpp ----------------------------------------------//
+
+// Copyright Beman Dawes 2008
+// Copyright VicenteJ Botet Escriba 2010-2011
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See library home page at http://www.boost.org/libs/integer/endian
+
+//----------------------------------------------------------------------------//
+
+// This test probes operator overloading, including interaction between
+// operand types.
+
+// See endian_test for tests of endianess correctness, size, and value.
+
+//----------------------------------------------------------------------------//
+
+#define BOOST_ENDIAN_LOG
+
+#include <boost/integer/endian/endian.hpp>
+#include <cassert>
+#include <iostream>
+
+namespace bi = boost::integer;
+
+#ifdef _MSC_VER
+# pragma warning( disable : 4244 ) // conversion ..., possible loss of data
+# pragma warning( disable : 4018 ) // signed/unsigned mismatch
+#endif
+
+template <class T1, class T2>
+struct default_construct
+{
+ static void test()
+ {
+ T1 o1;
+ o1 = 1; // quiet warnings
+ }
+};
+
+template <class T1, class T2>
+struct construct
+{
+ static void test()
+ {
+ T2 o2(1);
+ T1 o1(o2);
+ ++o1; // quiet gcc unused variable warning
+ }
+};
+
+template <class T1, class T2>
+struct initialize
+{
+ static void test()
+ {
+ T1 o2(2);
+ T1 o1 = o2;
+ ++o1; // quiet gcc unused variable warning
+ }
+};
+
+template <class T1, class T2>
+struct assign
+{
+ static void test()
+ {
+ T2 o2;
+ o2 = 1;
+ T1 o1;
+ o1 = o2;
+ }
+};
+
+template <class T1, class T2>
+struct relational
+{
+ static void test()
+ {
+ T1 o1(1);
+ T2 o2(2);
+ if ( o1 == o2 ) return;
+ if ( o1 != o2 ) return;
+ if ( o1 < o2 ) return;
+ if ( o1 <= o2 ) return;
+ if ( o1 > o2 ) return;
+ if ( o1 >= o2 ) return;
+ }
+};
+
+template <class T1, class T2>
+struct op_plus
+{
+ static void test()
+ {
+ T1 o1(1);
+ T2 o2(2);
+ T1 o3;
+
+ o3 = +o1;
+
+ o3 = o1 + o2;
+
+ o1 += o2;
+ }
+};
+
+template <class T1, class T2>
+struct op_star
+{
+ static void test()
+ {
+ T1 o1(1);
+ T2 o2(2);
+ T1 o3;
+
+ o3 = o1 * o2;
+
+ o1 *= o2;
+ }
+};
+
+template <template<class, class> class Test, class T1>
+void op_test_aux()
+{
+#ifdef BOOST_SHORT_ENDIAN_TEST
+ Test<T1, int>::test();
+ Test<T1, unsigned int>::test();
+ Test<T1, bi::big16_t>::test();
+ Test<T1, bi::ubig64_t>::test();
+#else
+ Test<T1, char>::test();
+ Test<T1, unsigned char>::test();
+ Test<T1, signed char>::test();
+ Test<T1, short>::test();
+ Test<T1, unsigned short>::test();
+ Test<T1, int>::test();
+ Test<T1, unsigned int>::test();
+ Test<T1, long>::test();
+ Test<T1, unsigned long>::test();
+ Test<T1, long long>::test();
+ Test<T1, unsigned long long>::test();
+ Test<T1, bi::big8_t>::test();
+ Test<T1, bi::big16_t>::test();
+ Test<T1, bi::big24_t>::test();
+ Test<T1, bi::big32_t>::test();
+ Test<T1, bi::big40_t>::test();
+ Test<T1, bi::big48_t>::test();
+ Test<T1, bi::big56_t>::test();
+ Test<T1, bi::big64_t>::test();
+ Test<T1, bi::ubig8_t>::test();
+ Test<T1, bi::ubig16_t>::test();
+ Test<T1, bi::ubig24_t>::test();
+ Test<T1, bi::ubig32_t>::test();
+ Test<T1, bi::ubig40_t>::test();
+ Test<T1, bi::ubig48_t>::test();
+ Test<T1, bi::ubig56_t>::test();
+ Test<T1, bi::ubig64_t>::test();
+ Test<T1, bi::little8_t>::test();
+ Test<T1, bi::little16_t>::test();
+ Test<T1, bi::little24_t>::test();
+ Test<T1, bi::little32_t>::test();
+ Test<T1, bi::little40_t>::test();
+ Test<T1, bi::little48_t>::test();
+ Test<T1, bi::little56_t>::test();
+ Test<T1, bi::little64_t>::test();
+ Test<T1, bi::ulittle8_t>::test();
+ Test<T1, bi::ulittle16_t>::test();
+ Test<T1, bi::ulittle24_t>::test();
+ Test<T1, bi::ulittle32_t>::test();
+ Test<T1, bi::ulittle40_t>::test();
+ Test<T1, bi::ulittle48_t>::test();
+ Test<T1, bi::ulittle56_t>::test();
+ Test<T1, bi::ulittle64_t>::test();
+ Test<T1, bi::native8_t>::test();
+ Test<T1, bi::native16_t>::test();
+ Test<T1, bi::native24_t>::test();
+ Test<T1, bi::native32_t>::test();
+ Test<T1, bi::native40_t>::test();
+ Test<T1, bi::native48_t>::test();
+ Test<T1, bi::native56_t>::test();
+ Test<T1, bi::native64_t>::test();
+ Test<T1, bi::unative8_t>::test();
+ Test<T1, bi::unative16_t>::test();
+ Test<T1, bi::unative24_t>::test();
+ Test<T1, bi::unative32_t>::test();
+ Test<T1, bi::unative40_t>::test();
+ Test<T1, bi::unative48_t>::test();
+ Test<T1, bi::unative56_t>::test();
+ Test<T1, bi::unative64_t>::test();
+#endif
+}
+
+template <template<class, class> class Test>
+void op_test()
+{
+#ifdef BOOST_SHORT_ENDIAN_TEST
+ op_test_aux<Test, unsigned short>();
+ op_test_aux<Test, int>();
+ op_test_aux<Test, bi::big32_t>();
+ op_test_aux<Test, bi::ubig32_t>();
+ op_test_aux<Test, bi::little48_t>();
+#else
+ op_test_aux<Test, char>();
+ op_test_aux<Test, unsigned char>();
+ op_test_aux<Test, signed char>();
+ op_test_aux<Test, short>();
+ op_test_aux<Test, unsigned short>();
+ op_test_aux<Test, int>();
+ op_test_aux<Test, unsigned int>();
+ op_test_aux<Test, long>();
+ op_test_aux<Test, unsigned long>();
+ op_test_aux<Test, long long>();
+ op_test_aux<Test, unsigned long long>();
+ op_test_aux<Test, bi::big8_t>();
+ op_test_aux<Test, bi::big16_t>();
+ op_test_aux<Test, bi::big24_t>();
+ op_test_aux<Test, bi::big32_t>();
+ op_test_aux<Test, bi::big40_t>();
+ op_test_aux<Test, bi::big48_t>();
+ op_test_aux<Test, bi::big56_t>();
+ op_test_aux<Test, bi::big64_t>();
+ op_test_aux<Test, bi::ubig8_t>();
+ op_test_aux<Test, bi::ubig16_t>();
+ op_test_aux<Test, bi::ubig24_t>();
+ op_test_aux<Test, bi::ubig32_t>();
+ op_test_aux<Test, bi::ubig40_t>();
+ op_test_aux<Test, bi::ubig48_t>();
+ op_test_aux<Test, bi::ubig56_t>();
+ op_test_aux<Test, bi::ubig64_t>();
+ op_test_aux<Test, bi::little8_t>();
+ op_test_aux<Test, bi::little16_t>();
+ op_test_aux<Test, bi::little24_t>();
+ op_test_aux<Test, bi::little32_t>();
+ op_test_aux<Test, bi::little40_t>();
+ op_test_aux<Test, bi::little48_t>();
+ op_test_aux<Test, bi::little56_t>();
+ op_test_aux<Test, bi::little64_t>();
+ op_test_aux<Test, bi::ulittle8_t>();
+ op_test_aux<Test, bi::ulittle16_t>();
+ op_test_aux<Test, bi::ulittle24_t>();
+ op_test_aux<Test, bi::ulittle32_t>();
+ op_test_aux<Test, bi::ulittle40_t>();
+ op_test_aux<Test, bi::ulittle48_t>();
+ op_test_aux<Test, bi::ulittle56_t>();
+ op_test_aux<Test, bi::ulittle64_t>();
+ op_test_aux<Test, bi::native8_t>();
+ op_test_aux<Test, bi::native16_t>();
+ op_test_aux<Test, bi::native24_t>();
+ op_test_aux<Test, bi::native32_t>();
+ op_test_aux<Test, bi::native40_t>();
+ op_test_aux<Test, bi::native48_t>();
+ op_test_aux<Test, bi::native56_t>();
+ op_test_aux<Test, bi::native64_t>();
+ op_test_aux<Test, bi::unative8_t>();
+ op_test_aux<Test, bi::unative16_t>();
+ op_test_aux<Test, bi::unative24_t>();
+ op_test_aux<Test, bi::unative32_t>();
+ op_test_aux<Test, bi::unative40_t>();
+ op_test_aux<Test, bi::unative48_t>();
+ op_test_aux<Test, bi::unative56_t>();
+ op_test_aux<Test, bi::unative64_t>();
+#endif
+}
+
+// main ------------------------------------------------------------------------------//
+
+int main()
+{
+ bi::endian_log = false;
+
+ // make sure some simple things work
+
+ bi::big32_t o1(1);
+ bi::big32_t o2(2L);
+ bi::big32_t o3(3LL);
+ bi::big64_t o4(1);
+
+ // use cases; if BOOST_ENDIAN_LOG is defined, will output to clog info on
+ // what overloads and conversions are actually being performed.
+
+ bi::endian_log = true;
+
+ std::clog << "set up test values\n";
+ bi::big32_t big(12345);
+ bi::ulittle16_t ulittle(10);
+ bi::big64_t result;
+
+
+ std::clog << "\nresult = +big\n";
+ result = +big;
+
+ std::clog << "\nresult = -big\n";
+ result = -big;
+
+ std::clog << "\n++big\n";
+ ++big;
+
+ std::clog << "\nresult = big++\n";
+ result = big++;
+
+ std::clog << "\n--big\n";
+ --big;
+
+ std::clog << "\nbig--\n";
+ big--;
+
+ std::clog << "\nresult = big * big\n";
+ result = big * big;
+
+ std::clog << "\nresult = big * big\n";
+ result = big * big;
+
+ std::clog << "\nresult = big * ulittle\n";
+ result = big * ulittle;
+
+ std::clog << "\nbig *= ulittle\n";
+ big *= ulittle;
+
+ std::clog << "\nresult = ulittle * big\n";
+ result = ulittle * big;
+
+ std::clog << "\nresult = big * 5\n";
+ result = big * 5;
+
+ std::clog << "\nbig *= 5\n";
+ big *= 5;
+
+ std::clog << "\nresult = 5 * big\n";
+ result = 5 * big;
+
+ std::clog << "\nresult = ulittle * 5\n";
+ result = ulittle * 5;
+
+ std::clog << "\nresult = 5 * ulittle\n";
+ result = 5 * ulittle;
+
+ std::clog << "\nresult = 5 * 10\n";
+ result = 5 * 10;
+ std::clog << "\n";
+
+ bi::endian_log = false;
+
+ // test from Roland Schwarz that detected ambiguities
+ unsigned u;
+ bi::ulittle32_t u1;
+ bi::ulittle32_t u2;
+
+ u = 1;
+ u1 = 1;
+ u2 = u1 + u;
+
+ // one more wrinkle
+ bi::ulittle16_t u3(3);
+ u3 = 3;
+ u2 = u1 + u3;
+
+ // perform the indicated test on ~60*60 operand types
+
+ op_test<default_construct>();
+ op_test<construct>(); // includes copy construction
+ op_test<initialize>();
+ op_test<assign>();
+ op_test<relational>();
+ op_test<op_plus>();
+ op_test<op_star>();
+
+ return 0;
+}
Added: sandbox/endian_ext/libs/integer/endian/test/endian_pack_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/test/endian_pack_test.cpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,599 @@
+// endian_pack_test.cpp ---------------------------------------------------------//
+
+// (C) Copyright VicenteJ Botet Escriba 2010-2011
+
+// 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/integer/endian
+
+//----------------------------------------------------------------------------//
+
+// This test probes for correct endianess, size, and value.
+
+// See endian_operations_test for tests of operator correctness and interaction
+// between operand types.
+
+//----------------------------------------------------------------------------//
+
+#include <boost/integer/endian/endian_pack.hpp>
+#include <boost/cstdint.hpp>
+#include <boost/progress.hpp>
+
+#include <iostream>
+#include <limits>
+#include <climits>
+#include <cstdlib> // for atoi(), exit()
+#include <cstring> // for memcmp()
+
+using namespace std; // Not the best programming practice, but I
+using namespace boost; // want to verify this combination of using
+using namespace boost::integer; // namespaces works. See endian_operations_test
+// // for tests that don't do "using namespace".
+
+#define VERIFY(predicate) verify( predicate, __LINE__ )
+#define VERIFY_SIZE(actual, expected) verify_size( actual, expected, __LINE__ )
+#define VERIFY_VALUE_AND_OPS(endian_t,expected_t,expected) verify_value_and_ops<endian_t, expected_t>( expected, __LINE__ )
+#define VERIFY_BIG_REPRESENTATION(t) verify_representation<t>( true, __LINE__ )
+#define VERIFY_LITTLE_REPRESENTATION(t) verify_representation<t>( false, __LINE__ )
+#define VERIFY_NATIVE_REPRESENTATION(t) verify_native_representation<t>( __LINE__ )
+
+namespace
+{
+ int err_count;
+
+ void verify( bool x, int line )
+ {
+ if ( x ) return;
+ ++err_count;
+ cout << "Error: verify failed on line " << line << endl;
+ }
+
+ void verify_size( size_t actual, size_t expected, int line )
+ {
+ if ( actual == expected ) return;
+ ++err_count;
+ cout << "Error: verify size failed on line " << line << endl;
+ cout << " A structure with an expected sizeof() " << expected
+ << " had an actual sizeof() " << actual
+ << "\n This will cause common uses of <boost/endian_pack.hpp> to fail\n";
+ }
+
+ template <class Endian, class Base>
+ void verify_value_and_ops( const Base & expected, int line )
+ {
+ Endian v( expected );
+ verify( v == expected, line );
+
+ Endian v2;
+ v2.operator=( expected );
+ verify( v2 == expected, line );
+
+ //~ ++v; // verify integer_cover_operators being applied to this type -
+ // will fail to compile if no endian_pack<> specialization is present
+ }
+
+ const char * big_rep = "\x12\x34\x56\x78\x9A\xBC\xDE\xF0";
+ const char * little_rep = "\xF0\xDE\xBC\x9A\x78\x56\x34\x12";
+
+ template <class Endian>
+ void verify_representation( bool is_big, int line )
+ {
+ int silence = 0;
+ Endian x ( static_cast<typename Endian::value_type>
+ (0x123456789abcdef0LL + silence) ); // will truncate
+
+ if ( is_big )
+ verify( memcmp( &x,
+ reinterpret_cast<const char*>(big_rep)+8-sizeof(Endian),
+ sizeof(Endian) ) == 0, line );
+ else
+ verify( memcmp( &x, little_rep, sizeof(Endian) ) == 0, line );
+ }
+
+ template <class Endian>
+ inline void verify_native_representation( int line )
+ {
+# ifdef BOOST_BIG_ENDIAN
+ verify_representation<Endian>( true, line );
+# else
+ verify_representation<Endian>( false, line );
+# endif
+ }
+
+ // detect_endianness -----------------------------------------------------//
+
+ void detect_endianness()
+ {
+ union View
+ {
+ long long i;
+ unsigned char c[8];
+ };
+
+ View v = { 0x0102030405060708LL }; // initialize v.i
+
+ if ( memcmp( v.c, "\10\7\6\5\4\3\2\1", 8) == 0 )
+ {
+ cout << "This machine is little-endian.\n";
+ # ifdef BOOST_BIG_INTEGER_OPERATORS
+ cout << "yet boost/detail/endian_pack.hpp defines BOOST_BIG_INTEGER_OPERATORS.\n"
+ "You must fix boost/detail/endian_pack.hpp for boost/endian_pack.hpp to work correctly.\n"
+ "Please report the fix to the Boost mailing list.\n";
+ exit(1);
+ # endif
+ }
+ else if ( memcmp( v.c, "\1\2\3\4\5\6\7\10", 8) == 0 )
+ {
+ cout << "This machine is big-endian.\n";
+ # ifdef BOOST_LITTLE_INTEGER_OPERATORS
+ cout << "yet boost/detail/endian_pack.hpp defines BOOST__LITTLE_INTEGER_OPERATORS.\n"
+ "You must fix boost/detail/endian_pack.hpp for boost/endian_pack.hpp to work correctly.\n"
+ "Please report the fix to the Boost mailing list.\n";
+ exit(1);
+ # endif
+ }
+ else
+ {
+ cout << "This machine is neither strict big-endian nor strict little-endian\n"
+ "You must modify boost/endian_pack.hpp for it to work correctly.\n";
+ exit(1);
+ }
+ cout << "That should not matter and is presented for your information only.\n";
+ } // detect_endianness
+
+ // check_size ------------------------------------------------------------//
+
+ void check_size()
+ {
+ VERIFY( numeric_limits<signed char>::digits == 7 );
+ VERIFY( numeric_limits<unsigned char>::digits == 8 );
+
+ VERIFY_SIZE( sizeof( big8_pt ), 1 );
+ VERIFY_SIZE( sizeof( big16_pt ), 2 );
+ VERIFY_SIZE( sizeof( big24_pt ), 3 );
+ VERIFY_SIZE( sizeof( big32_pt ), 4 );
+ VERIFY_SIZE( sizeof( big40_pt ), 5 );
+ VERIFY_SIZE( sizeof( big48_pt ), 6 );
+ VERIFY_SIZE( sizeof( big56_pt ), 7 );
+ VERIFY_SIZE( sizeof( big64_pt ), 8 );
+
+ VERIFY_SIZE( sizeof( ubig8_pt ), 1 );
+ VERIFY_SIZE( sizeof( ubig16_pt ), 2 );
+ VERIFY_SIZE( sizeof( ubig24_pt ), 3 );
+ VERIFY_SIZE( sizeof( ubig32_pt ), 4 );
+ VERIFY_SIZE( sizeof( ubig40_pt ), 5 );
+ VERIFY_SIZE( sizeof( ubig48_pt ), 6 );
+ VERIFY_SIZE( sizeof( ubig56_pt ), 7 );
+ VERIFY_SIZE( sizeof( ubig64_pt ), 8 );
+
+ VERIFY_SIZE( sizeof( little8_pt ), 1 );
+ VERIFY_SIZE( sizeof( little16_pt ), 2 );
+ VERIFY_SIZE( sizeof( little24_pt ), 3 );
+ VERIFY_SIZE( sizeof( little32_pt ), 4 );
+ VERIFY_SIZE( sizeof( little40_pt ), 5 );
+ VERIFY_SIZE( sizeof( little48_pt ), 6 );
+ VERIFY_SIZE( sizeof( little56_pt ), 7 );
+ VERIFY_SIZE( sizeof( little64_pt ), 8 );
+
+ VERIFY_SIZE( sizeof( ulittle8_pt ), 1 );
+ VERIFY_SIZE( sizeof( ulittle16_pt ), 2 );
+ VERIFY_SIZE( sizeof( ulittle24_pt ), 3 );
+ VERIFY_SIZE( sizeof( ulittle32_pt ), 4 );
+ VERIFY_SIZE( sizeof( ulittle40_pt ), 5 );
+ VERIFY_SIZE( sizeof( ulittle48_pt ), 6 );
+ VERIFY_SIZE( sizeof( ulittle56_pt ), 7 );
+ VERIFY_SIZE( sizeof( ulittle64_pt ), 8 );
+
+ VERIFY_SIZE( sizeof( native8_pt ), 1 );
+ VERIFY_SIZE( sizeof( native16_pt ), 2 );
+ VERIFY_SIZE( sizeof( native24_pt ), 3 );
+ VERIFY_SIZE( sizeof( native32_pt ), 4 );
+ VERIFY_SIZE( sizeof( native40_pt ), 5 );
+ VERIFY_SIZE( sizeof( native48_pt ), 6 );
+ VERIFY_SIZE( sizeof( native56_pt ), 7 );
+ VERIFY_SIZE( sizeof( native64_pt ), 8 );
+
+ VERIFY_SIZE( sizeof( unative8_pt ), 1 );
+ VERIFY_SIZE( sizeof( unative16_pt ), 2 );
+ VERIFY_SIZE( sizeof( unative24_pt ), 3 );
+ VERIFY_SIZE( sizeof( unative32_pt ), 4 );
+ VERIFY_SIZE( sizeof( unative40_pt ), 5 );
+ VERIFY_SIZE( sizeof( unative48_pt ), 6 );
+ VERIFY_SIZE( sizeof( unative56_pt ), 7 );
+ VERIFY_SIZE( sizeof( unative64_pt ), 8 );
+
+ VERIFY_SIZE( sizeof( aligned_big16_pt ), 2 );
+ VERIFY_SIZE( sizeof( aligned_big32_pt ), 4 );
+ VERIFY_SIZE( sizeof( aligned_big64_pt ), 8 );
+
+ VERIFY_SIZE( sizeof( aligned_ubig16_pt ), 2 );
+ VERIFY_SIZE( sizeof( aligned_ubig32_pt ), 4 );
+ VERIFY_SIZE( sizeof( aligned_ubig64_pt ), 8 );
+
+ VERIFY_SIZE( sizeof( aligned_little16_pt ), 2 );
+ VERIFY_SIZE( sizeof( aligned_little32_pt ), 4 );
+ VERIFY_SIZE( sizeof( aligned_little64_pt ), 8 );
+
+ VERIFY_SIZE( sizeof( aligned_ulittle16_pt ), 2 );
+ VERIFY_SIZE( sizeof( aligned_ulittle32_pt ), 4 );
+ VERIFY_SIZE( sizeof( aligned_ulittle64_pt ), 8 );
+ } // check_size
+
+ // check_alignment -------------------------------------------------------//
+
+ void check_alignment()
+ {
+ // structs with offsets % 2 == 1 for type of size > 1 to ensure no alignment
+ // bytes added for any size > 1
+
+ struct big_struct
+ {
+ big8_pt v0;
+ big16_pt v1;
+ big24_pt v3;
+ char v6;
+ big32_pt v7;
+ big40_pt v11;
+ char v16;
+ big48_pt v17;
+ big56_pt v23;
+ char v30;
+ big64_pt v31;
+ };
+
+ struct ubig_struct
+ {
+ ubig8_pt v0;
+ ubig16_pt v1;
+ ubig24_pt v3;
+ char v6;
+ ubig32_pt v7;
+ ubig40_pt v11;
+ char v16;
+ ubig48_pt v17;
+ ubig56_pt v23;
+ char v30;
+ ubig64_pt v31;
+ };
+
+ struct little_struct
+ {
+ little8_pt v0;
+ little16_pt v1;
+ little24_pt v3;
+ char v6;
+ little32_pt v7;
+ little40_pt v11;
+ char v16;
+ little48_pt v17;
+ little56_pt v23;
+ char v30;
+ little64_pt v31;
+ };
+
+ struct ulittle_struct
+ {
+ ulittle8_pt v0;
+ ulittle16_pt v1;
+ ulittle24_pt v3;
+ char v6;
+ ulittle32_pt v7;
+ ulittle40_pt v11;
+ char v16;
+ ulittle48_pt v17;
+ ulittle56_pt v23;
+ char v30;
+ ulittle64_pt v31;
+ };
+
+ struct native_struct
+ {
+ native8_pt v0;
+ native16_pt v1;
+ native24_pt v3;
+ char v6;
+ native32_pt v7;
+ native40_pt v11;
+ char v16;
+ native48_pt v17;
+ native56_pt v23;
+ char v30;
+ native64_pt v31;
+ };
+
+ struct unative_struct
+ {
+ unative8_pt v0;
+ unative16_pt v1;
+ unative24_pt v3;
+ char v6;
+ unative32_pt v7;
+ unative40_pt v11;
+ char v16;
+ unative48_pt v17;
+ unative56_pt v23;
+ char v30;
+ unative64_pt v31;
+ };
+
+ int saved_err_count = err_count;
+
+ VERIFY_SIZE( sizeof(big_struct), 39 );
+ VERIFY_SIZE( sizeof(ubig_struct), 39 );
+ VERIFY_SIZE( sizeof(little_struct), 39 );
+ VERIFY_SIZE( sizeof(ulittle_struct), 39 );
+ VERIFY_SIZE( sizeof(native_struct), 39 );
+ VERIFY_SIZE( sizeof(unative_struct), 39 );
+
+ if ( saved_err_count == err_count )
+ {
+ cout <<
+ "Size and alignment for structures of endian_pack types are as expected.\n";
+ }
+ } // check_alignment
+
+ // check_representation_and_range_and_ops --------------------------------//
+
+ void check_representation_and_range_and_ops()
+ {
+
+ VERIFY_BIG_REPRESENTATION( big8_pt );
+ VERIFY_VALUE_AND_OPS( big8_pt, int_least8_t, 0x7f );
+ VERIFY_VALUE_AND_OPS( big8_pt, int_least8_t, -0x80 );
+
+ VERIFY_BIG_REPRESENTATION( big16_pt );
+ VERIFY_VALUE_AND_OPS( big16_pt, int_least16_t, 0x7fff );
+ VERIFY_VALUE_AND_OPS( big16_pt, int_least16_t, -0x8000 );
+
+ VERIFY_BIG_REPRESENTATION( big24_pt );
+ VERIFY_VALUE_AND_OPS( big24_pt, int_least32_t, 0x7fffff );
+ VERIFY_VALUE_AND_OPS( big24_pt, int_least32_t, -0x800000 );
+
+ VERIFY_BIG_REPRESENTATION( big32_pt );
+ VERIFY_VALUE_AND_OPS( big32_pt, int_least32_t, 0x7fffffff );
+ VERIFY_VALUE_AND_OPS( big32_pt, int_least32_t, -0x7fffffff-1 );
+
+ VERIFY_BIG_REPRESENTATION( big40_pt );
+ VERIFY_VALUE_AND_OPS( big40_pt, int_least64_t, 0x7fffffffffLL );
+ VERIFY_VALUE_AND_OPS( big40_pt, int_least64_t, -0x8000000000LL );
+
+ VERIFY_BIG_REPRESENTATION( big48_pt );
+ VERIFY_VALUE_AND_OPS( big48_pt, int_least64_t, 0x7fffffffffffLL );
+ VERIFY_VALUE_AND_OPS( big48_pt, int_least64_t, -0x800000000000LL );
+
+ VERIFY_BIG_REPRESENTATION( big56_pt );
+ VERIFY_VALUE_AND_OPS( big56_pt, int_least64_t, 0x7fffffffffffffLL );
+ VERIFY_VALUE_AND_OPS( big56_pt, int_least64_t, -0x80000000000000LL );
+
+ VERIFY_BIG_REPRESENTATION( big64_pt );
+ VERIFY_VALUE_AND_OPS( big64_pt, int_least64_t, 0x7fffffffffffffffLL );
+ VERIFY_VALUE_AND_OPS( big64_pt, int_least64_t, -0x7fffffffffffffffLL-1 );
+
+ VERIFY_BIG_REPRESENTATION( ubig8_pt );
+ VERIFY_VALUE_AND_OPS( ubig8_pt, uint_least8_t, 0xff );
+
+ VERIFY_BIG_REPRESENTATION( ubig16_pt );
+ VERIFY_VALUE_AND_OPS( ubig16_pt, uint_least16_t, 0xffff );
+
+ VERIFY_BIG_REPRESENTATION( ubig24_pt );
+ VERIFY_VALUE_AND_OPS( ubig24_pt, uint_least32_t, 0xffffff );
+
+ VERIFY_BIG_REPRESENTATION( ubig32_pt );
+ VERIFY_VALUE_AND_OPS( ubig32_pt, uint_least32_t, 0xffffffff );
+
+ VERIFY_BIG_REPRESENTATION( ubig40_pt );
+ VERIFY_VALUE_AND_OPS( ubig40_pt, uint_least64_t, 0xffffffffffLL );
+
+ VERIFY_BIG_REPRESENTATION( ubig48_pt );
+ VERIFY_VALUE_AND_OPS( ubig48_pt, uint_least64_t, 0xffffffffffffLL );
+
+ VERIFY_BIG_REPRESENTATION( ubig56_pt );
+ VERIFY_VALUE_AND_OPS( ubig56_pt, uint_least64_t, 0xffffffffffffffLL );
+
+ VERIFY_BIG_REPRESENTATION( ubig64_pt );
+ VERIFY_VALUE_AND_OPS( ubig64_pt, uint_least64_t, 0xffffffffffffffffLL );
+
+ VERIFY_LITTLE_REPRESENTATION( little8_pt );
+ VERIFY_VALUE_AND_OPS( little8_pt, int_least8_t, 0x7f );
+ VERIFY_VALUE_AND_OPS( little8_pt, int_least8_t, -0x80 );
+
+ VERIFY_LITTLE_REPRESENTATION( little16_pt );
+ VERIFY_VALUE_AND_OPS( little16_pt, int_least16_t, 0x7fff );
+ VERIFY_VALUE_AND_OPS( little16_pt, int_least16_t, -0x8000 );
+
+ VERIFY_LITTLE_REPRESENTATION( little24_pt );
+ VERIFY_VALUE_AND_OPS( little24_pt, int_least32_t, 0x7fffff );
+ VERIFY_VALUE_AND_OPS( little24_pt, int_least32_t, -0x800000 );
+
+ VERIFY_LITTLE_REPRESENTATION( little32_pt );
+ VERIFY_VALUE_AND_OPS( little32_pt, int_least32_t, 0x7fffffff );
+ VERIFY_VALUE_AND_OPS( little32_pt, int_least32_t, -0x7fffffff-1 );
+
+ VERIFY_LITTLE_REPRESENTATION( little40_pt );
+ VERIFY_VALUE_AND_OPS( little40_pt, int_least64_t, 0x7fffffffffLL );
+ VERIFY_VALUE_AND_OPS( little40_pt, int_least64_t, -0x8000000000LL );
+
+ VERIFY_LITTLE_REPRESENTATION( little48_pt );
+ VERIFY_VALUE_AND_OPS( little48_pt, int_least64_t, 0x7fffffffffffLL );
+ VERIFY_VALUE_AND_OPS( little48_pt, int_least64_t, -0x800000000000LL );
+
+ VERIFY_LITTLE_REPRESENTATION( little56_pt );
+ VERIFY_VALUE_AND_OPS( little56_pt, int_least64_t, 0x7fffffffffffffLL );
+ VERIFY_VALUE_AND_OPS( little56_pt, int_least64_t, -0x80000000000000LL );
+
+ VERIFY_LITTLE_REPRESENTATION( little64_pt );
+ VERIFY_VALUE_AND_OPS( little64_pt, int_least64_t, 0x7fffffffffffffffLL );
+ VERIFY_VALUE_AND_OPS( little64_pt, int_least64_t, -0x7fffffffffffffffLL-1 );
+
+ VERIFY_LITTLE_REPRESENTATION( ulittle8_pt );
+ VERIFY_VALUE_AND_OPS( ulittle8_pt, uint_least8_t, 0xff );
+
+ VERIFY_LITTLE_REPRESENTATION( ulittle16_pt );
+ VERIFY_VALUE_AND_OPS( ulittle16_pt, uint_least16_t, 0xffff );
+
+ VERIFY_LITTLE_REPRESENTATION( ulittle24_pt );
+ VERIFY_VALUE_AND_OPS( ulittle24_pt, uint_least32_t, 0xffffff );
+
+ VERIFY_LITTLE_REPRESENTATION( ulittle32_pt );
+ VERIFY_VALUE_AND_OPS( ulittle32_pt, uint_least32_t, 0xffffffff );
+
+ VERIFY_LITTLE_REPRESENTATION( ulittle40_pt );
+ VERIFY_VALUE_AND_OPS( ulittle40_pt, uint_least64_t, 0xffffffffffLL );
+
+ VERIFY_LITTLE_REPRESENTATION( ulittle48_pt );
+ VERIFY_VALUE_AND_OPS( ulittle48_pt, uint_least64_t, 0xffffffffffffLL );
+
+ VERIFY_LITTLE_REPRESENTATION( ulittle56_pt );
+ VERIFY_VALUE_AND_OPS( ulittle56_pt, uint_least64_t, 0xffffffffffffffLL );
+
+ VERIFY_LITTLE_REPRESENTATION( ulittle64_pt );
+ VERIFY_VALUE_AND_OPS( ulittle64_pt, uint_least64_t, 0xffffffffffffffffLL );
+
+ VERIFY_NATIVE_REPRESENTATION( native8_pt );
+ VERIFY_VALUE_AND_OPS( native8_pt, int_least8_t, 0x7f );
+ VERIFY_VALUE_AND_OPS( native8_pt, int_least8_t, -0x80 );
+
+ VERIFY_NATIVE_REPRESENTATION( native16_pt );
+ VERIFY_VALUE_AND_OPS( native16_pt, int_least16_t, 0x7fff );
+ VERIFY_VALUE_AND_OPS( native16_pt, int_least16_t, -0x8000 );
+
+ VERIFY_NATIVE_REPRESENTATION( native24_pt );
+ VERIFY_VALUE_AND_OPS( native24_pt, int_least32_t, 0x7fffff );
+ VERIFY_VALUE_AND_OPS( native24_pt, int_least32_t, -0x800000 );
+
+ VERIFY_NATIVE_REPRESENTATION( native32_pt );
+ VERIFY_VALUE_AND_OPS( native32_pt, int_least32_t, 0x7fffffff );
+ VERIFY_VALUE_AND_OPS( native32_pt, int_least32_t, -0x7fffffff-1 );
+
+ VERIFY_NATIVE_REPRESENTATION( native40_pt );
+ VERIFY_VALUE_AND_OPS( native40_pt, int_least64_t, 0x7fffffffffLL );
+ VERIFY_VALUE_AND_OPS( native40_pt, int_least64_t, -0x8000000000LL );
+
+ VERIFY_NATIVE_REPRESENTATION( native48_pt );
+ VERIFY_VALUE_AND_OPS( native48_pt, int_least64_t, 0x7fffffffffffLL );
+ VERIFY_VALUE_AND_OPS( native48_pt, int_least64_t, -0x800000000000LL );
+
+ VERIFY_NATIVE_REPRESENTATION( native56_pt );
+ VERIFY_VALUE_AND_OPS( native56_pt, int_least64_t, 0x7fffffffffffffLL );
+ VERIFY_VALUE_AND_OPS( native56_pt, int_least64_t, -0x80000000000000LL );
+
+ VERIFY_NATIVE_REPRESENTATION( native64_pt );
+ VERIFY_VALUE_AND_OPS( native64_pt, int_least64_t, 0x7fffffffffffffffLL );
+ VERIFY_VALUE_AND_OPS( native64_pt, int_least64_t, -0x7fffffffffffffffLL-1 );
+
+ VERIFY_NATIVE_REPRESENTATION( unative8_pt );
+ VERIFY_VALUE_AND_OPS( unative8_pt, uint_least8_t, 0xff );
+
+ VERIFY_NATIVE_REPRESENTATION( unative16_pt );
+ VERIFY_VALUE_AND_OPS( unative16_pt, uint_least16_t, 0xffff );
+
+ VERIFY_NATIVE_REPRESENTATION( unative24_pt );
+ VERIFY_VALUE_AND_OPS( unative24_pt, uint_least32_t, 0xffffff );
+
+ VERIFY_NATIVE_REPRESENTATION( unative32_pt );
+ VERIFY_VALUE_AND_OPS( unative32_pt, uint_least32_t, 0xffffffff );
+
+ VERIFY_NATIVE_REPRESENTATION( unative40_pt );
+ VERIFY_VALUE_AND_OPS( unative40_pt, uint_least64_t, 0xffffffffffLL );
+
+ VERIFY_NATIVE_REPRESENTATION( unative48_pt );
+ VERIFY_VALUE_AND_OPS( unative48_pt, uint_least64_t, 0xffffffffffffLL );
+
+ VERIFY_NATIVE_REPRESENTATION( unative56_pt );
+ VERIFY_VALUE_AND_OPS( unative56_pt, uint_least64_t, 0xffffffffffffffLL );
+
+ VERIFY_NATIVE_REPRESENTATION( unative64_pt );
+ VERIFY_VALUE_AND_OPS( unative64_pt, uint_least64_t, 0xffffffffffffffffLL );
+
+ VERIFY_BIG_REPRESENTATION( aligned_big16_pt );
+ VERIFY_VALUE_AND_OPS( aligned_big16_pt, int_least16_t, 0x7fff );
+ VERIFY_VALUE_AND_OPS( aligned_big16_pt, int_least16_t, -0x8000 );
+
+ VERIFY_BIG_REPRESENTATION( aligned_big32_pt );
+ VERIFY_VALUE_AND_OPS( aligned_big32_pt, int_least32_t, 0x7fffffff );
+ VERIFY_VALUE_AND_OPS( aligned_big32_pt, int_least32_t, -0x7fffffff-1 );
+
+ VERIFY_BIG_REPRESENTATION( aligned_big64_pt );
+ VERIFY_VALUE_AND_OPS( aligned_big64_pt, int_least64_t, 0x7fffffffffffffffLL );
+ VERIFY_VALUE_AND_OPS( aligned_big64_pt, int_least64_t, -0x7fffffffffffffffLL-1 );
+
+ VERIFY_BIG_REPRESENTATION( aligned_ubig16_pt );
+ VERIFY_VALUE_AND_OPS( aligned_ubig16_pt, uint_least16_t, 0xffff );
+
+ VERIFY_BIG_REPRESENTATION( aligned_ubig32_pt );
+ VERIFY_VALUE_AND_OPS( aligned_ubig32_pt, uint_least32_t, 0xffffffff );
+
+ VERIFY_BIG_REPRESENTATION( aligned_ubig64_pt );
+ VERIFY_VALUE_AND_OPS( aligned_ubig64_pt, uint_least64_t, 0xffffffffffffffffLL );
+
+ VERIFY_LITTLE_REPRESENTATION( aligned_little16_pt );
+ VERIFY_VALUE_AND_OPS( aligned_little16_pt, int_least16_t, 0x7fff );
+ VERIFY_VALUE_AND_OPS( aligned_little16_pt, int_least16_t, -0x8000 );
+
+ VERIFY_LITTLE_REPRESENTATION( aligned_little32_pt );
+ VERIFY_VALUE_AND_OPS( aligned_little32_pt, int_least32_t, 0x7fffffff );
+ VERIFY_VALUE_AND_OPS( aligned_little32_pt, int_least32_t, -0x7fffffff-1 );
+
+ VERIFY_LITTLE_REPRESENTATION( aligned_little64_pt );
+ VERIFY_VALUE_AND_OPS( aligned_little64_pt, int_least64_t, 0x7fffffffffffffffLL );
+ VERIFY_VALUE_AND_OPS( aligned_little64_pt, int_least64_t, -0x7fffffffffffffffLL-1 );
+
+ VERIFY_LITTLE_REPRESENTATION( aligned_ulittle16_pt );
+ VERIFY_VALUE_AND_OPS( aligned_ulittle16_pt, uint_least16_t, 0xffff );
+
+ VERIFY_LITTLE_REPRESENTATION( aligned_ulittle32_pt );
+ VERIFY_VALUE_AND_OPS( aligned_ulittle32_pt, uint_least32_t, 0xffffffff );
+
+ VERIFY_LITTLE_REPRESENTATION( aligned_ulittle64_pt );
+ VERIFY_VALUE_AND_OPS( aligned_ulittle64_pt, uint_least64_t, 0xffffffffffffffffLL );
+
+ } // check_representation_and_range
+
+ long iterations = 10000000;
+
+ template< class Endian >
+ Endian timing_test( const char * s)
+ {
+ cout << s << " timing test, " << iterations << " iterations: ";
+ progress_timer t;
+
+ Endian v = 1;
+ for ( long i = 0; i < iterations; ++i )
+ {
+ v += 1;
+ v *= 3;
+ ++v;
+ v *= i;
+ if ( i == 0 ) VERIFY_VALUE_AND_OPS( Endian, typename Endian::value_type, 21 );
+ }
+ return v;
+ }
+
+} // unnamed namespace
+
+int main( int argc, char * argv[] )
+{
+ cout << "Usage: "
+ << argv[0] << " [#],\n where # specifies iteration count\n"
+ " default iteration count is 1000000" << endl;
+
+ if ( argc > 1 )
+ iterations = atol( argv[1] );
+ if ( iterations < 1 ) iterations = 1;
+
+ detect_endianness();
+ check_size();
+ check_alignment();
+ check_representation_and_range_and_ops();
+
+ //timing_test<big32_t> ( "big32_t" );
+ //timing_test<aligned_big32_t>( "aligned_big32_t" );
+ //timing_test<little32_t> ( "little32_t" );
+ //timing_test<aligned_little32_t>( "aligned_little32_t" );
+
+ cout << "\n" << err_count << " errors detected\nTest "
+ << (err_count==0 ? "passed\n\n" : "failed\n\n");
+
+ return err_count ? 1 : 0;
+} // main
Added: sandbox/endian_ext/libs/integer/endian/test/endian_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/test/endian_test.cpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,748 @@
+// endian_test.cpp ---------------------------------------------------------//
+
+// Copyright Beman Dawes 1999-2008
+
+// 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/integer/endian
+
+//----------------------------------------------------------------------------//
+
+// This test probes for correct endianess, size, and value.
+
+// See endian_operations_test for tests of operator correctness and interaction
+// between operand types.
+
+//----------------------------------------------------------------------------//
+
+#include <boost/integer/endian/endian.hpp>
+#include <boost/cstdint.hpp>
+#include <boost/progress.hpp>
+
+#include <iostream>
+#include <limits>
+#include <climits>
+#include <cstdlib> // for atoi(), exit()
+#include <cstring> // for memcmp()
+
+using namespace std; // Not the best programming practice, but I
+using namespace boost; // want to verify this combination of using
+using namespace boost::integer; // namespaces works. See endian_operations_test
+// // for tests that don't do "using namespace".
+
+#define VERIFY(predicate) verify( predicate, __LINE__ )
+#define VERIFY_SIZE(actual, expected) verify_size( actual, expected, __LINE__ )
+#define VERIFY_VALUE_AND_OPS(endian_t,expected_t,expected) verify_value_and_ops<endian_t, expected_t>( expected, __LINE__ )
+#define VERIFY_BIG_REPRESENTATION(t) verify_representation<t>( true, __LINE__ )
+#define VERIFY_LITTLE_REPRESENTATION(t) verify_representation<t>( false, __LINE__ )
+#define VERIFY_NATIVE_REPRESENTATION(t) verify_native_representation<t>( __LINE__ )
+
+namespace
+{
+ int err_count;
+
+ void verify( bool x, int line )
+ {
+ if ( x ) return;
+ ++err_count;
+ cout << "Error: verify failed on line " << line << endl;
+ }
+
+ void verify_size( size_t actual, size_t expected, int line )
+ {
+ if ( actual == expected ) return;
+ ++err_count;
+ cout << "Error: verify size failed on line " << line << endl;
+ cout << " A structure with an expected sizeof() " << expected
+ << " had an actual sizeof() " << actual
+ << "\n This will cause common uses of <boost/endian.hpp> to fail\n";
+ }
+
+ template <class Endian, class Base>
+ void verify_value_and_ops( const Base & expected, int line )
+ {
+ Endian v( expected );
+ verify( v == expected, line );
+
+ Endian v2;
+ v2.operator=( expected );
+ verify( v2 == expected, line );
+
+ ++v; // verify integer_cover_operators being applied to this type -
+ // will fail to compile if no endian<> specialization is present
+ }
+
+ const char * big_rep = "\x12\x34\x56\x78\x9A\xBC\xDE\xF0";
+ const char * little_rep = "\xF0\xDE\xBC\x9A\x78\x56\x34\x12";
+
+ template <class Endian>
+ void verify_representation( bool is_big, int line )
+ {
+ int silence = 0;
+ Endian x ( static_cast<typename Endian::value_type>
+ (0x123456789abcdef0LL + silence) ); // will truncate
+
+ if ( is_big )
+ verify( memcmp( &x,
+ reinterpret_cast<const char*>(big_rep)+8-sizeof(Endian),
+ sizeof(Endian) ) == 0, line );
+ else
+ verify( memcmp( &x, little_rep, sizeof(Endian) ) == 0, line );
+ }
+
+ template <class Endian>
+ inline void verify_native_representation( int line )
+ {
+# ifdef BOOST_BIG_ENDIAN
+ verify_representation<Endian>( true, line );
+# else
+ verify_representation<Endian>( false, line );
+# endif
+ }
+
+ // detect_endianness -----------------------------------------------------//
+
+ void detect_endianness()
+ {
+ union View
+ {
+ long long i;
+ unsigned char c[8];
+ };
+
+ View v = { 0x0102030405060708LL }; // initialize v.i
+
+ if ( memcmp( v.c, "\10\7\6\5\4\3\2\1", 8) == 0 )
+ {
+ cout << "This machine is little-endian.\n";
+ # ifdef BOOST_BIG_INTEGER_OPERATORS
+ cout << "yet boost/detail/endian.hpp defines BOOST_BIG_INTEGER_OPERATORS.\n"
+ "You must fix boost/detail/endian.hpp for boost/endian.hpp to work correctly.\n"
+ "Please report the fix to the Boost mailing list.\n";
+ exit(1);
+ # endif
+ }
+ else if ( memcmp( v.c, "\1\2\3\4\5\6\7\10", 8) == 0 )
+ {
+ cout << "This machine is big-endian.\n";
+ # ifdef BOOST_LITTLE_INTEGER_OPERATORS
+ cout << "yet boost/detail/endian.hpp defines BOOST__LITTLE_INTEGER_OPERATORS.\n"
+ "You must fix boost/detail/endian.hpp for boost/endian.hpp to work correctly.\n"
+ "Please report the fix to the Boost mailing list.\n";
+ exit(1);
+ # endif
+ }
+ else
+ {
+ cout << "This machine is neither strict big-endian nor strict little-endian\n"
+ "You must modify boost/endian.hpp for it to work correctly.\n";
+ exit(1);
+ }
+ cout << "That should not matter and is presented for your information only.\n";
+ } // detect_endianness
+
+ // check_data ------------------------------------------------------------//
+
+ void check_data()
+ {
+ big8_t big8;
+ big16_t big16;
+ big24_t big24;
+ big32_t big32;
+ big40_t big40;
+ big48_t big48;
+ big56_t big56;
+ big64_t big64;
+
+ ubig8_t ubig8;
+ ubig16_t ubig16;
+ ubig24_t ubig24;
+ ubig32_t ubig32;
+ ubig40_t ubig40;
+ ubig48_t ubig48;
+ ubig56_t ubig56;
+ ubig64_t ubig64;
+
+ little8_t little8;
+ little16_t little16;
+ little24_t little24;
+ little32_t little32;
+ little40_t little40;
+ little48_t little48;
+ little56_t little56;
+ little64_t little64;
+
+ ulittle8_t ulittle8;
+ ulittle16_t ulittle16;
+ ulittle24_t ulittle24;
+ ulittle32_t ulittle32;
+ ulittle40_t ulittle40;
+ ulittle48_t ulittle48;
+ ulittle56_t ulittle56;
+ ulittle64_t ulittle64;
+
+ native8_t native8;
+ native16_t native16;
+ native24_t native24;
+ native32_t native32;
+ native40_t native40;
+ native48_t native48;
+ native56_t native56;
+ native64_t native64;
+
+ unative8_t unative8;
+ unative16_t unative16;
+ unative24_t unative24;
+ unative32_t unative32;
+ unative40_t unative40;
+ unative48_t unative48;
+ unative56_t unative56;
+ unative64_t unative64;
+
+ aligned_big16_t aligned_big16;
+ aligned_big32_t aligned_big32;
+ aligned_big64_t aligned_big64;
+
+ aligned_ubig16_t aligned_ubig16;
+ aligned_ubig32_t aligned_ubig32;
+ aligned_ubig64_t aligned_ubig64;
+
+ aligned_little16_t aligned_little16;
+ aligned_little32_t aligned_little32;
+ aligned_little64_t aligned_little64;
+
+ aligned_ulittle16_t aligned_ulittle16 ;
+ aligned_ulittle32_t aligned_ulittle32 ;
+ aligned_ulittle64_t aligned_ulittle64 ;
+
+ VERIFY(big8.data() == reinterpret_cast<const char *>(&big8));
+ VERIFY(big16.data() == reinterpret_cast<const char *>(&big16));
+ VERIFY(big24.data() == reinterpret_cast<const char *>(&big24));
+ VERIFY(big32.data() == reinterpret_cast<const char *>(&big32));
+ VERIFY(big40.data() == reinterpret_cast<const char *>(&big40));
+ VERIFY(big48.data() == reinterpret_cast<const char *>(&big48));
+ VERIFY(big56.data() == reinterpret_cast<const char *>(&big56));
+ VERIFY(big64.data() == reinterpret_cast<const char *>(&big64));
+
+ VERIFY(ubig8.data() == reinterpret_cast<const char *>(&ubig8));
+ VERIFY(ubig16.data() == reinterpret_cast<const char *>(&ubig16));
+ VERIFY(ubig24.data() == reinterpret_cast<const char *>(&ubig24));
+ VERIFY(ubig32.data() == reinterpret_cast<const char *>(&ubig32));
+ VERIFY(ubig40.data() == reinterpret_cast<const char *>(&ubig40));
+ VERIFY(ubig48.data() == reinterpret_cast<const char *>(&ubig48));
+ VERIFY(ubig56.data() == reinterpret_cast<const char *>(&ubig56));
+ VERIFY(ubig64.data() == reinterpret_cast<const char *>(&ubig64));
+
+ VERIFY(little8.data() == reinterpret_cast<const char *>(&little8));
+ VERIFY(little16.data() == reinterpret_cast<const char *>(&little16));
+ VERIFY(little24.data() == reinterpret_cast<const char *>(&little24));
+ VERIFY(little32.data() == reinterpret_cast<const char *>(&little32));
+ VERIFY(little40.data() == reinterpret_cast<const char *>(&little40));
+ VERIFY(little48.data() == reinterpret_cast<const char *>(&little48));
+ VERIFY(little56.data() == reinterpret_cast<const char *>(&little56));
+ VERIFY(little64.data() == reinterpret_cast<const char *>(&little64));
+
+ VERIFY(ulittle8.data() == reinterpret_cast<const char *>(&ulittle8));
+ VERIFY(ulittle16.data() == reinterpret_cast<const char *>(&ulittle16));
+ VERIFY(ulittle24.data() == reinterpret_cast<const char *>(&ulittle24));
+ VERIFY(ulittle32.data() == reinterpret_cast<const char *>(&ulittle32));
+ VERIFY(ulittle40.data() == reinterpret_cast<const char *>(&ulittle40));
+ VERIFY(ulittle48.data() == reinterpret_cast<const char *>(&ulittle48));
+ VERIFY(ulittle56.data() == reinterpret_cast<const char *>(&ulittle56));
+ VERIFY(ulittle64.data() == reinterpret_cast<const char *>(&ulittle64));
+
+ VERIFY(native8.data() == reinterpret_cast<const char *>(&native8));
+ VERIFY(native16.data() == reinterpret_cast<const char *>(&native16));
+ VERIFY(native24.data() == reinterpret_cast<const char *>(&native24));
+ VERIFY(native32.data() == reinterpret_cast<const char *>(&native32));
+ VERIFY(native40.data() == reinterpret_cast<const char *>(&native40));
+ VERIFY(native48.data() == reinterpret_cast<const char *>(&native48));
+ VERIFY(native56.data() == reinterpret_cast<const char *>(&native56));
+ VERIFY(native64.data() == reinterpret_cast<const char *>(&native64));
+
+ VERIFY(unative8.data() == reinterpret_cast<const char *>(&unative8));
+ VERIFY(unative16.data() == reinterpret_cast<const char *>(&unative16));
+ VERIFY(unative24.data() == reinterpret_cast<const char *>(&unative24));
+ VERIFY(unative32.data() == reinterpret_cast<const char *>(&unative32));
+ VERIFY(unative40.data() == reinterpret_cast<const char *>(&unative40));
+ VERIFY(unative48.data() == reinterpret_cast<const char *>(&unative48));
+ VERIFY(unative56.data() == reinterpret_cast<const char *>(&unative56));
+ VERIFY(unative64.data() == reinterpret_cast<const char *>(&unative64));
+
+ VERIFY(aligned_big16.data() == reinterpret_cast<const char *>(&aligned_big16));
+ VERIFY(aligned_big32.data() == reinterpret_cast<const char *>(&aligned_big32));
+ VERIFY(aligned_big64.data() == reinterpret_cast<const char *>(&aligned_big64));
+
+ VERIFY(aligned_ubig16.data() == reinterpret_cast<const char *>(&aligned_ubig16));
+ VERIFY(aligned_ubig32.data() == reinterpret_cast<const char *>(&aligned_ubig32));
+ VERIFY(aligned_ubig64.data() == reinterpret_cast<const char *>(&aligned_ubig64));
+
+ VERIFY(aligned_little16.data() == reinterpret_cast<const char *>(&aligned_little16));
+ VERIFY(aligned_little32.data() == reinterpret_cast<const char *>(&aligned_little32));
+ VERIFY(aligned_little64.data() == reinterpret_cast<const char *>(&aligned_little64));
+
+ VERIFY(aligned_ulittle16.data() == reinterpret_cast<const char *>(&aligned_ulittle16));
+ VERIFY(aligned_ulittle32.data() == reinterpret_cast<const char *>(&aligned_ulittle32));
+ VERIFY(aligned_ulittle64.data() == reinterpret_cast<const char *>(&aligned_ulittle64));
+
+ }
+
+ // check_size ------------------------------------------------------------//
+
+ void check_size()
+ {
+ VERIFY( numeric_limits<signed char>::digits == 7 );
+ VERIFY( numeric_limits<unsigned char>::digits == 8 );
+
+ VERIFY_SIZE( sizeof( big8_t ), 1 );
+ VERIFY_SIZE( sizeof( big16_t ), 2 );
+ VERIFY_SIZE( sizeof( big24_t ), 3 );
+ VERIFY_SIZE( sizeof( big32_t ), 4 );
+ VERIFY_SIZE( sizeof( big40_t ), 5 );
+ VERIFY_SIZE( sizeof( big48_t ), 6 );
+ VERIFY_SIZE( sizeof( big56_t ), 7 );
+ VERIFY_SIZE( sizeof( big64_t ), 8 );
+
+ VERIFY_SIZE( sizeof( ubig8_t ), 1 );
+ VERIFY_SIZE( sizeof( ubig16_t ), 2 );
+ VERIFY_SIZE( sizeof( ubig24_t ), 3 );
+ VERIFY_SIZE( sizeof( ubig32_t ), 4 );
+ VERIFY_SIZE( sizeof( ubig40_t ), 5 );
+ VERIFY_SIZE( sizeof( ubig48_t ), 6 );
+ VERIFY_SIZE( sizeof( ubig56_t ), 7 );
+ VERIFY_SIZE( sizeof( ubig64_t ), 8 );
+
+ VERIFY_SIZE( sizeof( little8_t ), 1 );
+ VERIFY_SIZE( sizeof( little16_t ), 2 );
+ VERIFY_SIZE( sizeof( little24_t ), 3 );
+ VERIFY_SIZE( sizeof( little32_t ), 4 );
+ VERIFY_SIZE( sizeof( little40_t ), 5 );
+ VERIFY_SIZE( sizeof( little48_t ), 6 );
+ VERIFY_SIZE( sizeof( little56_t ), 7 );
+ VERIFY_SIZE( sizeof( little64_t ), 8 );
+
+ VERIFY_SIZE( sizeof( ulittle8_t ), 1 );
+ VERIFY_SIZE( sizeof( ulittle16_t ), 2 );
+ VERIFY_SIZE( sizeof( ulittle24_t ), 3 );
+ VERIFY_SIZE( sizeof( ulittle32_t ), 4 );
+ VERIFY_SIZE( sizeof( ulittle40_t ), 5 );
+ VERIFY_SIZE( sizeof( ulittle48_t ), 6 );
+ VERIFY_SIZE( sizeof( ulittle56_t ), 7 );
+ VERIFY_SIZE( sizeof( ulittle64_t ), 8 );
+
+ VERIFY_SIZE( sizeof( native8_t ), 1 );
+ VERIFY_SIZE( sizeof( native16_t ), 2 );
+ VERIFY_SIZE( sizeof( native24_t ), 3 );
+ VERIFY_SIZE( sizeof( native32_t ), 4 );
+ VERIFY_SIZE( sizeof( native40_t ), 5 );
+ VERIFY_SIZE( sizeof( native48_t ), 6 );
+ VERIFY_SIZE( sizeof( native56_t ), 7 );
+ VERIFY_SIZE( sizeof( native64_t ), 8 );
+
+ VERIFY_SIZE( sizeof( unative8_t ), 1 );
+ VERIFY_SIZE( sizeof( unative16_t ), 2 );
+ VERIFY_SIZE( sizeof( unative24_t ), 3 );
+ VERIFY_SIZE( sizeof( unative32_t ), 4 );
+ VERIFY_SIZE( sizeof( unative40_t ), 5 );
+ VERIFY_SIZE( sizeof( unative48_t ), 6 );
+ VERIFY_SIZE( sizeof( unative56_t ), 7 );
+ VERIFY_SIZE( sizeof( unative64_t ), 8 );
+
+ VERIFY_SIZE( sizeof( aligned_big16_t ), 2 );
+ VERIFY_SIZE( sizeof( aligned_big32_t ), 4 );
+ VERIFY_SIZE( sizeof( aligned_big64_t ), 8 );
+
+ VERIFY_SIZE( sizeof( aligned_ubig16_t ), 2 );
+ VERIFY_SIZE( sizeof( aligned_ubig32_t ), 4 );
+ VERIFY_SIZE( sizeof( aligned_ubig64_t ), 8 );
+
+ VERIFY_SIZE( sizeof( aligned_little16_t ), 2 );
+ VERIFY_SIZE( sizeof( aligned_little32_t ), 4 );
+ VERIFY_SIZE( sizeof( aligned_little64_t ), 8 );
+
+ VERIFY_SIZE( sizeof( aligned_ulittle16_t ), 2 );
+ VERIFY_SIZE( sizeof( aligned_ulittle32_t ), 4 );
+ VERIFY_SIZE( sizeof( aligned_ulittle64_t ), 8 );
+ } // check_size
+
+ // check_alignment -------------------------------------------------------//
+
+ void check_alignment()
+ {
+ // structs with offsets % 2 == 1 for type of size > 1 to ensure no alignment
+ // bytes added for any size > 1
+
+ struct big_struct
+ {
+ big8_t v0;
+ big16_t v1;
+ big24_t v3;
+ char v6;
+ big32_t v7;
+ big40_t v11;
+ char v16;
+ big48_t v17;
+ big56_t v23;
+ char v30;
+ big64_t v31;
+ };
+
+ struct ubig_struct
+ {
+ ubig8_t v0;
+ ubig16_t v1;
+ ubig24_t v3;
+ char v6;
+ ubig32_t v7;
+ ubig40_t v11;
+ char v16;
+ ubig48_t v17;
+ ubig56_t v23;
+ char v30;
+ ubig64_t v31;
+ };
+
+ struct little_struct
+ {
+ little8_t v0;
+ little16_t v1;
+ little24_t v3;
+ char v6;
+ little32_t v7;
+ little40_t v11;
+ char v16;
+ little48_t v17;
+ little56_t v23;
+ char v30;
+ little64_t v31;
+ };
+
+ struct ulittle_struct
+ {
+ ulittle8_t v0;
+ ulittle16_t v1;
+ ulittle24_t v3;
+ char v6;
+ ulittle32_t v7;
+ ulittle40_t v11;
+ char v16;
+ ulittle48_t v17;
+ ulittle56_t v23;
+ char v30;
+ ulittle64_t v31;
+ };
+
+ struct native_struct
+ {
+ native8_t v0;
+ native16_t v1;
+ native24_t v3;
+ char v6;
+ native32_t v7;
+ native40_t v11;
+ char v16;
+ native48_t v17;
+ native56_t v23;
+ char v30;
+ native64_t v31;
+ };
+
+ struct unative_struct
+ {
+ unative8_t v0;
+ unative16_t v1;
+ unative24_t v3;
+ char v6;
+ unative32_t v7;
+ unative40_t v11;
+ char v16;
+ unative48_t v17;
+ unative56_t v23;
+ char v30;
+ unative64_t v31;
+ };
+
+ int saved_err_count = err_count;
+
+ VERIFY_SIZE( sizeof(big_struct), 39 );
+ VERIFY_SIZE( sizeof(ubig_struct), 39 );
+ VERIFY_SIZE( sizeof(little_struct), 39 );
+ VERIFY_SIZE( sizeof(ulittle_struct), 39 );
+ VERIFY_SIZE( sizeof(native_struct), 39 );
+ VERIFY_SIZE( sizeof(unative_struct), 39 );
+
+ if ( saved_err_count == err_count )
+ {
+ cout <<
+ "Size and alignment for structures of endian types are as expected.\n";
+ }
+ } // check_alignment
+
+ // check_representation_and_range_and_ops --------------------------------//
+
+ void check_representation_and_range_and_ops()
+ {
+
+ VERIFY_BIG_REPRESENTATION( big8_t );
+ VERIFY_VALUE_AND_OPS( big8_t, int_least8_t, 0x7f );
+ VERIFY_VALUE_AND_OPS( big8_t, int_least8_t, -0x80 );
+
+ VERIFY_BIG_REPRESENTATION( big16_t );
+ VERIFY_VALUE_AND_OPS( big16_t, int_least16_t, 0x7fff );
+ VERIFY_VALUE_AND_OPS( big16_t, int_least16_t, -0x8000 );
+
+ VERIFY_BIG_REPRESENTATION( big24_t );
+ VERIFY_VALUE_AND_OPS( big24_t, int_least32_t, 0x7fffff );
+ VERIFY_VALUE_AND_OPS( big24_t, int_least32_t, -0x800000 );
+
+ VERIFY_BIG_REPRESENTATION( big32_t );
+ VERIFY_VALUE_AND_OPS( big32_t, int_least32_t, 0x7fffffff );
+ VERIFY_VALUE_AND_OPS( big32_t, int_least32_t, -0x7fffffff-1 );
+
+ VERIFY_BIG_REPRESENTATION( big40_t );
+ VERIFY_VALUE_AND_OPS( big40_t, int_least64_t, 0x7fffffffffLL );
+ VERIFY_VALUE_AND_OPS( big40_t, int_least64_t, -0x8000000000LL );
+
+ VERIFY_BIG_REPRESENTATION( big48_t );
+ VERIFY_VALUE_AND_OPS( big48_t, int_least64_t, 0x7fffffffffffLL );
+ VERIFY_VALUE_AND_OPS( big48_t, int_least64_t, -0x800000000000LL );
+
+ VERIFY_BIG_REPRESENTATION( big56_t );
+ VERIFY_VALUE_AND_OPS( big56_t, int_least64_t, 0x7fffffffffffffLL );
+ VERIFY_VALUE_AND_OPS( big56_t, int_least64_t, -0x80000000000000LL );
+
+ VERIFY_BIG_REPRESENTATION( big64_t );
+ VERIFY_VALUE_AND_OPS( big64_t, int_least64_t, 0x7fffffffffffffffLL );
+ VERIFY_VALUE_AND_OPS( big64_t, int_least64_t, -0x7fffffffffffffffLL-1 );
+
+ VERIFY_BIG_REPRESENTATION( ubig8_t );
+ VERIFY_VALUE_AND_OPS( ubig8_t, uint_least8_t, 0xff );
+
+ VERIFY_BIG_REPRESENTATION( ubig16_t );
+ VERIFY_VALUE_AND_OPS( ubig16_t, uint_least16_t, 0xffff );
+
+ VERIFY_BIG_REPRESENTATION( ubig24_t );
+ VERIFY_VALUE_AND_OPS( ubig24_t, uint_least32_t, 0xffffff );
+
+ VERIFY_BIG_REPRESENTATION( ubig32_t );
+ VERIFY_VALUE_AND_OPS( ubig32_t, uint_least32_t, 0xffffffff );
+
+ VERIFY_BIG_REPRESENTATION( ubig40_t );
+ VERIFY_VALUE_AND_OPS( ubig40_t, uint_least64_t, 0xffffffffffLL );
+
+ VERIFY_BIG_REPRESENTATION( ubig48_t );
+ VERIFY_VALUE_AND_OPS( ubig48_t, uint_least64_t, 0xffffffffffffLL );
+
+ VERIFY_BIG_REPRESENTATION( ubig56_t );
+ VERIFY_VALUE_AND_OPS( ubig56_t, uint_least64_t, 0xffffffffffffffLL );
+
+ VERIFY_BIG_REPRESENTATION( ubig64_t );
+ VERIFY_VALUE_AND_OPS( ubig64_t, uint_least64_t, 0xffffffffffffffffLL );
+
+ VERIFY_LITTLE_REPRESENTATION( little8_t );
+ VERIFY_VALUE_AND_OPS( little8_t, int_least8_t, 0x7f );
+ VERIFY_VALUE_AND_OPS( little8_t, int_least8_t, -0x80 );
+
+ VERIFY_LITTLE_REPRESENTATION( little16_t );
+ VERIFY_VALUE_AND_OPS( little16_t, int_least16_t, 0x7fff );
+ VERIFY_VALUE_AND_OPS( little16_t, int_least16_t, -0x8000 );
+
+ VERIFY_LITTLE_REPRESENTATION( little24_t );
+ VERIFY_VALUE_AND_OPS( little24_t, int_least32_t, 0x7fffff );
+ VERIFY_VALUE_AND_OPS( little24_t, int_least32_t, -0x800000 );
+
+ VERIFY_LITTLE_REPRESENTATION( little32_t );
+ VERIFY_VALUE_AND_OPS( little32_t, int_least32_t, 0x7fffffff );
+ VERIFY_VALUE_AND_OPS( little32_t, int_least32_t, -0x7fffffff-1 );
+
+ VERIFY_LITTLE_REPRESENTATION( little40_t );
+ VERIFY_VALUE_AND_OPS( little40_t, int_least64_t, 0x7fffffffffLL );
+ VERIFY_VALUE_AND_OPS( little40_t, int_least64_t, -0x8000000000LL );
+
+ VERIFY_LITTLE_REPRESENTATION( little48_t );
+ VERIFY_VALUE_AND_OPS( little48_t, int_least64_t, 0x7fffffffffffLL );
+ VERIFY_VALUE_AND_OPS( little48_t, int_least64_t, -0x800000000000LL );
+
+ VERIFY_LITTLE_REPRESENTATION( little56_t );
+ VERIFY_VALUE_AND_OPS( little56_t, int_least64_t, 0x7fffffffffffffLL );
+ VERIFY_VALUE_AND_OPS( little56_t, int_least64_t, -0x80000000000000LL );
+
+ VERIFY_LITTLE_REPRESENTATION( little64_t );
+ VERIFY_VALUE_AND_OPS( little64_t, int_least64_t, 0x7fffffffffffffffLL );
+ VERIFY_VALUE_AND_OPS( little64_t, int_least64_t, -0x7fffffffffffffffLL-1 );
+
+ VERIFY_LITTLE_REPRESENTATION( ulittle8_t );
+ VERIFY_VALUE_AND_OPS( ulittle8_t, uint_least8_t, 0xff );
+
+ VERIFY_LITTLE_REPRESENTATION( ulittle16_t );
+ VERIFY_VALUE_AND_OPS( ulittle16_t, uint_least16_t, 0xffff );
+
+ VERIFY_LITTLE_REPRESENTATION( ulittle24_t );
+ VERIFY_VALUE_AND_OPS( ulittle24_t, uint_least32_t, 0xffffff );
+
+ VERIFY_LITTLE_REPRESENTATION( ulittle32_t );
+ VERIFY_VALUE_AND_OPS( ulittle32_t, uint_least32_t, 0xffffffff );
+
+ VERIFY_LITTLE_REPRESENTATION( ulittle40_t );
+ VERIFY_VALUE_AND_OPS( ulittle40_t, uint_least64_t, 0xffffffffffLL );
+
+ VERIFY_LITTLE_REPRESENTATION( ulittle48_t );
+ VERIFY_VALUE_AND_OPS( ulittle48_t, uint_least64_t, 0xffffffffffffLL );
+
+ VERIFY_LITTLE_REPRESENTATION( ulittle56_t );
+ VERIFY_VALUE_AND_OPS( ulittle56_t, uint_least64_t, 0xffffffffffffffLL );
+
+ VERIFY_LITTLE_REPRESENTATION( ulittle64_t );
+ VERIFY_VALUE_AND_OPS( ulittle64_t, uint_least64_t, 0xffffffffffffffffLL );
+
+ VERIFY_NATIVE_REPRESENTATION( native8_t );
+ VERIFY_VALUE_AND_OPS( native8_t, int_least8_t, 0x7f );
+ VERIFY_VALUE_AND_OPS( native8_t, int_least8_t, -0x80 );
+
+ VERIFY_NATIVE_REPRESENTATION( native16_t );
+ VERIFY_VALUE_AND_OPS( native16_t, int_least16_t, 0x7fff );
+ VERIFY_VALUE_AND_OPS( native16_t, int_least16_t, -0x8000 );
+
+ VERIFY_NATIVE_REPRESENTATION( native24_t );
+ VERIFY_VALUE_AND_OPS( native24_t, int_least32_t, 0x7fffff );
+ VERIFY_VALUE_AND_OPS( native24_t, int_least32_t, -0x800000 );
+
+ VERIFY_NATIVE_REPRESENTATION( native32_t );
+ VERIFY_VALUE_AND_OPS( native32_t, int_least32_t, 0x7fffffff );
+ VERIFY_VALUE_AND_OPS( native32_t, int_least32_t, -0x7fffffff-1 );
+
+ VERIFY_NATIVE_REPRESENTATION( native40_t );
+ VERIFY_VALUE_AND_OPS( native40_t, int_least64_t, 0x7fffffffffLL );
+ VERIFY_VALUE_AND_OPS( native40_t, int_least64_t, -0x8000000000LL );
+
+ VERIFY_NATIVE_REPRESENTATION( native48_t );
+ VERIFY_VALUE_AND_OPS( native48_t, int_least64_t, 0x7fffffffffffLL );
+ VERIFY_VALUE_AND_OPS( native48_t, int_least64_t, -0x800000000000LL );
+
+ VERIFY_NATIVE_REPRESENTATION( native56_t );
+ VERIFY_VALUE_AND_OPS( native56_t, int_least64_t, 0x7fffffffffffffLL );
+ VERIFY_VALUE_AND_OPS( native56_t, int_least64_t, -0x80000000000000LL );
+
+ VERIFY_NATIVE_REPRESENTATION( native64_t );
+ VERIFY_VALUE_AND_OPS( native64_t, int_least64_t, 0x7fffffffffffffffLL );
+ VERIFY_VALUE_AND_OPS( native64_t, int_least64_t, -0x7fffffffffffffffLL-1 );
+
+ VERIFY_NATIVE_REPRESENTATION( unative8_t );
+ VERIFY_VALUE_AND_OPS( unative8_t, uint_least8_t, 0xff );
+
+ VERIFY_NATIVE_REPRESENTATION( unative16_t );
+ VERIFY_VALUE_AND_OPS( unative16_t, uint_least16_t, 0xffff );
+
+ VERIFY_NATIVE_REPRESENTATION( unative24_t );
+ VERIFY_VALUE_AND_OPS( unative24_t, uint_least32_t, 0xffffff );
+
+ VERIFY_NATIVE_REPRESENTATION( unative32_t );
+ VERIFY_VALUE_AND_OPS( unative32_t, uint_least32_t, 0xffffffff );
+
+ VERIFY_NATIVE_REPRESENTATION( unative40_t );
+ VERIFY_VALUE_AND_OPS( unative40_t, uint_least64_t, 0xffffffffffLL );
+
+ VERIFY_NATIVE_REPRESENTATION( unative48_t );
+ VERIFY_VALUE_AND_OPS( unative48_t, uint_least64_t, 0xffffffffffffLL );
+
+ VERIFY_NATIVE_REPRESENTATION( unative56_t );
+ VERIFY_VALUE_AND_OPS( unative56_t, uint_least64_t, 0xffffffffffffffLL );
+
+ VERIFY_NATIVE_REPRESENTATION( unative64_t );
+ VERIFY_VALUE_AND_OPS( unative64_t, uint_least64_t, 0xffffffffffffffffLL );
+
+ VERIFY_BIG_REPRESENTATION( aligned_big16_t );
+ VERIFY_VALUE_AND_OPS( aligned_big16_t, int_least16_t, 0x7fff );
+ VERIFY_VALUE_AND_OPS( aligned_big16_t, int_least16_t, -0x8000 );
+
+ VERIFY_BIG_REPRESENTATION( aligned_big32_t );
+ VERIFY_VALUE_AND_OPS( aligned_big32_t, int_least32_t, 0x7fffffff );
+ VERIFY_VALUE_AND_OPS( aligned_big32_t, int_least32_t, -0x7fffffff-1 );
+
+ VERIFY_BIG_REPRESENTATION( aligned_big64_t );
+ VERIFY_VALUE_AND_OPS( aligned_big64_t, int_least64_t, 0x7fffffffffffffffLL );
+ VERIFY_VALUE_AND_OPS( aligned_big64_t, int_least64_t, -0x7fffffffffffffffLL-1 );
+
+ VERIFY_BIG_REPRESENTATION( aligned_ubig16_t );
+ VERIFY_VALUE_AND_OPS( aligned_ubig16_t, uint_least16_t, 0xffff );
+
+ VERIFY_BIG_REPRESENTATION( aligned_ubig32_t );
+ VERIFY_VALUE_AND_OPS( aligned_ubig32_t, uint_least32_t, 0xffffffff );
+
+ VERIFY_BIG_REPRESENTATION( aligned_ubig64_t );
+ VERIFY_VALUE_AND_OPS( aligned_ubig64_t, uint_least64_t, 0xffffffffffffffffLL );
+
+ VERIFY_LITTLE_REPRESENTATION( aligned_little16_t );
+ VERIFY_VALUE_AND_OPS( aligned_little16_t, int_least16_t, 0x7fff );
+ VERIFY_VALUE_AND_OPS( aligned_little16_t, int_least16_t, -0x8000 );
+
+ VERIFY_LITTLE_REPRESENTATION( aligned_little32_t );
+ VERIFY_VALUE_AND_OPS( aligned_little32_t, int_least32_t, 0x7fffffff );
+ VERIFY_VALUE_AND_OPS( aligned_little32_t, int_least32_t, -0x7fffffff-1 );
+
+ VERIFY_LITTLE_REPRESENTATION( aligned_little64_t );
+ VERIFY_VALUE_AND_OPS( aligned_little64_t, int_least64_t, 0x7fffffffffffffffLL );
+ VERIFY_VALUE_AND_OPS( aligned_little64_t, int_least64_t, -0x7fffffffffffffffLL-1 );
+
+ VERIFY_LITTLE_REPRESENTATION( aligned_ulittle16_t );
+ VERIFY_VALUE_AND_OPS( aligned_ulittle16_t, uint_least16_t, 0xffff );
+
+ VERIFY_LITTLE_REPRESENTATION( aligned_ulittle32_t );
+ VERIFY_VALUE_AND_OPS( aligned_ulittle32_t, uint_least32_t, 0xffffffff );
+
+ VERIFY_LITTLE_REPRESENTATION( aligned_ulittle64_t );
+ VERIFY_VALUE_AND_OPS( aligned_ulittle64_t, uint_least64_t, 0xffffffffffffffffLL );
+
+ } // check_representation_and_range
+
+ long iterations = 10000000;
+
+ template< class Endian >
+ Endian timing_test( const char * s)
+ {
+ cout << s << " timing test, " << iterations << " iterations: ";
+ progress_timer t;
+
+ Endian v = 1;
+ for ( long i = 0; i < iterations; ++i )
+ {
+ v += 1;
+ v *= 3;
+ ++v;
+ v *= i;
+ if ( i == 0 ) VERIFY_VALUE_AND_OPS( Endian, typename Endian::value_type, 21 );
+ }
+ return v;
+ }
+
+} // unnamed namespace
+
+// main ------------------------------------------------------------------------------//
+
+int main( int argc, char * argv[] )
+{
+ cout << "Usage: "
+ << argv[0] << " [#],\n where # specifies iteration count\n"
+ " default iteration count is 1000000" << endl;
+
+ if ( argc > 1 )
+ iterations = atol( argv[1] );
+ if ( iterations < 1 ) iterations = 1;
+
+ detect_endianness();
+ check_size();
+ check_alignment();
+ check_representation_and_range_and_ops();
+ check_data();
+
+ //timing_test<big32_t> ( "big32_t" );
+ //timing_test<aligned_big32_t>( "aligned_big32_t" );
+ //timing_test<little32_t> ( "little32_t" );
+ //timing_test<aligned_little32_t>( "aligned_little32_t" );
+
+ cout << "\n" << err_count << " errors detected\nTest "
+ << (err_count==0 ? "passed\n\n" : "failed\n\n");
+
+ return err_count ? 1 : 0;
+} // main
Added: sandbox/endian_ext/libs/integer/endian/test/endian_type_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/test/endian_type_test.cpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,146 @@
+// endian_type_test.cpp ---------------------------------------------------------//
+
+// (C) Copyright VicenteJ Botet Escriba 2010-2011
+
+// 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/integer/endian
+
+//----------------------------------------------------------------------------//
+
+// This test probes for correct endianess, size, and value.
+
+// See endian_operations_test for tests of operator correctness and interaction
+// between operand types.
+
+//----------------------------------------------------------------------------//
+
+#include <boost/detail/lightweight_test.hpp> // for main
+
+#include <iostream>
+#include <boost/type_traits/remove_cv.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+#include <boost/integer/endian/endian_type.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/fusion/adapted/struct/adapt_struct.hpp>
+
+using namespace std; // Not the best programming practice, but I
+using namespace boost; // want to verify this combination of using
+using namespace boost::integer; // namespaces works. See endian_operations_test
+// // for tests that don't do "using namespace".
+
+namespace X {
+
+struct big_c {
+ ubig32_t a;
+ ubig16_t b;
+};
+
+
+struct little_c {
+ ulittle32_t a;
+ ulittle16_t b;
+};
+
+
+struct mixed_c {
+ big_c a;
+ little_c b;
+};
+
+
+}
+
+BOOST_FUSION_ADAPT_STRUCT(
+ X::big_c,
+ (ubig32_t, a)
+ (ubig16_t, a)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ X::little_c,
+ (ulittle32_t, a)
+ (ulittle16_t, a)
+)
+
+
+BOOST_FUSION_ADAPT_STRUCT(
+ X::mixed_c,
+ (X::big_c, a)
+ (X::little_c, a)
+)
+
+
+namespace
+{
+void check_endian_type()
+{
+
+ // fundamental types
+ //~ BOOST_TEST((endian_type<int>::value == endianness::native));
+ BOOST_TEST((is_native<int>::value));
+
+ // endian types
+ //~ BOOST_TEST((endian_type<endian_pack<endianness::little,short> >::value == endianness::little));
+ BOOST_TEST((is_little<endian_pack<little_endian,short> >::value));
+ //~ BOOST_TEST((endian_type<endian<endianness::big,int> >::value== endianness::big));
+ BOOST_TEST((is_big<integer::endian<big_endian,int> >::value));
+
+ // array of endian types
+ //~ BOOST_TEST((endian_type<endian_pack<endianness::little,short>[2] >::value == endianness::little));
+ BOOST_TEST((is_little<endian_pack<little_endian,short>[2] >::value));
+ //~ BOOST_TEST((endian_type<endian<endianness::big,int>[3] >::value== endianness::big));
+ BOOST_TEST((is_big<integer::endian<big_endian,int>[3] >::value));
+
+
+ //~ typedef remove_reference<remove_cv<fusion::result_of::front<X::big_c>::type>::type>::type front_type;
+ //~ typedef remove_reference<
+ //~ remove_cv<
+ //~ fusion::result_of::deref<
+ //~ fusion::result_of::begin<X::big_c>::type
+ //~ >::type
+ //~ >::type
+ //~ >::type deref_type;
+ //~ // typedef typename fusion::result_of::deref<It>::type deref_it_type;
+
+
+ //~ BOOST_MPL_ASSERT_MSG((is_same<front_type, ubig32_t>::value), FAIL, (front_type, ubig32_t) );
+ //~ BOOST_MPL_ASSERT_MSG((is_same<deref_type, ubig32_t>::value), FAIL, (deref_type, ubig32_t) );
+
+ //~ typedef fusion::result_of::begin<X::big_c>::type It;
+ //~ typedef fusion::result_of::end<X::big_c>::type End;
+ //~ typedef fusion::result_of::deref<It>::type deref_it_type;
+ //~ typedef remove_reference<
+ //~ remove_cv<deref_it_type>::type
+ //~ >::type it_type;
+ //~ static const BOOST_SCOPED_ENUM(endianness) it_value = endian_type< it_type >::value;
+ //~ typedef mpl::if_c<it_value==endianness::big,
+ //~ mpl::int_<integer_detail::endian_type_loop<endianness::big,fusion::result_of::next<It>::type, End>::value>,
+ //~ mpl::int_<endianness::mixed>
+ //~ >::type res_type;
+ //~ BOOST_MPL_ASSERT_MSG((res_type::value==endianness::big), FAIL, (res_type, it_type, deref_it_type, It) );
+
+
+ //~ static const BOOST_SCOPED_ENUM(endianness) front_value=
+ //~ endian_type< front_type >::value;
+
+ //~ std::cout << "front=" << endian_type<X::big_c>::value << std::endl;
+ //~ std::cout << "ubig32_t=" << endian_type<ubig32_t>::value << std::endl;
+ //~ // struct of bigs of endian types
+ //~ std::cout << "X::big_c=" << endian_type<X::big_c>::value << std::endl;
+ //~ BOOST_TEST((endian_type<X::big_c>::value == endianness::big));
+ BOOST_TEST((is_big<X::big_c>::value));
+ //~ BOOST_TEST((endian_type<X::little_c>::value == endianness::little));
+ BOOST_TEST((is_little<X::little_c>::value));
+ //~ BOOST_TEST((endian_type<X::mixed_c>::value == endianness::mixed));
+ BOOST_TEST((is_mixed<X::mixed_c>::value));
+
+}
+} // unnamed namespace
+
+int main( )
+{
+ check_endian_type();
+ return boost::report_errors();
+} // main
Added: sandbox/endian_ext/libs/integer/endian/test/endian_view_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/test/endian_view_test.cpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,193 @@
+// endian_view_test.cpp ---------------------------------------------------------//
+
+// Copyright Beman Dawes 1999-2008
+// (C) Copyright VicenteJ Botet Escriba 2010-2011
+
+// 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/integer/endian
+
+//----------------------------------------------------------------------------//
+
+// This test probes for correct endianess, size, and value.
+
+// See endian_operations_test for tests of operator correctness and interaction
+// between operand types.
+
+//----------------------------------------------------------------------------//
+#include <iostream>
+
+#include <boost/detail/lightweight_test.hpp> // for main
+
+#include <boost/integer/endian/endian_view.hpp>
+#include <boost/fusion/adapted/struct/adapt_struct.hpp>
+//~ #include <boost/cstdint.hpp>
+//~ #include <boost/progress.hpp>
+
+//~ #include <iostream>
+//~ #include <limits>
+//~ #include <climits>
+//~ #include <cstdlib> // for atoi(), exit()
+//~ #include <cstring> // for memcmp()
+
+using namespace std; // Not the best programming practice, but I
+using namespace boost; // want to verify this combination of using
+using namespace boost::integer; // namespaces works. See endian_operations_test
+// // for tests that don't do "using namespace".
+
+namespace X {
+
+struct big_c {
+ uint32_t a;
+ uint16_t b;
+};
+
+
+struct little_c {
+ int32_t a;
+ int16_t b;
+};
+
+struct mixed_c {
+ big_c a;
+ little_c b;
+};
+
+}
+
+struct network {};
+
+namespace boost {
+namespace integer {
+namespace endianness {
+
+ template <>
+ struct domain_map <network, X::big_c> {
+ typedef mpl::vector<big,big> type;
+ };
+ template <>
+ struct domain_map <network, X::little_c> {
+ typedef mpl::vector<little,little> type;
+ };
+
+}
+}
+}
+
+BOOST_FUSION_ADAPT_STRUCT(
+ X::big_c,
+ (uint32_t, a)
+ (uint16_t, b)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ X::little_c,
+ (int32_t, a)
+ (int16_t, b)
+)
+
+
+BOOST_FUSION_ADAPT_STRUCT(
+ X::mixed_c,
+ (X::big_c, a)
+ (X::little_c, b)
+)
+
+namespace
+{
+ X::mixed_c m;
+
+void check_access()
+{
+ // structs with offsets % 2 == 1 for type of size > 1 to ensure no alignment
+ // bytes added for any size > 1
+
+ struct a_struct
+ {
+ char c1;
+ short s1;
+ int i1;
+ char c2;
+ short s2;
+ int i2;
+ };
+
+ a_struct a;
+ as_big(a.c1)=0x0A;
+ as_endian<big_endian>(a.s1)=0x0102;
+ as_big(a.i1)=0x01020304;
+
+
+ as_little(a.c2)=0x0A;
+ as_little(a.s2)=0x0102;
+ as_little(a.i2)=0x01020304;
+
+ std::cout << std::hex << int(a.c1) << std::endl;
+ std::cout << std::hex << a.s1 << std::endl;
+ std::cout << std::hex << a.i1 << std::endl;
+ std::cout << std::hex << int(a.c2) << std::endl;
+ std::cout << std::hex << a.s2 << std::endl;
+ std::cout << std::hex << a.i2 << std::endl;
+
+ a.c1=as_big(a.c1);
+ a.s1=as_big(a.s1);
+ a.i1=as_big(a.i1);
+
+ a.c2=as_little(a.c2);
+ a.s2=as_little(a.s2);
+ a.i2=as_little(a.i2);
+
+ BOOST_TEST(a.c1 == 0x0A);
+ BOOST_TEST(a.s1 == 0x0102);
+ BOOST_TEST(a.i1 == 0x01020304);
+
+ BOOST_TEST(a.c2 == 0x0A);
+ BOOST_TEST(a.s2 == 0x0102);
+ BOOST_TEST(a.i2 == 0x01020304);
+
+ as_big(a.c1)=as_little(a.c1);
+ as_big(a.s1)=as_little(a.s1);
+ as_big(a.i1)=as_little(a.i1);
+
+ std::cout << std::hex << int(a.c1) << std::endl;
+ std::cout << std::hex << a.s1 << std::endl;
+ std::cout << std::hex << a.i1 << std::endl;
+
+ std::cout << "**********" << std::endl;
+ std::cout << std::hex << m.a.a << std::endl;
+ std::cout << std::hex << m.a.b << std::endl;
+ std::cout << std::hex << m.b.a << std::endl;
+ std::cout << std::hex << m.b.b << std::endl;
+
+ as_endian<network>(a.i1)=as_endian<network>(a.i1);
+ std::cout << "**********" << std::endl;
+ std::cout << std::hex << m.a.a << std::endl;
+ std::cout << std::hex << m.a.b << std::endl;
+ std::cout << std::hex << m.b.a << std::endl;
+ std::cout << std::hex << m.b.b << std::endl;
+
+ //~ as_big(m)=as_big(m);
+
+ as(m)=as_endian<network>(m);
+ std::cout << "**********" << std::endl;
+ std::cout << std::hex << m.a.a << std::endl;
+ std::cout << std::hex << m.a.b << std::endl;
+ std::cout << std::hex << m.b.a << std::endl;
+ std::cout << std::hex << m.b.b << std::endl;
+
+ //~ as(m)=as_big(m);
+}
+} // unnamed namespace
+
+int main( )
+{
+ m.b.a=0x01020304;
+ m.b.b=0x0A0B;
+ m.a.a=0x04030201;
+ m.a.b=0x0B0A;
+
+ check_access();
+ return boost::report_errors();
+ //~ return 1;
+} // main
Added: sandbox/endian_ext/libs/integer/endian/test/scoped_enum_emulation_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/endian/test/scoped_enum_emulation_test.cpp 2011-02-13 08:17:30 EST (Sun, 13 Feb 2011)
@@ -0,0 +1,42 @@
+// scoped_enum_emulation_test.cpp ----------------------------------------------------//
+
+// Copyright Beman Dawes, 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/integer/endian
+
+#include <boost/detail/scoped_enum_emulation.hpp>
+#include <boost/assert.hpp>
+
+BOOST_SCOPED_ENUM_START(traffic_light) { red=0, yellow, green }; BOOST_SCOPED_ENUM_END
+
+BOOST_SCOPED_ENUM_START(algae) { green=0, red, cyan }; BOOST_SCOPED_ENUM_END
+
+struct color
+{
+ BOOST_SCOPED_ENUM_START(value_t) { red, green, blue }; BOOST_SCOPED_ENUM_END
+ BOOST_SCOPED_ENUM(value_t) value;
+};
+
+void foo( BOOST_SCOPED_ENUM(algae) arg )
+{
+ BOOST_ASSERT( arg == algae::cyan );
+}
+
+int main()
+{
+ BOOST_SCOPED_ENUM(traffic_light) signal( traffic_light::red );
+ BOOST_SCOPED_ENUM(algae) sample( algae::red );
+
+ BOOST_ASSERT( signal == traffic_light::red );
+ BOOST_ASSERT( sample == algae::red );
+
+ foo( algae::cyan );
+
+ color tracker;
+ tracker.value = color::value_t::blue;
+
+ return 0;
+}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk