Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63748 - in sandbox/SOC/2010/bit_masks/boost: . integer
From: bbartmanboost_at_[hidden]
Date: 2010-07-08 09:40:46


Author: bbartman
Date: 2010-07-08 09:40:45 EDT (Thu, 08 Jul 2010)
New Revision: 63748
URL: http://svn.boost.org/trac/boost/changeset/63748

Log:
adding header from the boost endian project also known as beman's endians to work with them
Added:
   sandbox/SOC/2010/bit_masks/boost/binary_stream.hpp (contents, props changed)
   sandbox/SOC/2010/bit_masks/boost/integer/cover_operators.hpp (contents, props changed)
   sandbox/SOC/2010/bit_masks/boost/integer/endian.hpp (contents, props changed)
   sandbox/SOC/2010/bit_masks/boost/integer/endian_binary_stream.hpp (contents, props changed)

Added: sandbox/SOC/2010/bit_masks/boost/binary_stream.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bit_masks/boost/binary_stream.hpp 2010-07-08 09:40:45 EDT (Thu, 08 Jul 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/SOC/2010/bit_masks/boost/integer/cover_operators.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bit_masks/boost/integer/cover_operators.hpp 2010-07-08 09:40:45 EDT (Thu, 08 Jul 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/SOC/2010/bit_masks/boost/integer/endian.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bit_masks/boost/integer/endian.hpp 2010-07-08 09:40:45 EDT (Thu, 08 Jul 2010)
@@ -0,0 +1,431 @@
+// Boost endian.hpp header file -------------------------------------------------------//
+
+// (C) Copyright Darin Adler 2000
+// (C) Copyright Beman Dawes 2006, 2009
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+// See library home page at http://www.boost.org/libs/endian
+
+//--------------------------------------------------------------------------------------//
+
+// Original design developed by Darin Adler based on classes developed by Mark
+// Borgerding. Four original class templates were combined into a single endian
+// class template by Beman Dawes, who also added the unrolled_byte_loops sign
+// partial specialization to correctly extend the sign when cover integer size
+// differs from endian representation size.
+
+// TODO: When a compiler supporting constexpr becomes available, try possible uses.
+
+#ifndef BOOST_ENDIAN_HPP
+#define BOOST_ENDIAN_HPP
+
+#ifdef BOOST_ENDIAN_LOG
+# include <iostream>
+#endif
+
+#if defined(__BORLANDC__) || defined( __CODEGEARC__)
+# pragma pack(push, 1)
+#endif
+
+#include <boost/config.hpp>
+#include <boost/detail/endian.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 <boost/detail/scoped_enum_emulation.hpp>
+#include <iosfwd>
+#include <climits>
+
+# 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
+
+
+ // endian class template and specializations ---------------------------------------//
+
+ BOOST_SCOPED_ENUM_START(endianness) { big, little, native }; BOOST_SCOPED_ENUM_END
+ BOOST_SCOPED_ENUM_START(alignment) { unaligned, aligned }; BOOST_SCOPED_ENUM_END
+
+ template <BOOST_SCOPED_ENUM(endianness) E, typename T, std::size_t n_bits,
+ BOOST_SCOPED_ENUM(alignment) A = alignment::unaligned>
+ class endian;
+
+ // Specializations that represent unaligned bytes.
+ // Taking an integer type as a parameter provides a nice way to pass both
+ // the size and signedness of the desired integer and get the appropriate
+ // corresponding integer type for the interface.
+
+ // unaligned big endian specialization
+ template <typename T, std::size_t n_bits>
+ class endian< endianness::big, T, n_bits, alignment::unaligned >
+ : cover_operators< endian< endianness::big, T, n_bits >, T >
+ {
+ BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
+ public:
+ typedef T value_type;
+# ifndef BOOST_ENDIAN_NO_CTORS
+ endian() BOOST_ENDIAN_DEFAULT_CONSTRUCT
+ explicit endian(T val)
+ {
+# ifdef BOOST_ENDIAN_LOG
+ if ( endian_log )
+ std::clog << "big, unaligned, " << n_bits << "-bits, construct(" << val << ")\n";
+# endif
+ detail::store_big_endian<T, n_bits/8>(m_value, val);
+ }
+# endif
+ endian & 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);
+ }
+ const char* data() const { return m_value; }
+ private:
+ char m_value[n_bits/8];
+ };
+
+ // unaligned little endian specialization
+ template <typename T, std::size_t n_bits>
+ class endian< endianness::little, T, n_bits, alignment::unaligned >
+ : cover_operators< endian< endianness::little, T, n_bits >, T >
+ {
+ BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
+ public:
+ typedef T value_type;
+# ifndef BOOST_ENDIAN_NO_CTORS
+ endian() BOOST_ENDIAN_DEFAULT_CONSTRUCT
+ explicit endian(T val)
+ {
+# ifdef BOOST_ENDIAN_LOG
+ if ( endian_log )
+ std::clog << "little, unaligned, " << n_bits << "-bits, construct(" << val << ")\n";
+# endif
+ detail::store_little_endian<T, n_bits/8>(m_value, val);
+ }
+# endif
+ endian & 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);
+ }
+ const char* data() const { return m_value; }
+ private:
+ char m_value[n_bits/8];
+ };
+
+ // unaligned native endian specialization
+ template <typename T, std::size_t n_bits>
+ class endian< endianness::native, T, n_bits, alignment::unaligned >
+ : cover_operators< endian< endianness::native, T, n_bits >, T >
+ {
+ BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
+ public:
+ typedef T value_type;
+# ifndef BOOST_ENDIAN_NO_CTORS
+ endian() BOOST_ENDIAN_DEFAULT_CONSTRUCT
+# ifdef BOOST_BIG_ENDIAN
+ explicit endian(T val) { detail::store_big_endian<T, n_bits/8>(m_value, val); }
+# else
+ explicit endian(T val) { detail::store_little_endian<T, n_bits/8>(m_value, val); }
+# endif
+# endif
+# ifdef BOOST_BIG_ENDIAN
+ endian & operator=(T val) { detail::store_big_endian<T, n_bits/8>(m_value, val); return *this; }
+ operator T() const { return detail::load_big_endian<T, n_bits/8>(m_value); }
+# else
+ endian & operator=(T val) { detail::store_little_endian<T, n_bits/8>(m_value, val); return *this; }
+ operator T() const { return detail::load_little_endian<T, n_bits/8>(m_value); }
+# endif
+ const char* data() const { return m_value; }
+ private:
+ char m_value[n_bits/8];
+ };
+
+ // Specializations that mimic built-in integer types.
+ // These typically have the same alignment as the underlying types.
+
+ // aligned big endian specialization
+ template <typename T, std::size_t n_bits>
+ class endian< endianness::big, T, n_bits, alignment::aligned >
+ : cover_operators< endian< endianness::big, T, n_bits, alignment::aligned >, T >
+ {
+ BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
+ BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 );
+ public:
+ typedef T value_type;
+# ifndef BOOST_ENDIAN_NO_CTORS
+ endian() BOOST_ENDIAN_DEFAULT_CONSTRUCT
+# ifdef BOOST_BIG_ENDIAN
+ endian(T val) : m_value(val) { }
+# else
+ explicit endian(T val) { detail::store_big_endian<T, sizeof(T)>(&m_value, val); }
+# endif
+# endif
+# ifdef BOOST_BIG_ENDIAN
+ endian & operator=(T val) { m_value = val); return *this; }
+ operator T() const { return m_value; }
+# else
+ endian & operator=(T val) { detail::store_big_endian<T, sizeof(T)>(&m_value, val); return *this; }
+ operator T() const { return detail::load_big_endian<T, sizeof(T)>(&m_value); }
+# endif
+ const char* data() const { return reinterpret_cast<const char *>(&m_value); }
+ private:
+ T m_value;
+ };
+
+ // aligned little endian specialization
+ template <typename T, std::size_t n_bits>
+ class endian< endianness::little, T, n_bits, alignment::aligned >
+ : cover_operators< endian< endianness::little, T, n_bits, alignment::aligned >, T >
+ {
+ BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
+ BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 );
+ public:
+ typedef T value_type;
+# ifndef BOOST_ENDIAN_NO_CTORS
+ endian() BOOST_ENDIAN_DEFAULT_CONSTRUCT
+# ifdef BOOST_LITTLE_ENDIAN
+ endian(T val) : m_value(val) { }
+# else
+ explicit endian(T val) { detail::store_little_endian<T, sizeof(T)>(&m_value, val); }
+# endif
+# endif
+# ifdef BOOST_LITTLE_ENDIAN
+ endian & operator=(T val) { m_value = val; return *this; }
+ operator T() const { return m_value; }
+ #else
+ endian & operator=(T val) { detail::store_little_endian<T, sizeof(T)>(&m_value, val); return *this; }
+ operator T() const { return detail::load_little_endian<T, sizeof(T)>(&m_value); }
+ #endif
+ const char* data() const { return reinterpret_cast<const char *>(&m_value); }
+ private:
+ T m_value;
+ };
+
+ // naming convention typedefs ------------------------------------------------------//
+
+ // unaligned big endian signed integer types
+ typedef endian< endianness::big, int_least8_t, 8 > big8_t;
+ typedef endian< endianness::big, int_least16_t, 16 > big16_t;
+ typedef endian< endianness::big, int_least32_t, 24 > big24_t;
+ typedef endian< endianness::big, int_least32_t, 32 > big32_t;
+ typedef endian< endianness::big, int_least64_t, 40 > big40_t;
+ typedef endian< endianness::big, int_least64_t, 48 > big48_t;
+ typedef endian< endianness::big, int_least64_t, 56 > big56_t;
+ typedef endian< endianness::big, int_least64_t, 64 > big64_t;
+
+ // unaligned big endian unsigned integer types
+ typedef endian< endianness::big, uint_least8_t, 8 > ubig8_t;
+ typedef endian< endianness::big, uint_least16_t, 16 > ubig16_t;
+ typedef endian< endianness::big, uint_least32_t, 24 > ubig24_t;
+ typedef endian< endianness::big, uint_least32_t, 32 > ubig32_t;
+ typedef endian< endianness::big, uint_least64_t, 40 > ubig40_t;
+ typedef endian< endianness::big, uint_least64_t, 48 > ubig48_t;
+ typedef endian< endianness::big, uint_least64_t, 56 > ubig56_t;
+ typedef endian< endianness::big, uint_least64_t, 64 > ubig64_t;
+
+ // unaligned little endian signed integer types
+ typedef endian< endianness::little, int_least8_t, 8 > little8_t;
+ typedef endian< endianness::little, int_least16_t, 16 > little16_t;
+ typedef endian< endianness::little, int_least32_t, 24 > little24_t;
+ typedef endian< endianness::little, int_least32_t, 32 > little32_t;
+ typedef endian< endianness::little, int_least64_t, 40 > little40_t;
+ typedef endian< endianness::little, int_least64_t, 48 > little48_t;
+ typedef endian< endianness::little, int_least64_t, 56 > little56_t;
+ typedef endian< endianness::little, int_least64_t, 64 > little64_t;
+
+ // unaligned little endian unsigned integer types
+ typedef endian< endianness::little, uint_least8_t, 8 > ulittle8_t;
+ typedef endian< endianness::little, uint_least16_t, 16 > ulittle16_t;
+ typedef endian< endianness::little, uint_least32_t, 24 > ulittle24_t;
+ typedef endian< endianness::little, uint_least32_t, 32 > ulittle32_t;
+ typedef endian< endianness::little, uint_least64_t, 40 > ulittle40_t;
+ typedef endian< endianness::little, uint_least64_t, 48 > ulittle48_t;
+ typedef endian< endianness::little, uint_least64_t, 56 > ulittle56_t;
+ typedef endian< endianness::little, uint_least64_t, 64 > ulittle64_t;
+
+ // unaligned native endian signed integer types
+ typedef endian< endianness::native, int_least8_t, 8 > native8_t;
+ typedef endian< endianness::native, int_least16_t, 16 > native16_t;
+ typedef endian< endianness::native, int_least32_t, 24 > native24_t;
+ typedef endian< endianness::native, int_least32_t, 32 > native32_t;
+ typedef endian< endianness::native, int_least64_t, 40 > native40_t;
+ typedef endian< endianness::native, int_least64_t, 48 > native48_t;
+ typedef endian< endianness::native, int_least64_t, 56 > native56_t;
+ typedef endian< endianness::native, int_least64_t, 64 > native64_t;
+
+ // unaligned native endian unsigned integer types
+ typedef endian< endianness::native, uint_least8_t, 8 > unative8_t;
+ typedef endian< endianness::native, uint_least16_t, 16 > unative16_t;
+ typedef endian< endianness::native, uint_least32_t, 24 > unative24_t;
+ typedef endian< endianness::native, uint_least32_t, 32 > unative32_t;
+ typedef endian< endianness::native, uint_least64_t, 40 > unative40_t;
+ typedef endian< endianness::native, uint_least64_t, 48 > unative48_t;
+ typedef endian< endianness::native, uint_least64_t, 56 > unative56_t;
+ typedef endian< endianness::native, uint_least64_t, 64 > unative64_t;
+
+#define BOOST_HAS_INT16_T
+#define BOOST_HAS_INT32_T
+#define BOOST_HAS_INT64_T
+
+ // These types only present if platform has exact size integers:
+ // aligned big endian signed integer types
+ // aligned big endian unsigned integer types
+ // aligned little endian signed integer types
+ // aligned little endian unsigned integer types
+
+ // aligned native endian typedefs are not provided because
+ // <cstdint> types are superior for this use case
+
+# if defined(BOOST_HAS_INT16_T)
+ typedef endian< endianness::big, int16_t, 16, alignment::aligned > aligned_big16_t;
+ typedef endian< endianness::big, uint16_t, 16, alignment::aligned > aligned_ubig16_t;
+ typedef endian< endianness::little, int16_t, 16, alignment::aligned > aligned_little16_t;
+ typedef endian< endianness::little, uint16_t, 16, alignment::aligned > aligned_ulittle16_t;
+# endif
+
+# if defined(BOOST_HAS_INT32_T)
+ typedef endian< endianness::big, int32_t, 32, alignment::aligned > aligned_big32_t;
+ typedef endian< endianness::big, uint32_t, 32, alignment::aligned > aligned_ubig32_t;
+ typedef endian< endianness::little, int32_t, 32, alignment::aligned > aligned_little32_t;
+ typedef endian< endianness::little, uint32_t, 32, alignment::aligned > aligned_ulittle32_t;
+# endif
+
+# if defined(BOOST_HAS_INT64_T)
+ typedef endian< endianness::big, int64_t, 64, alignment::aligned > aligned_big64_t;
+ typedef endian< endianness::big, uint64_t, 64, alignment::aligned > aligned_ubig64_t;
+ typedef endian< endianness::little, int64_t, 64, alignment::aligned > aligned_little64_t;
+ typedef endian< endianness::little, uint64_t, 64, alignment::aligned > aligned_ulittle64_t;
+# endif
+
+ } // namespace integer
+} // namespace boost
+
+#if defined(__BORLANDC__) || defined( __CODEGEARC__)
+# pragma pack(pop)
+#endif
+
+#endif // BOOST_ENDIAN_HPP

Added: sandbox/SOC/2010/bit_masks/boost/integer/endian_binary_stream.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bit_masks/boost/integer/endian_binary_stream.hpp 2010-07-08 09:40:45 EDT (Thu, 08 Jul 2010)
@@ -0,0 +1,135 @@
+// 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; };
+
+ 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; };
+
+ # 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( e.data(), sizeof(e) );
+ }
+
+ template < class Endian >
+ inline typename boost::enable_if< is_endian<Endian>, std::istream & >::type
+ operator>=( std::istream & is, Endian & e )
+ {
+ return is.read( reinterpret_cast<char*>(&e), sizeof(e) );
+ }
+
+ } // namespace integer
+} // namespace boost
+
+#endif // BOOST_ENDIAN_BINARY_STREAM_HPP


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