Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62772 - in sandbox/endian_ext: . boost boost/endian boost/integer libs libs/endian libs/endian/doc libs/endian/test libs/integer libs/integer/doc libs/integer/example libs/integer/test
From: vicente.botet_at_[hidden]
Date: 2010-06-10 17:53:51


Author: viboes
Date: 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
New Revision: 62772
URL: http://svn.boost.org/trac/boost/changeset/62772

Log:
First commit for Boost.Integer.Endian.Ext.
 

Added:
   sandbox/endian_ext/
   sandbox/endian_ext/boost/
   sandbox/endian_ext/boost/binary_stream.hpp (contents, props changed)
   sandbox/endian_ext/boost/endian/
   sandbox/endian_ext/boost/endian/domain_map.hpp (contents, props changed)
   sandbox/endian_ext/boost/endian/endian.hpp (contents, props changed)
   sandbox/endian_ext/boost/endian/native_tree.hpp (contents, props changed)
   sandbox/endian_ext/boost/integer/
   sandbox/endian_ext/boost/integer/cover_operators.hpp (contents, props changed)
   sandbox/endian_ext/boost/integer/endian.hpp (contents, props changed)
   sandbox/endian_ext/boost/integer/endian_binary_stream.hpp (contents, props changed)
   sandbox/endian_ext/boost/integer/endian_conversion.hpp (contents, props changed)
   sandbox/endian_ext/boost/integer/endian_pack.hpp (contents, props changed)
   sandbox/endian_ext/boost/integer/endian_type.hpp (contents, props changed)
   sandbox/endian_ext/boost/integer/endian_view.hpp (contents, props changed)
   sandbox/endian_ext/libs/
   sandbox/endian_ext/libs/endian/
   sandbox/endian_ext/libs/endian/doc/
   sandbox/endian_ext/libs/endian/test/
   sandbox/endian_ext/libs/integer/
   sandbox/endian_ext/libs/integer/doc/
   sandbox/endian_ext/libs/integer/doc/Jamfile.v2 (contents, props changed)
   sandbox/endian_ext/libs/integer/doc/integer_endian.qbk (contents, props changed)
   sandbox/endian_ext/libs/integer/example/
   sandbox/endian_ext/libs/integer/example/endian_example.cpp (contents, props changed)
   sandbox/endian_ext/libs/integer/example/endian_hello_world.cpp (contents, props changed)
   sandbox/endian_ext/libs/integer/test/
   sandbox/endian_ext/libs/integer/test/Jamfile.v2 (contents, props changed)
   sandbox/endian_ext/libs/integer/test/binary_stream_test.cpp (contents, props changed)
   sandbox/endian_ext/libs/integer/test/endian_binary_stream_test.cpp (contents, props changed)
   sandbox/endian_ext/libs/integer/test/endian_convert_test.cpp (contents, props changed)
   sandbox/endian_ext/libs/integer/test/endian_in_union_test.cpp (contents, props changed)
   sandbox/endian_ext/libs/integer/test/endian_operations_test.cpp (contents, props changed)
   sandbox/endian_ext/libs/integer/test/endian_pack_test.cpp (contents, props changed)
   sandbox/endian_ext/libs/integer/test/endian_test.cpp (contents, props changed)
   sandbox/endian_ext/libs/integer/test/endian_type_test.cpp (contents, props changed)
   sandbox/endian_ext/libs/integer/test/endian_view_test.cpp (contents, props changed)
   sandbox/endian_ext/libs/integer/test/scoped_enum_emulation_test.cpp (contents, props changed)

Added: sandbox/endian_ext/boost/binary_stream.hpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/boost/binary_stream.hpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,155 @@
+// boost/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 documentation at http://www.boost.org/libs/utility
+
+#ifndef BOOST_BINARY_STREAM_HPP
+#define BOOST_BINARY_STREAM_HPP
+
+#include <boost/config.hpp>
+#include <ostream>
+#include <istream>
+#include <string>
+#include <cstring> // for strlen
+
+#ifndef BOOST_NO_CWCHAR
+# include <cwchar> // for wcslen
+#endif
+
+// unformatted binary (as opposed to formatted character-set) input and output
+
+// Caution: 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
+{
+
+ // built-in types ------------------------------------------------------------------//
+
+ // omission of bool and void* is deliberate; any semantics would be questionable
+
+ inline std::ostream& operator<=(std::ostream& os, short v)
+ { return os.write( reinterpret_cast<const char*>(&v), sizeof(v) ); }
+ inline std::istream& operator>=(std::istream& is, short& v)
+ { return is.read( reinterpret_cast<char*>(&v), sizeof(v) ); }
+
+ inline std::ostream& operator<=(std::ostream& os, unsigned short v)
+ { return os.write( reinterpret_cast<const char*>(&v), sizeof(v) ); }
+ inline std::istream& operator>=(std::istream& is, unsigned short& v)
+ { return is.read( reinterpret_cast<char*>(&v), sizeof(v) ); }
+
+ inline std::ostream& operator<=(std::ostream& os, int v)
+ { return os.write( reinterpret_cast<const char*>(&v), sizeof(v) ); }
+ inline std::istream& operator>=(std::istream& is, int& v)
+ { return is.read( reinterpret_cast<char*>(&v), sizeof(v) ); }
+
+ inline std::ostream& operator<=(std::ostream& os, unsigned int v)
+ { return os.write( reinterpret_cast<const char*>(&v), sizeof(v) ); }
+ inline std::istream& operator>=(std::istream& is, unsigned int& v)
+ { return is.read( reinterpret_cast<char*>(&v), sizeof(v) ); }
+
+ inline std::ostream& operator<=(std::ostream& os, long v)
+ { return os.write( reinterpret_cast<const char*>(&v), sizeof(v) ); }
+ inline std::istream& operator>=(std::istream& is, long& v)
+ { return is.read( reinterpret_cast<char*>(&v), sizeof(v) ); }
+
+ inline std::ostream& operator<=(std::ostream& os, unsigned long v)
+ { return os.write( reinterpret_cast<const char*>(&v), sizeof(v) ); }
+ inline std::istream& operator>=(std::istream& is, unsigned long& v)
+ { return is.read( reinterpret_cast<char*>(&v), sizeof(v) ); }
+
+ inline std::ostream& operator<=(std::ostream& os, long long v)
+ { return os.write( reinterpret_cast<const char*>(&v), sizeof(v) ); }
+ inline std::istream& operator>=(std::istream& is, long long& v)
+ { return is.read( reinterpret_cast<char*>(&v), sizeof(v) ); }
+
+ inline std::ostream& operator<=(std::ostream& os, unsigned long long v)
+ { return os.write( reinterpret_cast<const char*>(&v), sizeof(v) ); }
+ inline std::istream& operator>=(std::istream& is, unsigned long long& v)
+ { return is.read( reinterpret_cast<char*>(&v), sizeof(v) ); }
+
+ inline std::ostream& operator<=(std::ostream& os, float v)
+ { return os.write( reinterpret_cast<const char*>(&v), sizeof(v) ); }
+ inline std::istream& operator>=(std::istream& is, float& v)
+ { return is.read( reinterpret_cast<char*>(&v), sizeof(v) ); }
+
+ inline std::ostream& operator<=(std::ostream& os, double v)
+ { return os.write( reinterpret_cast<const char*>(&v), sizeof(v) ); }
+ inline std::istream& operator>=(std::istream& is, double& v)
+ { return is.read( reinterpret_cast<char*>(&v), sizeof(v) ); }
+
+ inline std::ostream& operator<=(std::ostream& os, long double v)
+ { return os.write( reinterpret_cast<const char*>(&v), sizeof(v) ); }
+ inline std::istream& operator>=(std::istream& is, long double& v)
+ { return is.read( reinterpret_cast<char*>(&v), sizeof(v) ); }
+
+ inline std::ostream& operator<=(std::ostream& os, char c)
+ { return os.put( c ); }
+ inline std::istream& operator>=(std::istream& is, char& c)
+ { return is.get( c ); }
+
+ inline std::ostream& operator<=(std::ostream& os, signed char c)
+ { return os.put( c ); }
+ inline std::istream& operator>=(std::istream& is, signed char& c)
+ { return is.get( reinterpret_cast<char&>(c) ); }
+
+ inline std::ostream& operator<=(std::ostream& os, unsigned char c)
+ { return os.put( c ); }
+ inline std::istream& operator>=(std::istream& is, unsigned char& c)
+ { return is.get( reinterpret_cast<char&>(c) ); }
+
+ inline std::ostream& operator<=(std::ostream& os, wchar_t v)
+ { return os.write( reinterpret_cast<const char*>(&v), sizeof(v) ); }
+ inline std::istream& operator>=(std::istream& is, wchar_t& v)
+ { return is.read( reinterpret_cast<char*>(&v), sizeof(v) ); }
+
+ // strings -------------------------------------------------------------------------//
+
+ inline std::ostream& operator<=(std::ostream& os, const char* p)
+ { return os.write( p, std::strlen(p)+1 ); }
+
+ inline std::ostream& operator<=(std::ostream& os, const signed char* p)
+ { return os.write( reinterpret_cast<const char*>(p), std::strlen(reinterpret_cast<const char*>(p))+1 ); }
+
+ inline std::ostream& operator<=(std::ostream& os, const unsigned char* p)
+ { return os.write( reinterpret_cast<const char*>(p), std::strlen(reinterpret_cast<const char*>(p))+1 ); }
+
+#ifndef BOOST_NO_CWCHAR
+ inline std::ostream& operator<=(std::ostream& os, const wchar_t* p)
+ { return os.write( reinterpret_cast<const char*>(p), (std::wcslen(p)+1)*sizeof(wchar_t) ); }
+#endif
+
+ // Caution: 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.
+ inline std::ostream& operator<=(std::ostream& os, const std::string& s)
+ { return os.write( s.c_str(), s.size()+1 ); }
+ inline std::istream& operator>=(std::istream& is, std::string& s)
+ { return getline(is, s, '\0'); }
+
+#ifndef BOOST_NO_STD_WSTRING
+ inline std::ostream& operator<=(std::ostream& os, const std::wstring& s)
+ { return os.write( reinterpret_cast<const char*>(s.c_str()), (s.size()+1)*sizeof(wchar_t) ); }
+ // TODO: provide input function
+#endif
+
+} // namespace boost
+
+#endif // BOOST_BINARY_STREAM_HPP

Added: sandbox/endian_ext/boost/endian/domain_map.hpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/boost/endian/domain_map.hpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,102 @@
+// 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_DOMAIN_MAP__HPP
+#define BOOST_ENDIAN_DOMAIN_MAP__HPP
+
+#include <boost/endian/endian.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>
+
+namespace boost {
+
+
+namespace endian {
+
+ 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 native 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 endian
+
+} // namespace boost
+
+
+#endif // BOOST_ENDIAN_DOMAIN_MAP__HPP

Added: sandbox/endian_ext/boost/endian/endian.hpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/boost/endian/endian.hpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,52 @@
+// 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_ENDIAN__HPP
+#define BOOST_ENDIAN_ENDIAN__HPP
+
+//~ #include <boost/config.hpp>
+#include <boost/detail/endian.hpp>
+#include <boost/detail/scoped_enum_emulation.hpp>
+
+namespace boost {
+
+# 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
+
+namespace endian {
+ 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
+
+}
+
+} // namespace boost
+
+
+#endif // BOOST_ENDIAN_ENDIAN__HPP

Added: sandbox/endian_ext/boost/endian/native_tree.hpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/boost/endian/native_tree.hpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,103 @@
+// 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_NATIVE_TREE__HPP
+#define BOOST_ENDIAN_NATIVE_TREE__HPP
+
+#include <boost/endian/endian.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>
+
+namespace boost {
+
+
+namespace endian {
+
+ namespace endian_detail {
+
+ template <typename T,
+ bool isFundamental = is_fundamental<T>::value,
+ bool IsSeq = fusion::traits::is_sequence<T>::value
+ >
+ struct native_tree_impl;
+
+ }
+
+ /// By default the shared endianess of a type depends on whether it is fundamental and or a fusion sequence.
+ template <typename T>
+ struct native_tree : endian_detail::native_tree_impl<T> {};
+
+ namespace endian_detail {
+
+ // fundamental types are native
+ template <typename T, bool IsSeq>
+ struct native_tree_impl<T, true, IsSeq> {
+ typedef native type;
+ };
+
+ // other type which has not been explicitly declared is undefined,
+ template <typename T>
+ struct native_tree_impl<T, false, false> {};
+
+ template <typename SharedTree, typename It, typename End>
+ struct native_tree_loop {
+ private:
+ typedef
+ typename remove_reference<
+ typename remove_cv<
+ typename fusion::result_of::deref<It>::type
+ >::type
+ >::type it_type;
+ public:
+ typedef typename native_tree_loop<
+ typename mpl::push_back<SharedTree, typename native_tree<it_type>::type>::type,
+ typename fusion::result_of::next<It>::type,
+ End
+ >::type type;
+ };
+
+ // When iteration ends, accumulated SharedTree
+ template <typename SharedTree, typename End>
+ struct native_tree_loop<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 Seq>
+ struct native_tree_impl<Seq, false, true> :
+ native_tree_loop< 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 T, std::size_t N>
+ struct native_tree<T[N]> {
+ typedef typename native_tree<T>::type type;
+ };
+
+} // namespace endian
+
+} // namespace boost
+
+
+
+#endif // BOOST_ENDIAN_NATIVE_TREE__HPP

Added: sandbox/endian_ext/boost/integer/cover_operators.hpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/boost/integer/cover_operators.hpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -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.hpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/boost/integer/endian.hpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,187 @@
+// 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>
+
+namespace boost
+{
+
+ namespace integer
+ {
+
+ template <
+# ifdef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+ BOOST_SCOPED_ENUM(endianness) E,
+#else
+ typename E,
+#endif
+ typename T,
+ std::size_t n_bits=sizeof(T)*8,
+ BOOST_SCOPED_ENUM(alignment) A = alignment::unaligned
+ > 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
+ explicit endian(T val)
+ : pack_(val)
+ {
+ }
+# endif
+ endian & operator=(T val) {
+ pack_=val;
+ return *this;
+ }
+ operator T() const
+ {
+ return T(pack_);
+ }
+ };
+
+ // naming convention typedefs ------------------------------------------------------//
+
+ // unaligned big endian signed integer types
+ typedef endian< big_endian, int_least8_t, 8 > big8_t;
+ typedef endian< big_endian, int_least16_t, 16 > big16_t;
+ typedef endian< big_endian, int_least32_t, 24 > big24_t;
+ typedef endian< big_endian, int_least32_t, 32 > big32_t;
+ typedef endian< big_endian, int_least64_t, 40 > big40_t;
+ typedef endian< big_endian, int_least64_t, 48 > big48_t;
+ typedef endian< big_endian, int_least64_t, 56 > big56_t;
+ typedef endian< big_endian, int_least64_t, 64 > big64_t;
+
+ // unaligned big endian unsigned integer types
+ typedef endian< big_endian, uint_least8_t, 8 > ubig8_t;
+ typedef endian< big_endian, uint_least16_t, 16 > ubig16_t;
+ typedef endian< big_endian, uint_least32_t, 24 > ubig24_t;
+ typedef endian< big_endian, uint_least32_t, 32 > ubig32_t;
+ typedef endian< big_endian, uint_least64_t, 40 > ubig40_t;
+ typedef endian< big_endian, uint_least64_t, 48 > ubig48_t;
+ typedef endian< big_endian, uint_least64_t, 56 > ubig56_t;
+ typedef endian< big_endian, uint_least64_t, 64 > ubig64_t;
+
+ // unaligned little endian signed integer types
+ typedef endian< little_endian, int_least8_t, 8 > little8_t;
+ typedef endian< little_endian, int_least16_t, 16 > little16_t;
+ typedef endian< little_endian, int_least32_t, 24 > little24_t;
+ typedef endian< little_endian, int_least32_t, 32 > little32_t;
+ typedef endian< little_endian, int_least64_t, 40 > little40_t;
+ typedef endian< little_endian, int_least64_t, 48 > little48_t;
+ typedef endian< little_endian, int_least64_t, 56 > little56_t;
+ typedef endian< little_endian, int_least64_t, 64 > little64_t;
+
+ // unaligned little endian unsigned integer types
+ typedef endian< little_endian, uint_least8_t, 8 > ulittle8_t;
+ typedef endian< little_endian, uint_least16_t, 16 > ulittle16_t;
+ typedef endian< little_endian, uint_least32_t, 24 > ulittle24_t;
+ typedef endian< little_endian, uint_least32_t, 32 > ulittle32_t;
+ typedef endian< little_endian, uint_least64_t, 40 > ulittle40_t;
+ typedef endian< little_endian, uint_least64_t, 48 > ulittle48_t;
+ typedef endian< little_endian, uint_least64_t, 56 > ulittle56_t;
+ typedef endian< little_endian, uint_least64_t, 64 > ulittle64_t;
+
+ // unaligned native endian signed integer types
+ typedef endian< native_endian, int_least8_t, 8 > native8_t;
+ typedef endian< native_endian, int_least16_t, 16 > native16_t;
+ typedef endian< native_endian, int_least32_t, 24 > native24_t;
+ typedef endian< native_endian, int_least32_t, 32 > native32_t;
+ typedef endian< native_endian, int_least64_t, 40 > native40_t;
+ typedef endian< native_endian, int_least64_t, 48 > native48_t;
+ typedef endian< native_endian, int_least64_t, 56 > native56_t;
+ typedef endian< native_endian, int_least64_t, 64 > native64_t;
+
+ // unaligned native endian unsigned integer types
+ typedef endian< native_endian, uint_least8_t, 8 > unative8_t;
+ typedef endian< native_endian, uint_least16_t, 16 > unative16_t;
+ typedef endian< native_endian, uint_least32_t, 24 > unative24_t;
+ typedef endian< native_endian, uint_least32_t, 32 > unative32_t;
+ typedef endian< native_endian, uint_least64_t, 40 > unative40_t;
+ typedef endian< native_endian, uint_least64_t, 48 > unative48_t;
+ typedef endian< native_endian, uint_least64_t, 56 > unative56_t;
+ typedef endian< native_endian, uint_least64_t, 64 > unative64_t;
+
+#define BOOST_HAS_INT16_T
+#define BOOST_HAS_INT32_T
+#define BOOST_HAS_INT64_T
+
+ // These types only present if platform has exact size integers:
+ // aligned big endian signed integer types
+ // aligned big endian unsigned integer types
+ // aligned little endian signed integer types
+ // aligned little endian unsigned integer types
+
+ // aligned native endian typedefs are not provided because
+ // <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
+
+ } // namespace integer
+} // namespace boost
+
+#if defined(__BORLANDC__) || defined( __CODEGEARC__)
+# pragma pack(pop)
+#endif
+
+#endif // BOOST_ENDIAN_HPP

Added: sandbox/endian_ext/boost/integer/endian_binary_stream.hpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/boost/integer/endian_binary_stream.hpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,136 @@
+// 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; };
+
+ 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 0
+ template<> struct is_endian<native8_t> { static const bool value = true; };
+ template<> struct is_endian<native16_t> { static const bool value = true; };
+ template<> struct is_endian<native24_t> { static const bool value = true; };
+ template<> struct is_endian<native32_t> { static const bool value = true; };
+ template<> struct is_endian<native40_t> { static const bool value = true; };
+ template<> struct is_endian<native48_t> { static const bool value = true; };
+ template<> struct is_endian<native56_t> { static const bool value = true; };
+ template<> struct is_endian<native64_t> { static const bool value = true; };
+
+ template<> struct is_endian<unative8_t> { static const bool value = true; };
+ template<> struct is_endian<unative16_t> { static const bool value = true; };
+ template<> struct is_endian<unative24_t> { static const bool value = true; };
+ template<> struct is_endian<unative32_t> { static const bool value = true; };
+ template<> struct is_endian<unative40_t> { static const bool value = true; };
+ template<> struct is_endian<unative48_t> { static const bool value = true; };
+ template<> struct is_endian<unative56_t> { static const bool value = true; };
+ template<> struct is_endian<unative64_t> { static const bool value = true; };
+ #endif
+ # 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
+
+ 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) );
+ }
+
+ 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_conversion.hpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/boost/integer/endian_conversion.hpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,188 @@
+// 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/endian.hpp>
+//~ #include <boost/endian/shared_tree.hpp>
+#include <boost/endian/domain_map.hpp>
+#include <boost/endian/native_tree.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/integer/endian_view.hpp>
+
+namespace boost {
+namespace integer {
+
+ template <typename EndianTarget, typename EndianSource, typename T>
+ void convert_to_from(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<
+ 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<endian::big,endian::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<endian::little,endian::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>(r);
+ //~ }
+ };
+
+ } // namespace integer_detail
+
+template <typename EndianTarget, typename EndianSource, typename T>
+void convert_to_from(T& r) {
+ integer_detail::convert_to_from<
+ typename boost::endian::domain_map<EndianTarget,T>::type,
+ typename boost::endian::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 endian::native_tree<T>::type,
+ typename boost::endian::domain_map<EndianSource,T>::type,
+ T>::apply(r);
+}
+
+template <typename EndianTarget, typename T>
+void convert_to(T& r) {
+ integer_detail::convert_to_from<
+ typename boost::endian::domain_map<EndianTarget,T>::type,
+ typename endian::native_tree<T>::type,
+ T>::apply(r);
+}
+
+#if 0
+template <typename EndianTarget, typename EndianSource, typename T>
+void convert_to_from(T& r) {
+ integer_detail::convert_to_from<EndianTarget, EndianSource, 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 endian::native_tree<T>::type, EndianSource, T>::apply(r);
+}
+
+template <typename EndianTarget, typename T>
+void convert_to(T& r) {
+ integer_detail::convert_to_from<EndianTarget, typename endian::native_tree<T>::type, T>::apply(r);
+}
+#endif
+
+} // namespace integer
+} // namespace boost
+
+
+#endif // BOOST_INTEGER_ENDIAN_CONVERT_HPP

Added: sandbox/endian_ext/boost/integer/endian_pack.hpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/boost/integer/endian_pack.hpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,421 @@
+// 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.
+
+#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/detail/endian.hpp>
+#include <boost/type_traits/is_signed.hpp>
+#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>
+
+# ifndef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+# include <boost/endian/endian.hpp>
+# endif
+
+# 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);
+ }
+
+ } // namespace detail
+
+ namespace integer
+ {
+
+# ifdef BOOST_ENDIAN_LOG
+ bool endian_log(true);
+# endif
+
+
+# ifdef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+ // endian class template and specializations ---------------------------------------//
+# ifdef BOOST_BIG_ENDIAN
+ BOOST_SCOPED_ENUM_START(endianness) { big, little, mixed, native=big }; BOOST_SCOPED_ENUM_END
+# else
+ BOOST_SCOPED_ENUM_START(endianness) { big, little, 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) native_endian = endianness::native;
+#else
+ typedef endian::big big_endian;
+ typedef endian::little little_endian;
+ typedef endian::native native_endian;
+# endif
+
+ BOOST_SCOPED_ENUM_START(alignment) { unaligned, aligned }; BOOST_SCOPED_ENUM_END
+
+ template <
+# ifdef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+ BOOST_SCOPED_ENUM(endianness) E,
+#else
+ typename E,
+#endif
+ typename T,
+ std::size_t n_bits=sizeof(T)*8,
+ BOOST_SCOPED_ENUM(alignment) A = alignment::unaligned
+ > 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 T value_type;
+# 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 << "big, unaligned, " << n_bits << "-bits, construct(" << val << ")\n";
+# endif
+ detail::store_big_endian<T, n_bits/8>(m_value, val);
+ }
+# endif
+ endian_pack & operator=(T val) { 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(" << detail::load_big_endian<T, n_bits/8>(m_value) << ")\n";
+# endif
+ return detail::load_big_endian<T, n_bits/8>(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 T value_type;
+# 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
+ 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(" << detail::load_little_endian<T, n_bits/8>(m_value) << ")\n";
+# endif
+ return detail::load_little_endian<T, n_bits/8>(m_value);
+ }
+ private:
+ char m_value[n_bits/8];
+ };
+
+
+ // Specializations that mimic built-in integer types.
+ // These typically have the same alignment as the underlying types.
+
+ // aligned big endian specialization
+ template <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 T value_type;
+# ifndef BOOST_ENDIAN_NO_CTORS
+ endian_pack() BOOST_ENDIAN_DEFAULT_CONSTRUCT
+# ifdef BOOST_BIG_ENDIAN
+ endian_pack(T val) : m_value(val) { }
+# else
+ explicit endian_pack(T val) { 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) { detail::store_big_endian<T, sizeof(T)>(&m_value, val); return *this; }
+ operator T() const { return detail::load_big_endian<T, sizeof(T)>(&m_value); }
+# endif
+ 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 T value_type;
+# ifndef BOOST_ENDIAN_NO_CTORS
+ endian_pack() BOOST_ENDIAN_DEFAULT_CONSTRUCT
+# ifdef BOOST_LITTLE_ENDIAN
+ endian_pack(T val) : m_value(val) { }
+# else
+ explicit endian_pack(T val) { 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) { detail::store_little_endian<T, sizeof(T)>(&m_value, val); return *this; }
+ operator T() const { return detail::load_little_endian<T, sizeof(T)>(&m_value); }
+ #endif
+ private:
+ T m_value;
+ };
+
+ // naming convention typedefs ------------------------------------------------------//
+
+ // unaligned big endian_pack signed integer types
+ typedef endian_pack< big_endian, int_least8_t, 8 > big8_pt;
+ typedef endian_pack< big_endian, int_least16_t, 16 > big16_pt;
+ typedef endian_pack< big_endian, int_least32_t, 24 > big24_pt;
+ typedef endian_pack< big_endian, int_least32_t, 32 > big32_pt;
+ typedef endian_pack< big_endian, int_least64_t, 40 > big40_pt;
+ typedef endian_pack< big_endian, int_least64_t, 48 > big48_pt;
+ typedef endian_pack< big_endian, int_least64_t, 56 > big56_pt;
+ typedef endian_pack< big_endian, int_least64_t, 64 > big64_pt;
+
+ // unaligned big endian_pack unsigned integer types
+ typedef endian_pack< big_endian, uint_least8_t, 8 > ubig8_pt;
+ typedef endian_pack< big_endian, uint_least16_t, 16 > ubig16_pt;
+ typedef endian_pack< big_endian, uint_least32_t, 24 > ubig24_pt;
+ typedef endian_pack< big_endian, uint_least32_t, 32 > ubig32_pt;
+ typedef endian_pack< big_endian, uint_least64_t, 40 > ubig40_pt;
+ typedef endian_pack< big_endian, uint_least64_t, 48 > ubig48_pt;
+ typedef endian_pack< big_endian, uint_least64_t, 56 > ubig56_pt;
+ typedef endian_pack< big_endian, uint_least64_t, 64 > ubig64_pt;
+
+ // unaligned little endian_pack signed integer types
+ typedef endian_pack< little_endian, int_least8_t, 8 > little8_pt;
+ typedef endian_pack< little_endian, int_least16_t, 16 > little16_pt;
+ typedef endian_pack< little_endian, int_least32_t, 24 > little24_pt;
+ typedef endian_pack< little_endian, int_least32_t, 32 > little32_pt;
+ typedef endian_pack< little_endian, int_least64_t, 40 > little40_pt;
+ typedef endian_pack< little_endian, int_least64_t, 48 > little48_pt;
+ typedef endian_pack< little_endian, int_least64_t, 56 > little56_pt;
+ typedef endian_pack< little_endian, int_least64_t, 64 > little64_pt;
+
+ // unaligned little endian_pack unsigned integer types
+ typedef endian_pack< little_endian, uint_least8_t, 8 > ulittle8_pt;
+ typedef endian_pack< little_endian, uint_least16_t, 16 > ulittle16_pt;
+ typedef endian_pack< little_endian, uint_least32_t, 24 > ulittle24_pt;
+ typedef endian_pack< little_endian, uint_least32_t, 32 > ulittle32_pt;
+ typedef endian_pack< little_endian, uint_least64_t, 40 > ulittle40_pt;
+ typedef endian_pack< little_endian, uint_least64_t, 48 > ulittle48_pt;
+ typedef endian_pack< little_endian, uint_least64_t, 56 > ulittle56_pt;
+ typedef endian_pack< little_endian, uint_least64_t, 64 > ulittle64_pt;
+
+ // unaligned native endian_pack signed integer types
+ typedef endian_pack< native_endian, int_least8_t, 8 > native8_pt;
+ typedef endian_pack< native_endian, int_least16_t, 16 > native16_pt;
+ typedef endian_pack< native_endian, int_least32_t, 24 > native24_pt;
+ typedef endian_pack< native_endian, int_least32_t, 32 > native32_pt;
+ typedef endian_pack< native_endian, int_least64_t, 40 > native40_pt;
+ typedef endian_pack< native_endian, int_least64_t, 48 > native48_pt;
+ typedef endian_pack< native_endian, int_least64_t, 56 > native56_pt;
+ typedef endian_pack< native_endian, int_least64_t, 64 > native64_pt;
+
+ // unaligned native endian_pack unsigned integer types
+ typedef endian_pack< native_endian, uint_least8_t, 8 > unative8_pt;
+ typedef endian_pack< native_endian, uint_least16_t, 16 > unative16_pt;
+ typedef endian_pack< native_endian, uint_least32_t, 24 > unative24_pt;
+ typedef endian_pack< native_endian, uint_least32_t, 32 > unative32_pt;
+ typedef endian_pack< native_endian, uint_least64_t, 40 > unative40_pt;
+ typedef endian_pack< native_endian, uint_least64_t, 48 > unative48_pt;
+ typedef endian_pack< native_endian, uint_least64_t, 56 > unative56_pt;
+ typedef endian_pack< native_endian, uint_least64_t, 64 > 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
+
+ } // 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_type.hpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/boost/integer/endian_type.hpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,247 @@
+// 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> {
+# ifdef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+ static const BOOST_SCOPED_ENUM(endianness) value= endianness::native;
+#else
+ typedef boost::endian::native type;
+#endif
+
+};
+
+// 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> {
+# ifdef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+ static const BOOST_SCOPED_ENUM(endianness) value= endianness::mixed;
+#else
+ typedef boost::endian::mixed type;
+#endif
+};
+
+// if temp is equal the endian_type of the *it continue otherwise mixed
+template <
+# ifdef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+ BOOST_SCOPED_ENUM(endianness) res,
+#else
+ typename res,
+#endif
+ 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;
+# ifdef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+ typedef typename mpl::if_c<endian_type< it_type >::value==res,
+ mpl::int_<endian_type_loop<res,typename fusion::result_of::next<It>::type, End>::value>,
+ mpl::int_<endianness::mixed>
+ >::type res_type;
+public:
+ static const BOOST_SCOPED_ENUM(endianness) value= BOOST_SCOPED_ENUM(endianness)(res_type::value);
+# else
+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,
+ boost::endian::mixed
+ >::type type;
+# endif
+};
+
+// endian_type of mixed is mixed
+template <typename It, typename End>
+# ifdef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+struct endian_type_loop<endianness::mixed,It,End> {
+ static const BOOST_SCOPED_ENUM(endianness) value= endianness::mixed;
+};
+#else
+struct endian_type_loop<boost::endian::mixed,It,End> {
+ typedef boost::endian::mixed type;
+};
+#endif
+
+// temp when iteration ends
+# ifdef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+template <BOOST_SCOPED_ENUM(endianness) temp, typename End>
+struct endian_type_loop<temp,End,End> {
+ static const BOOST_SCOPED_ENUM(endianness) value= temp;
+};
+#else
+template <typename temp, typename End>
+struct endian_type_loop<temp,End,End> {
+ typedef temp type;
+};
+#endif
+
+// 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:
+# ifdef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+ static const BOOST_SCOPED_ENUM(endianness) value=
+ endian_type_loop<endian_type< front_type >::value,
+ typename fusion::result_of::begin<Seq>::type,
+ typename fusion::result_of::end<Seq>::type
+ >::value;
+#else
+ 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;
+#endif
+
+};
+
+
+}
+
+
+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 <
+# ifdef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+ BOOST_SCOPED_ENUM(endianness) E,
+# else
+ typename E,
+# endif
+ typename T,
+ std::size_t n_bits,
+ BOOST_SCOPED_ENUM(alignment) A
+> struct endian_type<endian_pack<E,T,n_bits,A> >
+{
+# ifdef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+ static const BOOST_SCOPED_ENUM(endianness) value= E;
+#else
+ typedef E type;
+#endif
+};
+
+// endianess of endian<E,T,n_bits,A> is E
+template <
+# ifdef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+ BOOST_SCOPED_ENUM(endianness) E,
+# else
+ typename E,
+# endif
+ typename T,
+ std::size_t n_bits,
+ BOOST_SCOPED_ENUM(alignment) A
+> struct endian_type<endian<E,T,n_bits,A> >
+{
+# ifdef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+ static const BOOST_SCOPED_ENUM(endianness) value= E;
+#else
+ typedef E type;
+#endif
+};
+
+template <typename T>
+struct is_native :
+# ifdef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+ mpl::bool_<endian_type<T>::value== endianness::native>
+#else
+ is_same<typename endian_type<T>::type, boost::endian::native>
+#endif
+{};
+
+template <typename T>
+struct is_big :
+# ifdef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+ mpl::bool_<endian_type<T>::value== endianness::big>
+#else
+ is_same<typename endian_type<T>::type, boost::endian::big>
+#endif
+{};
+
+template <typename T>
+struct is_little :
+# ifdef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+ mpl::bool_<endian_type<T>::value== endianness::little>
+#else
+ is_same<typename endian_type<T>::type, boost::endian::little>
+#endif
+{};
+
+template <typename T>
+struct is_mixed :
+# ifdef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+ mpl::bool_<endian_type<T>::value== endianness::mixed>
+#else
+ is_same<typename endian_type<T>::type, boost::endian::mixed>
+#endif
+{};
+
+
+} // namespace integer
+} // namespace boost
+
+#endif // BOOST_ENDIAN_HPP

Added: sandbox/endian_ext/boost/integer/endian_view.hpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/boost/integer/endian_view.hpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,74 @@
+// 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.hpp>
+
+namespace boost {
+
+namespace integer {
+
+ template <typename Endian>
+ class endian_view {
+ typedef typename Endian::value_type T;
+ T &ref_;
+ public:
+ typedef Endian endian_t;
+ endian_view(T& ref) : ref_(ref) {};
+ operator T() const {
+ endian_t& v=reinterpret_cast<endian_t&>(ref_);
+ return v;
+ }
+ endian_view& operator=(T val) {
+ endian_t& v=reinterpret_cast<endian_t&>(ref_);
+ v=val;
+ return *this;
+ }
+ };
+
+ template <
+# ifdef BOOST_INTEGER_ENDIAN_USES_ENDIANNESS
+ BOOST_SCOPED_ENUM(endianness) E,
+#else
+ typename E,
+#endif
+ typename T
+ >
+ endian_view<endian<E,T> > as_endian(T& v) {
+ return endian_view<endian<E,T> >(v);
+ }
+
+ template <typename T>
+ endian_view<endian<native_endian,T> > as(T& v)
+ {
+ return as_endian<native_endian>(v);
+ }
+ template <typename T>
+ endian_view<endian<little_endian,T> > as_little(T& v)
+ {
+ return as_endian<little_endian>(v);
+ }
+
+ template <typename T>
+ endian_view<endian<big_endian,T> > as_big(T& v)
+ {
+ return as_endian<big_endian>(v);
+ }
+
+
+} // namespace integer
+} // namespace boost
+
+
+#endif // BOOST_ENDIAN_HPP

Added: sandbox/endian_ext/libs/integer/doc/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/doc/Jamfile.v2 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -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/doc/integer_endian.qbk
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/doc/integer_endian.qbk 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,806 @@
+[/
+ / 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.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 Endian.Integers is not a part of the Boost libraries.]
+
+
+[/========================]
+[section Overview]
+[/========================]
+
+[/==================]
+[heading Description]
+[/==================]
+
+
+[*Boost.Integer.Endian] 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 integer types as endian packs or endian integers.
+* Generic In place conversion between different endian formats.
+
+[/====================================]
+[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]
+
+
+
+[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]
+[/=================================]
+
+There is no need to compile [*Boost.Integer.Endian], since it's a header only library. Just include your Boost header directory in your compiler include path.
+
+Boost.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. For these specific parts you must use either Boost version 1.38.0 or the version in SVN trunk (even if 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 3.4.6 Linux
+[/* 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]
+
+
+
+[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>`]
+[/==========================================================================================]
+
+ namespace boost
+ {
+
+ enum class alignment { unaligned, aligned }; // scoped enum emulated on C++03
+
+ }
+
+
+[/==========================================================================================]
+[section:endian_alignment Enum Class `alignment`]
+[/==========================================================================================]
+
+
+[endsect]
+
+[endsect]
+
+[/==========================================================================================]
+[section:endian_types_hpp Header `<boost/endian/types.hpp>`]
+[/==========================================================================================]
+
+ namespace boost
+ {
+
+ enum class endianness { big, little, middle, mixed, native=<platform dependent> }; // scoped enum emulated on C++03
+
+ namespace endian {
+ struct big {
+ static const endianness value= endianness::big;
+ };
+ struct little {
+ static const endianness value= endianness::little;
+ };
+ struct middle {
+ static const endianness value= endianness::middle;
+ };
+ struct mixed {
+ static const endianness value= endianness::mixed;
+ };
+ typedef <platform dependent> native ;
+ }
+
+ }
+
+[/==========================================================================================]
+[section:endian_endianness Enum Class `endianness`]
+[/==========================================================================================]
+
+
+[endsect]
+
+[/==========================================================================================]
+[section:endian_big Class `big`]
+[/==========================================================================================]
+
+
+[endsect]
+[/==========================================================================================]
+[section:endian_little Class `little`]
+[/==========================================================================================]
+
+
+[endsect]
+[/==========================================================================================]
+[section:endian_middle Class `middle`]
+[/==========================================================================================]
+
+
+[endsect]
+[/==========================================================================================]
+[section:endian_mixed Class `mixed`]
+[/==========================================================================================]
+
+
+[endsect]
+[/==========================================================================================]
+[section:endian_native Class `native`]
+[/==========================================================================================]
+
+
+[endsect]
+
+[endsect]
+
+[/==========================================================================================]
+[section:endian_shared_tree_hpp Header `<boost/endian/shared_tree.hpp>`]
+[/==========================================================================================]
+
+
+[/==========================================================================================]
+[section:endian_shared_tree Meta Function `shared_tree`]
+[/==========================================================================================]
+
+
+[endsect]
+
+[endsect]
+
+[/==========================================================================================]
+[section:endian_native_tree_hpp Header `<boost/endian/native_tree.hpp>`]
+[/==========================================================================================]
+
+[/==========================================================================================]
+[section:endian_native_tree Meta Function `native_tree`]
+[/==========================================================================================]
+
+
+[endsect]
+
+
+[endsect]
+
+[/==========================================================================================]
+[section:integer_endian_pack_hpp Header `<boost/integer/endian_pack.hpp>`]
+[/==========================================================================================]
+
+This file contains the core class template of 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.
+
+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.
+
+Such integer 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 soesn't provides arithmetic operators, but of course automatic conversion is provided to the underlying integer value type.
+
+An `endian_pack` is an byte-holder with user-specified endianness, intger value type, size, and alignment.
+
+[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.
+
+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.
+
+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]
+
+One class template is provided:
+
+ template <endianness::enum_t E, typename T, std::size_t n_bytes,
+ alignment::enum_t A = alignment::unaligned>
+ class endian;
+
+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.
+]
+
+[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` rather than `big56_t`.
+
+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.
+
+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.
+
+[heading Synopsis]
+
+
+ namespace boost
+ {
+ namespace integer
+ {
+
+ template <endianness 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 > 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
+
+
+
+
+
+
+[/==========================================================================================]
+[section:bitfield 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 <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;
+ };
+
+
+Members
+
+`endian() = default;` // C++03: endian(){}
+
+* Effects: Constructs an object of type `endian<E, T, n_bits, A>`.
+
+`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.
+
+`endian & operator=(T v);`
+
+* Postcondition: `x == v`, where `x` is the constructed object.
+
+* Returns: *this.
+
+`operator T() const;`
+
+* Returns: The current value stored in `*this`, converted to `value_type`.
+
+Other operators
+
+Other operators on endian objects are forwarded to the equivalent operator on `value_type`.
+
+[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.
+
+
+[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.
+
+[endsect]
+
+
+[/==========================================================================================]
+[section:integer_endian_type_hpp Header `<boost/integer/endian_type.hpp>`]
+[/==========================================================================================]
+
+[endsect]
+[/==========================================================================================]
+[section:integer_endian_view_hpp Header `<boost/integer/endian_view.hpp>`]
+[/==========================================================================================]
+
+[endsect]
+
+[endsect]
+
+
+[section Example]
+
+The endian_example.cpp program writes a binary file containing four byte big-endian and little-endian integers:
+
+ #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;
+ }
+
+After compiling and executing endian_example.cpp, a hex dump of test.dat shows:
+
+ 0403 0201 0000 0010 ffff ffff 0102 0304
+
+
+
+[endsect]
+
+
+[/=================]
+[section Appendices]
+[/=================]
+[section:history Appendix A: History]
+[section [*Version 0.1.0, June 20, 2010] ['Split of Boost.Endian]]
+
+[*Features:]
+
+
+[endsect]
+[endsect]
+
+[section:rationale Appendix B: Rationale]
+
+[heading Design considerations for Boost.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 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 is a performance hit when doing arithmetic using these 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 of C++03? 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.
+
+* 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 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.
+
+* These 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]
+
+Thanks to Emile Cormier, the initiator of this library. And also to Beman Dawes; in a first version of the Boost.Bitfield the bitfield class tokes in addition an endian template parameter to make the needed endian conversions. With the Boost.Endian this is much more simpler and orthogonal.
+
+[endsect]
+
+[section Appendix E: Tests]
+
+[section 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] [#]]
+]
+
+[endsect]
+
+
+[endsect]
+
+[section Appendix F: Tickets]
+
+[endsect]
+
+
+[/=====================================]
+[section:todo Appendix G: Future plans]
+[/=====================================]
+
+[heading Tasks to do before review]
+
+* Add endian_view and in place endian converion.
+
+[heading For later releases]
+
+[endsect]
+
+
+
+[endsect]
+

Added: sandbox/endian_ext/libs/integer/example/endian_example.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/example/endian_example.cpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -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/endian
+
+//----------------------------------------------------------------------------//
+
+#define _CRT_SECURE_NO_DEPRECATE // quiet VC++ 8.0 foolishness
+
+#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;
+}

Added: sandbox/endian_ext/libs/integer/example/endian_hello_world.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/example/endian_hello_world.cpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,30 @@
+// 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/endian
+
+#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';
+}
+

Added: sandbox/endian_ext/libs/integer/test/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/test/Jamfile.v2 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,25 @@
+# Boost Endian Library test Jamfile
+
+# 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/doc/endian.html
+
+ import testing ;
+
+ 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_view_test.cpp ]
+ [ run endian_type_test.cpp ]
+ [ run endian_convert_test.cpp ]
+ ;

Added: sandbox/endian_ext/libs/integer/test/binary_stream_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/test/binary_stream_test.cpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,121 @@
+// 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
+
+#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/test/endian_binary_stream_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/test/endian_binary_stream_test.cpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,289 @@
+// endian_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
+
+#include <boost/integer/endian_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(0x010203L), big24_t_2;
+ 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;
+}

Added: sandbox/endian_ext/libs/integer/test/endian_convert_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/test/endian_convert_test.cpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,130 @@
+// endian_type_test.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/endian_pack
+
+//----------------------------------------------------------------------------//
+
+// 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_type.hpp>
+#include <boost/integer/endian_conversion.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/fusion/adapted/struct/adapt_struct.hpp>
+
+//~ #include <boost/static_assert.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 endian {
+
+ 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
+{
+void check_endian_send()
+{
+
+ X::mixed_c m;
+ m.a.a=0x01020304;
+ m.a.b=0x0A0B;
+ m.b.a=0x04030201;
+ m.b.b=0x0B0A;
+
+ 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;
+
+}
+} // unnamed namespace
+
+int main( int argc, char * argv[] )
+{
+ check_endian_send();
+ //~ return boost::report_errors();
+ return 1;
+} // main

Added: sandbox/endian_ext/libs/integer/test/endian_in_union_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/test/endian_in_union_test.cpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,83 @@
+// endian_in_union_test.cpp -------------------------------------------------//
+
+// 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)
+
+// See library home page at http://www.boost.org/libs/endian
+
+//----------------------------------------------------------------------------//
+
+#define BOOST_ENDIAN_FORCE_PODNESS
+
+#include <boost/integer/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/test/endian_operations_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/test/endian_operations_test.cpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,354 @@
+// endian_operations_test.cpp ----------------------------------------------//
+
+// 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)
+
+// See library home page at http://www.boost.org/libs/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.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
+}
+
+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;
+
+ // 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/test/endian_pack_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/test/endian_pack_test.cpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,599 @@
+// endian_pack_test.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/endian_pack
+
+//----------------------------------------------------------------------------//
+
+// 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_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/test/endian_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/test/endian_test.cpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,599 @@
+// 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/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.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_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
+
+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/test/endian_type_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/test/endian_type_test.cpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,146 @@
+// endian_type_test.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/endian_pack
+
+//----------------------------------------------------------------------------//
+
+// 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_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( int argc, char * argv[] )
+{
+ check_endian_type();
+ return boost::report_errors();
+} // main

Added: sandbox/endian_ext/libs/integer/test/endian_view_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/test/endian_view_test.cpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -0,0 +1,87 @@
+// endian_view_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/endian_pack
+
+//----------------------------------------------------------------------------//
+
+// 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 <boost/integer/endian_view.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
+{
+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;
+
+ 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);
+
+
+}
+} // unnamed namespace
+
+int main( int argc, char * argv[] )
+{
+ check_access();
+ return boost::report_errors();
+} // main

Added: sandbox/endian_ext/libs/integer/test/scoped_enum_emulation_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/test/scoped_enum_emulation_test.cpp 2010-06-10 17:53:47 EDT (Thu, 10 Jun 2010)
@@ -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 documentation at http://www.boost.org/libs/utility/scoped_enum_emulation.html
+
+#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