|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r68378 - in sandbox/bitfield: boost/integer boost/integer/bitfield libs/bitfield libs/bitfield/doc libs/bitfield/doc/html libs/bitfield/example libs/bitfield/test libs/integer
From: vicente.botet_at_[hidden]
Date: 2011-01-23 09:05:02
Author: viboes
Date: 2011-01-23 09:04:49 EST (Sun, 23 Jan 2011)
New Revision: 68378
URL: http://svn.boost.org/trac/boost/changeset/68378
Log:
Boost.Bitfield: Port to Windows/MSVC and move to integer/bifield subdirectory
Added:
sandbox/bitfield/boost/integer/bitfield/
sandbox/bitfield/boost/integer/bitfield/bitfield.hpp (contents, props changed)
sandbox/bitfield/boost/integer/bitfield/bitfield_dcl.hpp (contents, props changed)
sandbox/bitfield/boost/integer/bitfield/endian_bitfield_value_type.hpp (contents, props changed)
sandbox/bitfield/boost/integer/bitfield/include.hpp (contents, props changed)
sandbox/bitfield/boost/integer/bitfield/pointer_plus_bits.hpp (contents, props changed)
sandbox/bitfield/libs/bitfield/
sandbox/bitfield/libs/bitfield/doc/
sandbox/bitfield/libs/bitfield/doc/Jamfile.v2 (contents, props changed)
sandbox/bitfield/libs/bitfield/doc/bitfield.pdf (contents, props changed)
sandbox/bitfield/libs/bitfield/doc/bitfield.qbk (contents, props changed)
sandbox/bitfield/libs/bitfield/doc/html/
sandbox/bitfield/libs/bitfield/doc/html/index.html (contents, props changed)
sandbox/bitfield/libs/bitfield/doc/html/standalone_HTML.manifest (contents, props changed)
sandbox/bitfield/libs/bitfield/doc/index.html (contents, props changed)
sandbox/bitfield/libs/bitfield/example/
sandbox/bitfield/libs/bitfield/test/
sandbox/bitfield/libs/bitfield/test/Jamfile.v2 (contents, props changed)
sandbox/bitfield/libs/bitfield/test/bitfield_group_test.cpp (contents, props changed)
sandbox/bitfield/libs/bitfield/test/bitfield_test.cpp (contents, props changed)
sandbox/bitfield/libs/bitfield/test/endian_flip.hpp (contents, props changed)
sandbox/bitfield/libs/bitfield/test/pointer_plus_small_int_test.cpp (contents, props changed)
Removed:
sandbox/bitfield/boost/integer/bitfield_dcl.hpp
sandbox/bitfield/boost/integer/bitfield_group.hpp
sandbox/bitfield/boost/integer/endian_bitfield_value_type.hpp.hpp
sandbox/bitfield/boost/integer/pointer_plus_bits.hpp
sandbox/bitfield/libs/integer/
Text files modified:
sandbox/bitfield/boost/integer/bitfield.hpp | 404 ---------------------------------------
1 files changed, 10 insertions(+), 394 deletions(-)
Modified: sandbox/bitfield/boost/integer/bitfield.hpp
==============================================================================
--- sandbox/bitfield/boost/integer/bitfield.hpp (original)
+++ sandbox/bitfield/boost/integer/bitfield.hpp 2011-01-23 09:04:49 EST (Sun, 23 Jan 2011)
@@ -1,404 +1,20 @@
//////////////////////////////////////////////////////////////////////////////
//
-// (C) Copyright Emile Cormier 2006.
-// (C) Copyright Vicente J. Botet Escriba 2008-2009.
-// Distributed under the Boost Software License, Version 1.0.
+// (C) Copyright Vicente J. Botet Escriba 2010.
+// 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 http://www.boost.org/libs/integer for documentation.
+// See http://www.boost.org/libs/stm for documentation.
//
//////////////////////////////////////////////////////////////////////////////
-#ifndef BOOST_INTEGER_BITFIELD__HPP
-#define BOOST_INTEGER_BITFIELD__HPP
+#ifndef BOOST_INTEGER_BITFIELD_HPP
+#define BOOST_INTEGER_BITFIELD_HPP
-#include <cstddef>
-#include <boost/static_assert.hpp>
-
-#include <cassert>
-#include <limits>
-//#include <netinet/in.h>
-
-namespace boost { namespace integer {
-
- template <typename T>
- struct bitfield_value_type {
- typedef T type;
- };
-
- //-----------------------------------------------------------------------------
- template <class, std::size_t, std::size_t, class, class> class bitfield;
-
- #if 0
- template <class R, class V>
- class bitfield_bit_proxy {
- public:
- bitfield_bit_proxy& operator=(bool state) {
- field_ &= ~mask_;
- if (state) field_ |= mask_;
- return *this;
- }
-
- operator bool() const {
- return (field_ & mask_) != 0;
- }
-
- bool operator~() const {return !(static_cast<bool>(*this));}
-
- private:
- R field_;
- V mask_;
-
- bitfield_bit_proxy(R f, V mask) : field_(f), mask_(mask) {
- std::cout << "field_=" << std::hex << field_ << std::endl;
- std::cout << "mask_=" << mask_ << std::endl;
- }
-
- template <class, std::size_t, std::size_t, class, class> friend class bitfield;
- };
-
- template <typename T> struct reference_traits;
-
- template <typename T> struct reference_traits<const T&> {
- typedef T value_type;
- };
- template <typename T> struct reference_traits<T&> {
- typedef T value_type;
- };
-
- template <typename C> struct reference_traits {
- typedef typename C::value_type value_type;
- };
- #endif
-
- namespace detail {
- // allows the user to make an explicit call to the copy constructor when
- // the types that are convertible conflict with one another.
- struct foce_copy { };
- template <bool is_signed, typename value_type
- , typename storage_type, unsigned int WIDTH>
- struct bitfield_complete_signed;
-
- template <typename value_type, typename storage_type, unsigned int WIDTH>
- struct bitfield_complete_signed<true, value_type, storage_type, WIDTH> {
- static value_type convert(storage_type val, storage_type SIGN_MASK) {
- if( (val>>(WIDTH-1))!=0) {
- return static_cast<value_type>(val | SIGN_MASK);
- } else {
- return static_cast<value_type>(val);
- }
- }
- };
-
- template <typename value_type, typename storage_type, unsigned int WIDTH>
- struct bitfield_complete_signed<false, value_type, storage_type, WIDTH> {
- static value_type convert(storage_type val, storage_type) {
- return static_cast<value_type>(val);
- }
- };
- template <typename storage_type, unsigned int WIDTH>
- struct bitfield_complete_signed<false, bool, storage_type, WIDTH> {
- static bool convert(storage_type val, storage_type) {
- return val!=0;
- }
- };
- }
-
- //------------------------------------------------------------------------------
- /*!
- Used to easily manipulate groups of bits the same way as does C bitfields,
- but in a portable manner.
- \par Example declaration:
- \code
- struct Rgb565
- {
- typedef volatile uint16_t storage_type;
- storage_type storage;
- typedef volatile uint16_t value_type;
- BOOST_BITFIELD_DCL(storage_type, storage, unsigned char, red, 0, 4);
- BOOST_BITFIELD_DCL(storage_type, storage, unsigned char, green, 5, 10);
- BOOST_BITFIELD_DCL(storage_type, storage, unsigned char, blue, 11,15);
- };
- \endcode
- \par Example usage:
- \code
- Rgb565 r;
- r.storage= 0xffff;
-
- // Write to a bitfield. Note that parenthesis are needed around the bitfield so
- r.red() = 23;
-
- // Read from a bitfield
- Rgb565::value_type b = r.blue();
-
- // Access a bit within a bit field
- bool bit = r.blue()[3];
- \endcode
- \note Bitfields within the same word may overlap.
- \param STORAGE_TYPE Unsigned integer type of the word occupied by the bitfield
- \param F Position of the first bit (0 is the least significant bit)
- \param L Position of the last bit (0 is the least significant bit)
- \param VALUE_TYPE Value type of the bitfield itself
- \param REFERENCE_TYPE Reference type of the word occupied by the bitfield
- */
-
-
- /* concept ReferenceType {
- * typedef value_type;
- * operator value_type();
- * ReferenceType operator=(ReferenceType rhs);
- * ReferenceType(ReferenceType rhs);
- * };
- * */
-
- template <typename STORAGE_TYPE, std::size_t F, std::size_t L
- , typename VALUE_TYPE=typename bitfield_value_type<STORAGE_TYPE>::type
- , typename REFERENCE_TYPE=VALUE_TYPE&>
- class bitfield {
- typedef bitfield<STORAGE_TYPE, F, L, VALUE_TYPE, REFERENCE_TYPE> this_type;
- public:
- //! storage type of the bitfield support
- typedef STORAGE_TYPE storage_type;
- //! Value type of the bitfield itself
- typedef VALUE_TYPE value_type;
- //! Reference type of the bitfield itself
- typedef REFERENCE_TYPE reference_type;
-
- private:
-
- // the storage type must be unsigned
- // BOOST_STATIC_ASSERT( std::numeric_limits<storage_type>::is_signed==false );
- // first and last index must be on the range corresponding to the storage_type
- BOOST_STATIC_ASSERT( F < 8*sizeof(storage_type) );
- BOOST_STATIC_ASSERT( L < 8*sizeof(storage_type) );
- BOOST_STATIC_ASSERT( F <= L );
- // The bitfield width can be stored on the value_type
- BOOST_STATIC_ASSERT( (L - F + 1) <= 8*sizeof(value_type) );
-
- static storage_type value_to_storage(value_type val) {
- storage_type res =storage_type(val);
- return storage_type((res & VAL_MASK) << LASTD);
- }
-
- static value_type storage_to_value(storage_type field) {
- storage_type val = storage_type((field & FIELD_MASK) >> LASTD);
- return detail::bitfield_complete_signed<std::numeric_limits<value_type>::is_signed, value_type, storage_type, WIDTH>::convert(val,SIGN_MASK);
- }
-
- void set_bit(std::size_t index, bool state) {
- field_ &= ~value_to_storage(1<<index);
- if (state) field_ |= value_to_storage(1<<index);
- }
-
- bool get_bit(std::size_t index) {
- return (field_ & value_to_storage(1<<index)) != 0;
- }
-
- template <typename BITFIELD>
- class bitfield_bit_proxy {
- public:
- bitfield_bit_proxy& operator=(bool state) {
- field_.set_bit(index_, state);
- }
-
- operator bool() const {
- return field_.get_bit(index_);
- }
-
- private:
- BITFIELD& field_;
- std::size_t index_;
-
- bitfield_bit_proxy(BITFIELD& f, std::size_t index) : field_(f), index_(index) {}
-
- template <class, std::size_t, std::size_t, class, class> friend class bitfield;
- };
- typedef bitfield_bit_proxy<this_type> bit_reference_type;
- typedef bitfield_bit_proxy<const this_type> bit_const_reference_type;
-
-
- //! private because a reference is nedeed
- bitfield();
-
- public:
-
-
- //! Useful constants
- static const std::size_t FIRST = F; //!< Position of the first bit
- static const std::size_t LAST = L; //!< Position of the last bit
- static const std::size_t STS = 8*sizeof(storage_type);
- static const std::size_t LASTD = STS-LAST-1;
- static const std::size_t WIDTH = LAST - FIRST + 1; //!< Width in bits of the bitfield
-
- static const storage_type VAL_MASK;
- static const storage_type FIELD_MASK;
- static const storage_type SIGN_MASK;
-
- static const value_type MIN_VAL = std::numeric_limits<value_type>::is_signed?value_type((1<<(WIDTH-1))-1):0; //!< min value that can be represented with the bitfield
- static const value_type MAX_VAL = std::numeric_limits<value_type>::is_signed?value_type(1<<(WIDTH-1)):(1<<(WIDTH))-1; //!< max value that can be represented with the bitfield
-
- template <VALUE_TYPE V>
- struct static_value_to_storage {
- static const storage_type value = ((storage_type(V) & VAL_MASK) << LASTD);
- };
- //! explicit constructor from a reference
- explicit bitfield(storage_type& field) : field_(field) {
- }
-
- //! setter from a value type
- void set(value_type val) {
- field_ = (field_ & ~FIELD_MASK) | value_to_storage(val);
- }
- //! Assignment from a value type
- bitfield& operator=(value_type val) {
- field_ = (field_ & ~FIELD_MASK) | value_to_storage(val);
- return *this;
- }
-
- //! Returns the bitfield value.
- operator value_type() const {
- return storage_to_value(field_);
- }
-
- value_type get() const {
- return storage_to_value(field_);
- }
-
- //! Returns the negative of the bitfield value.
- // this must be modified on the case of signed value_type
- value_type operator~() const {return storage_to_value(~field_);}
-
- #if 0
- bit_reference_type operator[](std::size_t index) {
- return bit_reference_type(field_, value_to_storage(1 << index));
- }
-
- bit_const_reference_type operator[](std::size_t index) const {
- assert(index < WIDTH);
- return bit_const_reference_type(field_, value_to_storage(1 << index));
- }
- #else
- bit_reference_type operator[](std::size_t index) {
- return bit_reference_type(*this,index);
- }
-
- bit_const_reference_type operator[](std::size_t index) const {
- assert(index < WIDTH);
- return bit_const_reference_type(*this, index);
- }
- #endif
-
- //! Returns the current bitfield value as bit flags.
- /*! The returned bit flags can be ORed with other bit flags. */
- storage_type flags() const {return field_ & FIELD_MASK;}
-
- //! Returns the given bitfield value as bit flags.
- /*! The returned bit flags can be ORed with other bit flags. */
- static storage_type get_flags(value_type val) {return value_to_storage(val);}
-
- static std::size_t first() {return FIRST;}
- static std::size_t last() {return LAST;}
- static std::size_t width() {return WIDTH;}
- static storage_type val_mask() {return VAL_MASK;}
- static storage_type field_mask() {return FIELD_MASK;}
-
- bitfield& operator=(bitfield const& rhs) {
- if (this == &rhs) return;
- field_ = rhs.field_;
- }
-
- //! Arithmetic-assign operators
- bitfield& operator++() {*this += 1; return *this;}
- value_type operator++(int) {value_type ret(*this); ++*this; return ret;}
-
- bitfield& operator--() {*this -= 1; return *this;}
- value_type operator--(int) {value_type ret(*this); --*this; return ret;}
-
- bitfield& operator+=(value_type rhs) {*this = value_type(*this) + rhs; return *this;}
- bitfield& operator-=(value_type rhs) {*this = value_type(*this) - rhs; return *this;}
-
- bitfield& operator*=(value_type rhs) {*this = value_type(*this) * rhs; return *this;}
- bitfield& operator/=(value_type rhs) {*this = value_type(*this) / rhs; return *this;}
- bitfield& operator%=(value_type rhs) {*this = value_type(*this) % rhs; return *this;}
-
- bitfield& operator<<=(int rhs) {*this = value_type(*this) << rhs; return *this;}
- bitfield& operator>>=(int rhs) {*this = value_type(*this) >> rhs; return *this;}
-
- bitfield& operator&=(value_type rhs) {*this = value_type(*this) & rhs; return *this;}
- bitfield& operator|=(value_type rhs) {*this = value_type(*this) | rhs; return *this;}
- bitfield& operator^=(value_type rhs) {*this = value_type(*this) ^ rhs; return *this;}
-
- private:
- storage_type& field_;
- };
-
-
- template <typename STORAGE_TYPE, std::size_t F, std::size_t L
- , typename VALUE_TYPE=typename bitfield_value_type<STORAGE_TYPE>::type
- >
- struct bitfield_traits {
- typedef bitfield<STORAGE_TYPE, F, L, VALUE_TYPE> reference;
- typedef bitfield<const STORAGE_TYPE, F, L, VALUE_TYPE> value;
- };
-
- template <typename OSTREAM, typename ST, std::size_t F, std::size_t L
- , typename VT
- , typename RT>
- OSTREAM& operator<<(OSTREAM& os, bitfield<ST, F, L, VT, RT> const& r) {
- os << r.value();
- return os;
- }
- template <typename ISTREAM, typename ST, std::size_t F, std::size_t L
- , typename VT
- , typename RT>
- ISTREAM& operator>>(ISTREAM& is, bitfield<ST, F, L, VT, RT> & r) {
- VT v;
- is>> v;
- r.set(v);
- return is;
- }
-
-template <
- typename STORAGE_TYPE,
- std::size_t F,
- std::size_t L,
- typename VALUE_TYPE,
- typename REFERENCE_TYPE
->
-const typename bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::storage_type bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::VAL_MASK =
- typename bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::storage_type(
- (1 << bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::WIDTH) - 1);
-
-template <
- typename STORAGE_TYPE,
- std::size_t F,
- std::size_t L,
- typename VALUE_TYPE,
- typename REFERENCE_TYPE
->
-const typename bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::storage_type bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::FIELD_MASK =
- typename bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::storage_type(
- ((1 << bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::WIDTH) - 1)
- <<
- bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::LASTD
- );
- //bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::VAL_MASK
-
-template <
- typename STORAGE_TYPE,
- std::size_t F,
- std::size_t L,
- typename VALUE_TYPE,
- typename REFERENCE_TYPE
->
-const typename bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::storage_type bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::SIGN_MASK =
- typename bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::storage_type(~
- //bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::VAL_MASK
- ((1 << bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::WIDTH) - 1)
-
- );
-
-}}
-#endif
+//-----------------------------------------------------------------------------
+#include <boost/integer/bitfield/include.hpp>
+//-----------------------------------------------------------------------------
+#endif // BOOST_INTEGER_BITFIELD_HPP
Added: sandbox/bitfield/boost/integer/bitfield/bitfield.hpp
==============================================================================
--- (empty file)
+++ sandbox/bitfield/boost/integer/bitfield/bitfield.hpp 2011-01-23 09:04:49 EST (Sun, 23 Jan 2011)
@@ -0,0 +1,357 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Emile Cormier 2006.
+// (C) Copyright Vicente J. Botet Escriba 2008-2009.
+// 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 http://www.boost.org/libs/integer for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTEGER_BITFIELD_BITFIELD_HPP
+#define BOOST_INTEGER_BITFIELD_BITFIELD_HPP
+
+#include <cstddef>
+#include <boost/static_assert.hpp>
+#include <boost/assert.hpp>
+
+#include <limits>
+
+namespace boost { namespace integer {
+
+ template <typename T>
+ struct bitfield_value_type {
+ typedef T type;
+ };
+
+ //-----------------------------------------------------------------------------
+ template <class, std::size_t, std::size_t, class, class> class bitfield;
+
+ namespace detail {
+ //~ // allows the user to make an explicit call to the copy constructor when
+ //~ // the types that are convertible conflict with one another.
+ //~ struct foce_copy { };
+ template <bool is_signed, typename value_type
+ , typename storage_type, unsigned int WIDTH>
+ struct bitfield_complete_signed;
+
+ template <typename value_type, typename storage_type, unsigned int WIDTH>
+ struct bitfield_complete_signed<true, value_type, storage_type, WIDTH> {
+ static value_type convert(storage_type val, storage_type SIGN_MASK) {
+ if( (val>>(WIDTH-1))!=0) {
+ return static_cast<value_type>(val | SIGN_MASK);
+ } else {
+ return static_cast<value_type>(val);
+ }
+ }
+ };
+
+ template <typename value_type, typename storage_type, unsigned int WIDTH>
+ struct bitfield_complete_signed<false, value_type, storage_type, WIDTH> {
+ static value_type convert(storage_type val, storage_type) {
+ return static_cast<value_type>(val);
+ }
+ };
+ template <typename storage_type, unsigned int WIDTH>
+ struct bitfield_complete_signed<false, bool, storage_type, WIDTH> {
+ static bool convert(storage_type val, storage_type) {
+ return val!=0;
+ }
+ };
+ }
+
+ //------------------------------------------------------------------------------
+ /*!
+ Used to easily manipulate groups of bits the same way as does C bitfields,
+ but in a portable manner.
+ \par Example declaration:
+ \code
+ struct Rgb565
+ {
+ typedef volatile uint16_t storage_type;
+ storage_type storage;
+ typedef volatile uint16_t value_type;
+ BOOST_BITFIELD_DCL(storage_type, storage, unsigned char, red, 0, 4);
+ BOOST_BITFIELD_DCL(storage_type, storage, unsigned char, green, 5, 10);
+ BOOST_BITFIELD_DCL(storage_type, storage, unsigned char, blue, 11,15);
+ };
+ \endcode
+ \par Example usage:
+ \code
+ Rgb565 r;
+ r.storage= 0xffff;
+
+ // Write to a bitfield. Note that parenthesis are needed around the bitfield so
+ r.red() = 23;
+
+ // Read from a bitfield
+ Rgb565::value_type b = r.blue();
+
+ // Access a bit within a bit field
+ bool bit = r.blue()[3];
+ \endcode
+ \note Bitfields within the same word may overlap.
+ \param STORAGE_TYPE Unsigned integer type of the word occupied by the bitfield
+ \param F Position of the first bit (0 is the least significant bit)
+ \param L Position of the last bit (0 is the least significant bit)
+ \param VALUE_TYPE Value type of the bitfield itself
+ \param REFERENCE_TYPE Reference type of the word occupied by the bitfield
+ */
+
+
+ /* concept ReferenceType {
+ * typedef value_type;
+ * operator value_type();
+ * ReferenceType operator=(ReferenceType rhs);
+ * ReferenceType(ReferenceType rhs);
+ * };
+ * */
+
+ template <typename STORAGE_TYPE, std::size_t F, std::size_t L
+ , typename VALUE_TYPE=typename bitfield_value_type<STORAGE_TYPE>::type
+ , typename REFERENCE_TYPE=VALUE_TYPE&>
+ class bitfield {
+ typedef bitfield<STORAGE_TYPE, F, L, VALUE_TYPE, REFERENCE_TYPE> this_type;
+ public:
+ //! storage type of the bitfield support
+ typedef STORAGE_TYPE storage_type;
+ //! Value type of the bitfield itself
+ typedef VALUE_TYPE value_type;
+ //! Reference type of the bitfield itself
+ typedef REFERENCE_TYPE reference_type;
+
+ private:
+
+ // the storage type must be unsigned
+ // BOOST_STATIC_ASSERT( std::numeric_limits<storage_type>::is_signed==false );
+ // first and last index must be on the range corresponding to the storage_type
+ BOOST_STATIC_ASSERT( F < 8*sizeof(storage_type) );
+ BOOST_STATIC_ASSERT( L < 8*sizeof(storage_type) );
+ BOOST_STATIC_ASSERT( F <= L );
+ // The bitfield width can be stored on the value_type
+ BOOST_STATIC_ASSERT( (L - F + 1) <= 8*sizeof(value_type) );
+
+ static storage_type value_to_storage(value_type val) {
+ storage_type res =storage_type(val);
+ return storage_type((res & VAL_MASK) << LASTD);
+ }
+
+ static value_type storage_to_value(storage_type field) {
+ storage_type val = storage_type((field & FIELD_MASK) >> LASTD);
+ return detail::bitfield_complete_signed<std::numeric_limits<value_type>::is_signed, value_type, storage_type, WIDTH>::convert(val,SIGN_MASK);
+ }
+
+ void set_bit(std::size_t index, bool state) {
+ field_ &= ~value_to_storage(1<<index);
+ if (state) field_ |= value_to_storage(1<<index);
+ }
+
+ bool get_bit(std::size_t index) {
+ return (field_ & value_to_storage(1<<index)) != 0;
+ }
+
+ template <typename BITFIELD>
+ class bitfield_bit_proxy {
+ public:
+ bitfield_bit_proxy& operator=(bool state) {
+ field_.set_bit(index_, state);
+ }
+
+ operator bool() const {
+ return field_.get_bit(index_);
+ }
+
+ private:
+ BITFIELD& field_;
+ std::size_t index_;
+
+ bitfield_bit_proxy(BITFIELD& f, std::size_t index) : field_(f), index_(index) {}
+
+ template <class, std::size_t, std::size_t, class, class> friend class bitfield;
+ };
+ typedef bitfield_bit_proxy<this_type> bit_reference_type;
+ typedef bitfield_bit_proxy<const this_type> bit_const_reference_type;
+
+
+ //! private because a reference is nedeed
+ bitfield();
+
+ public:
+ //! Useful constants
+ static const std::size_t FIRST = F; //!< Position of the first bit
+ static const std::size_t LAST = L; //!< Position of the last bit
+ private:
+ static const std::size_t STS = 8*sizeof(storage_type);
+ public:
+ static const std::size_t LASTD = STS-LAST-1;
+ static const std::size_t WIDTH = LAST - FIRST + 1; //!< Width in bits of the bitfield
+
+ static const storage_type VAL_MASK;
+ static const storage_type FIELD_MASK;
+ private:
+ static const storage_type SIGN_MASK;
+
+ static const value_type MIN_VAL = std::numeric_limits<value_type>::is_signed?value_type((1<<(WIDTH-1))-1):0; //!< min value that can be represented with the bitfield
+ static const value_type MAX_VAL = std::numeric_limits<value_type>::is_signed?value_type(1<<(WIDTH-1)):(1<<(WIDTH))-1; //!< max value that can be represented with the bitfield
+ public:
+ //! explicit constructor from a reference
+ explicit bitfield(storage_type& field) : field_(field) {
+ }
+
+ //! setter from a value type
+ void set(value_type val) {
+ field_ = (field_ & ~FIELD_MASK) | value_to_storage(val);
+ }
+ //! Assignment from a value type
+ bitfield& operator=(value_type val) {
+ field_ = (field_ & ~FIELD_MASK) | value_to_storage(val);
+ return *this;
+ }
+
+ //! Returns the bitfield value.
+ operator value_type() const {
+ return storage_to_value(field_);
+ }
+
+ value_type get() const {
+ return storage_to_value(field_);
+ }
+
+ //! Returns the negative of the bitfield value.
+ // this must be modified on the case of signed value_type
+ value_type operator~() const {return storage_to_value(~field_);}
+
+ bit_reference_type operator[](std::size_t index) {
+ return bit_reference_type(*this,index);
+ }
+
+ bit_const_reference_type operator[](std::size_t index) const {
+ BOOST_ASSERT(index < WIDTH);
+ return bit_const_reference_type(*this, index);
+ }
+
+ //! Returns the current bitfield value as bit flags.
+ /*! The returned bit flags can be ORed with other bit flags. */
+ storage_type flags() const {return field_ & FIELD_MASK;}
+
+ //! Returns the given bitfield value as bit flags.
+ /*! The returned bit flags can be ORed with other bit flags. */
+ static storage_type get_flags(value_type val) {return value_to_storage(val);}
+
+ static std::size_t first() {return FIRST;}
+ static std::size_t last() {return LAST;}
+ static std::size_t width() {return WIDTH;}
+ static storage_type val_mask() {return VAL_MASK;}
+ static storage_type field_mask() {return FIELD_MASK;}
+
+ bitfield& operator=(bitfield const& rhs) {
+ if (this == &rhs) return;
+ field_ = rhs.field_;
+ }
+
+ //! Arithmetic-assign operators
+ bitfield& operator++() {*this += 1; return *this;}
+ value_type operator++(int) {value_type ret(*this); ++*this; return ret;}
+
+ bitfield& operator--() {*this -= 1; return *this;}
+ value_type operator--(int) {value_type ret(*this); --*this; return ret;}
+
+ bitfield& operator+=(value_type rhs) {*this = value_type(*this) + rhs; return *this;}
+ bitfield& operator-=(value_type rhs) {*this = value_type(*this) - rhs; return *this;}
+
+ bitfield& operator*=(value_type rhs) {*this = value_type(*this) * rhs; return *this;}
+ bitfield& operator/=(value_type rhs) {*this = value_type(*this) / rhs; return *this;}
+ bitfield& operator%=(value_type rhs) {*this = value_type(*this) % rhs; return *this;}
+
+ bitfield& operator<<=(int rhs) {*this = value_type(*this) << rhs; return *this;}
+ bitfield& operator>>=(int rhs) {*this = value_type(*this) >> rhs; return *this;}
+
+ bitfield& operator&=(value_type rhs) {*this = value_type(*this) & rhs; return *this;}
+ bitfield& operator|=(value_type rhs) {*this = value_type(*this) | rhs; return *this;}
+ bitfield& operator^=(value_type rhs) {*this = value_type(*this) ^ rhs; return *this;}
+
+ private:
+ storage_type& field_;
+ };
+
+
+ template <typename STORAGE_TYPE, std::size_t F, std::size_t L
+ , typename VALUE_TYPE=typename bitfield_value_type<STORAGE_TYPE>::type
+ >
+ struct bitfield_traits {
+ typedef bitfield<STORAGE_TYPE, F, L, VALUE_TYPE> reference;
+ typedef bitfield<const STORAGE_TYPE, F, L, VALUE_TYPE> value;
+ };
+
+ template <typename OSTREAM, typename ST, std::size_t F, std::size_t L
+ , typename VT
+ , typename RT>
+ OSTREAM& operator<<(OSTREAM& os, bitfield<ST, F, L, VT, RT> const& r) {
+ os << r.value();
+ return os;
+ }
+ template <typename ISTREAM, typename ST, std::size_t F, std::size_t L
+ , typename VT
+ , typename RT>
+ ISTREAM& operator>>(ISTREAM& is, bitfield<ST, F, L, VT, RT> & r) {
+ VT v;
+ is>> v;
+ r.set(v);
+ return is;
+ }
+
+template <
+ typename STORAGE_TYPE,
+ std::size_t F,
+ std::size_t L,
+ typename VALUE_TYPE,
+ typename REFERENCE_TYPE
+>
+const typename bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::storage_type bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::VAL_MASK =
+ typename bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::storage_type(
+ (1 << bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::WIDTH) - 1);
+
+template <
+ typename STORAGE_TYPE,
+ std::size_t F,
+ std::size_t L,
+ typename VALUE_TYPE,
+ typename REFERENCE_TYPE
+>
+const typename bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::storage_type bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::FIELD_MASK =
+ typename bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::storage_type(
+ ((1 << bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::WIDTH) - 1)
+ <<
+ bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::LASTD
+ );
+
+template <
+ typename STORAGE_TYPE,
+ std::size_t F,
+ std::size_t L,
+ typename VALUE_TYPE,
+ typename REFERENCE_TYPE
+>
+const typename bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::storage_type bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::SIGN_MASK =
+ typename bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::storage_type(~
+ ((1 << bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::WIDTH) - 1)
+
+ );
+
+
+template <typename Bitfield, typename Bitfield::value_type V>
+struct bitfield_value_to_stprage {
+ static const typename Bitfield::storage_type value;
+};
+
+template <
+ typename Bitfield, typename Bitfield::value_type V
+>
+const typename Bitfield::storage_type bitfield_value_to_stprage<Bitfield, V>::value = ((V & Bitfield::VAL_MASK) << Bitfield::LASTD);
+
+
+}}
+#endif // BOOST_INTEGER_BITFIELD_BITFIELD_HPP
+
Added: sandbox/bitfield/boost/integer/bitfield/bitfield_dcl.hpp
==============================================================================
--- (empty file)
+++ sandbox/bitfield/boost/integer/bitfield/bitfield_dcl.hpp 2011-01-23 09:04:49 EST (Sun, 23 Jan 2011)
@@ -0,0 +1,24 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-2009.
+// 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 http://www.boost.org/libs/integer for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTEGER_BITFIELD_BITFIELD_DCL_HPP
+#define BOOST_INTEGER_BITFIELD_BITFIELD_DCL_HPP
+
+#include <boost/integer/bitfield/bitfield.hpp>
+
+#define BOOST_BITFIELD_DCL(STORAGE_TYPE, STORAGE_VAR, VALUE_TYPE, FIELD, F, L) \
+ typedef boost::integer::bitfield_traits<STORAGE_TYPE,F,L,VALUE_TYPE> FIELD##_type; \
+ FIELD##_type::reference FIELD() { return FIELD##_type::reference(STORAGE_VAR); } \
+ FIELD##_type::value::value_type FIELD() const { return FIELD##_type::value(STORAGE_VAR).get(); } \
+ void set_##FIELD(VALUE_TYPE& val) { FIELD##_type::reference(STORAGE_VAR).set(val); } \
+ FIELD##_type::value::value_type get_##FIELD() const { return FIELD##_type::value(STORAGE_VAR).get(); }
+
+#endif //BOOST_INTEGER_BITFIELD_BITFIELD_DCL_HPP
Added: sandbox/bitfield/boost/integer/bitfield/endian_bitfield_value_type.hpp
==============================================================================
--- (empty file)
+++ sandbox/bitfield/boost/integer/bitfield/endian_bitfield_value_type.hpp 2011-01-23 09:04:49 EST (Sun, 23 Jan 2011)
@@ -0,0 +1,30 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Emile Cormier 2006.
+// (C) Copyright Vicente J. Botet Escriba 2008-2009.
+// 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 http://www.boost.org/libs/integer for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTEGER_BITFIELD_ENDIAN_BITFIELD_VALUE_TYPE_HPP
+#define BOOST_INTEGER_BITFIELD_ENDIAN_BITFIELD_VALUE_TYPE_HPP
+
+#include <cstddef>
+#include <boost/integer/endian.hpp>
+#include <boost/integer/bitfield/bitfield.hpp>
+
+namespace boost { namespace integer {
+
+ template <endianness E, typename T, std::size_t n_bits, alignment A>
+ struct bitfield_value_type<endian<E,T,n_bits,A> > {
+ typedef typename endian<E,T,n_bits,A>::value_type type;
+ };
+
+}}
+
+#endif // BOOST_INTEGER_BITFIELD_ENDIAN_BITFIELD_VALUE_TYPE_HPP
+
Added: sandbox/bitfield/boost/integer/bitfield/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/bitfield/boost/integer/bitfield/include.hpp 2011-01-23 09:04:49 EST (Sun, 23 Jan 2011)
@@ -0,0 +1,24 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2010.
+// 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 http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTEGER_BITFIELD_INCLUDE_HPP
+#define BOOST_INTEGER_BITFIELD_INCLUDE_HPP
+
+//-----------------------------------------------------------------------------
+#include <boost/integer/bitfield/bitfield.hpp>
+#include <boost/integer/bitfield/bitfield_dcl.hpp>
+#if defined(BOOST_BITFIELD_USES_ENDIAN)
+#include <boost/integer/bitfield/endian_bitfield_value_type.hpp>
+#endif
+//-----------------------------------------------------------------------------
+
+#endif // BOOST_INTEGER_BITFIELD_INCLUDE_HPP
Added: sandbox/bitfield/boost/integer/bitfield/pointer_plus_bits.hpp
==============================================================================
--- (empty file)
+++ sandbox/bitfield/boost/integer/bitfield/pointer_plus_bits.hpp 2011-01-23 09:04:49 EST (Sun, 23 Jan 2011)
@@ -0,0 +1,339 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Joaquín M Lopez Munoz 2008.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// 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 http://www.boost.org/libs/integer for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTEGER_BITFIELD_POINTER_PLUS_BITS_HPP
+#define BOOST_INTEGER_BITFIELD_POINTER_PLUS_BITS_HPP
+
+#include <cstddef>
+#include <boost/static_assert.hpp>
+#include <boost/config.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/type_traits/alignment_of.hpp>
+
+namespace boost { namespace integer {
+
+template<int N>struct uintptr_candidates;
+template<>struct uintptr_candidates<-1>{typedef unsigned int type;};
+template<>struct uintptr_candidates<0> {typedef unsigned int type;};
+template<>struct uintptr_candidates<1> {typedef unsigned short type;};
+template<>struct uintptr_candidates<2> {typedef unsigned long type;};
+
+#if defined(BOOST_HAS_LONG_LONG)
+template<>struct uintptr_candidates<3> {typedef boost::ulong_long_type type;};
+#else
+template<>struct uintptr_candidates<3> {typedef unsigned int type;};
+#endif
+
+#if defined(BOOST_HAS_MS_INT64)
+template<>struct uintptr_candidates<4> {typedef unsigned __int64 type;};
+#else
+template<>struct uintptr_candidates<4> {typedef unsigned int type;};
+#endif
+
+struct uintptr_aux
+{
+ BOOST_STATIC_CONSTANT(int,index=
+ sizeof(void*)==sizeof(uintptr_candidates<0>::type)?0:
+ sizeof(void*)==sizeof(uintptr_candidates<1>::type)?1:
+ sizeof(void*)==sizeof(uintptr_candidates<2>::type)?2:
+ sizeof(void*)==sizeof(uintptr_candidates<3>::type)?3:
+ sizeof(void*)==sizeof(uintptr_candidates<4>::type)?4:-1);
+
+ BOOST_STATIC_CONSTANT(bool,has_uintptr_type=(index>=0));
+
+ typedef uintptr_candidates<index>::type type;
+};
+
+typedef boost::mpl::bool_<uintptr_aux::has_uintptr_type> has_uintptr_type;
+typedef uintptr_aux::type uintptr_type;
+
+
+template <std::size_t ALIGN>
+struct num_low_bits_available_for_alignement {
+ static const std::size_t value=0;
+};
+
+template <>
+struct num_low_bits_available_for_alignement<1> {
+ static const std::size_t value=0;
+};
+
+template <>
+struct num_low_bits_available_for_alignement<2> {
+ static const std::size_t value=1;
+};
+
+template <>
+struct num_low_bits_available_for_alignement<4> {
+ static const std::size_t value=2;
+};
+
+template <>
+struct num_low_bits_available_for_alignement<8> {
+ static const std::size_t value=3;
+};
+
+template <typename T>
+struct num_low_bits_available {
+};
+
+template <typename T>
+struct num_low_bits_available<T*> {
+ static const std::size_t value=num_low_bits_available_for_alignement<boost::alignment_of<T>::value>::value;
+};
+
+namespace detail {
+
+// Selects between a compressed and a regular class depending on whether
+// * the user wants the compression,
+// * the compilers has a unsigned integer type with the size of the the pointer and
+// * the alignement of the structure let unsued the BITS
+
+template <bool Compression, typename Compressed, typename Regular>
+struct select_compressed_if_required_aux {
+ typedef Compressed type;
+};
+
+template <typename Compressed, typename Regular>
+struct select_compressed_if_required_aux<false, Compressed, Regular> {
+ typedef Regular type;
+};
+
+template <typename Pointer, typename Compressed, typename Regular, std::size_t BITS, bool Compression=true>
+struct select_compressed_if_required {
+ static const bool cond = Compression && has_uintptr_type::value && (num_low_bits_available<Pointer>::value>=BITS);
+ typedef typename select_compressed_if_required_aux<
+ cond,
+ Compressed,
+ Regular
+ >::type type;
+};
+
+
+
+// compressed version
+template <typename Pointer, std::size_t BITS, typename Int>
+class compressed_pointer_plus_bits {
+ uintptr_type ui_;
+ enum {
+ /// pointer_bit_mask - The bits that come from the pointer.
+ pointer_bit_mask =
+ ~uintptr_type((uintptr_type(1) << num_low_bits_available<Pointer>::value)-1),
+
+ /// int_shift - The number of low bits that we reserve for other uses, and
+ /// keep zero.
+ int_shift = num_low_bits_available<Pointer>::value-BITS,
+
+ /// int_mask - This is the unshifted mask for valid bits of the int type.
+ int_mask = uintptr_type((uintptr_type(1) << BITS)-1),
+
+ // shifted_int_mask - This is the bits for the integer shifted in place.
+ shifted_int_mask = uintptr_type(int_mask << BITS)
+ };
+
+ struct pointer_ref {
+ uintptr_type& ui_;
+ pointer_ref(uintptr_type& ui): ui_(ui) {}
+ operator Pointer() const {
+ return reinterpret_cast<Pointer>(ui_ & pointer_bit_mask);
+ }
+
+ operator Pointer() {
+ return reinterpret_cast<Pointer>(ui_ & pointer_bit_mask);
+ }
+
+ pointer_ref& operator=(Pointer p) {
+ uintptr_type ptr_val = reinterpret_cast<uintptr_type>(p);
+ assert((ptr_val & ((1 << num_low_bits_available<Pointer>::value)-1)) == 0 &&
+ "Pointer is not sufficiently aligned");
+ // Preserve all low bits, just update the pointer.
+ ui_ = ptr_val | (ui_ & ~pointer_bit_mask);
+ return *this;
+ }
+ pointer_ref& operator=(const pointer_ref& x) {
+ return operator=(x.operator Pointer());
+ }
+ // behaves like a pointer
+ Pointer operator->() const {
+ return operator Pointer();
+ }
+ };
+
+ struct small_int_ref {
+ uintptr_type& ui_;
+ small_int_ref(uintptr_type& ui): ui_(ui) {}
+
+ operator Int() const {
+ return (Int)((ui_ >> int_shift) & int_mask);
+ }
+
+
+ small_int_ref& operator=(Int i) {
+ uintptr_type int_val = i;
+ assert(int_val < (1 << BITS) && "Integer too large for field");
+
+ // Preserve all bits other than the ones we are updating.
+ ui_ &= ~shifted_int_mask; // Remove integer field.
+ ui_ |= int_val << int_shift; // Set new integer.
+ return *this;
+ }
+ small_int_ref& operator=(const small_int_ref& x) {
+ return operator=(x.operator Int());
+ }
+ };
+
+public:
+ compressed_pointer_plus_bits (): ui_(0){}
+ compressed_pointer_plus_bits (uintptr_type ui): ui_(ui){}
+ compressed_pointer_plus_bits (Pointer p, Int i): ui_(0){
+ set_pointer(p);
+ set_int(i);
+ }
+
+ Pointer get_pointer() const {
+ //return reinterpret_cast<Pointer>(ui_ & pointer_bit_mask);
+ return Pointer(ui_ & pointer_bit_mask);
+ }
+
+ Int get_int() const {
+ return (Int)((ui_ >> int_shift) & int_mask);
+ }
+
+ void set_pointer(Pointer p) {
+ uintptr_type ptr_val = reinterpret_cast<uintptr_type>(p);
+ assert((ptr_val & ((1 << num_low_bits_available<Pointer>::value)-1)) == 0 &&
+ "Pointer is not sufficiently aligned");
+ // Preserve all low bits, just update the pointer.
+ ui_ = ptr_val | (ui_ & ~pointer_bit_mask);
+ }
+
+ void set_int(Int i) {
+ uintptr_type int_val = i;
+ assert(int_val < (1 << BITS) && "Integer too large for field");
+
+ // Preserve all bits other than the ones we are updating.
+ ui_ &= ~shifted_int_mask; // Remove integer field.
+ ui_ |= int_val << int_shift; // Set new integer.
+ }
+
+ void *get_opaque_value() const { return reinterpret_cast<void*>(ui_); }
+ void set_from_opaque_value(void *val) { ui_ = reinterpret_cast<uintptr_type>(val);}
+
+ static compressed_pointer_plus_bits get_from_opaque_value(void *p) {
+ compressed_pointer_plus_bits ppb; ppb.set_from_opaque_value(p); return ppb;
+ }
+
+ pointer_ref pointer() {return pointer_ref(ui_);}
+ small_int_ref small_int() {return small_int_ref(ui_);}
+ Pointer pointer() const {return get_pointer();}
+ Int small_int() const {return get_int(ui_);}
+};
+
+// regular version
+template <typename Pointer, typename Int>
+class regular_pointer_plus_bits {
+ Pointer pointer_;
+ Int i_;
+public:
+ regular_pointer_plus_bits ():pointer_(0),i_(0){}
+ regular_pointer_plus_bits (Pointer p, Int b):pointer_(p),i_(b){}
+
+ Pointer get_pointer() const {return pointer_;}
+ Int get_int() const {return i_;}
+ void set_pointer(Pointer p) {pointer_=p;}
+ void set_int(Int i) {return i_=i;}
+
+ Pointer& pointer() {return pointer_;}
+ Pointer pointer() const {return pointer_;}
+ Int& small_int() {return i_;}
+ Int small_int() const {return i_;}
+};
+
+}
+
+// This class implements a pair of a pointer and small integer represented by the given nomber of BITS.
+// It is designed to represent this in the space required by one pointer by bitmangling the integer
+// into the low part of the pointer. This can only be done for small integers: typically up to 3 bits,
+// but it depends on the number of bits available according to the trait num_low_bits_available_for_alignement for the
+// type.
+//
+// Note that pointer_plus_bits always puts the Int part in the highest bits
+// possible. For example, pointer_plus_bits<uint_64*, 1, bool> will put the bit for
+// the bool into bit #2, not bit #0, which allows the low two bits to be used
+// for something else. For example, this allows:
+// pointer_plus_bits<pointer_plus_bits<uint_64*, 1, bool>, 1, bool>
+// ... and the two bools will land in different bits.
+//
+
+// selects the best of the compressed or the regular version
+template <typename Pointer, std::size_t BITS, typename Int, bool Compression=true>
+struct pointer_plus_bits {
+ typedef typename detail::select_compressed_if_required<Pointer,
+ detail::compressed_pointer_plus_bits<Pointer, BITS, Int>, //num_low_bits_available<Pointer>::value>,
+ detail::regular_pointer_plus_bits<Pointer, Int>,
+ BITS, Compression
+ >::type type;
+};
+
+template <typename Pointer, std::size_t BITS, typename Int, bool Compression>
+struct num_low_bits_available<typename pointer_plus_bits<Pointer,BITS,Int,Compression>::type > {
+ static const std::size_t value= num_low_bits_available<Pointer>::value - BITS;
+};
+
+template <typename Pointer, std::size_t BITS, typename Int>
+struct num_low_bits_available<detail::compressed_pointer_plus_bits<Pointer,BITS,Int> > {
+ static const std::size_t value= num_low_bits_available<Pointer>::value - BITS;
+};
+
+namespace detail{
+template <typename T>
+struct max_bits {
+ static const std::size_t value=3;
+};
+
+template <>
+struct max_bits<bool> {
+ static const std::size_t value=1;
+};
+}
+
+template <typename T, typename Tag, std::size_t BITS=detail::max_bits<T>::value>
+struct member {
+ typedef T type;
+ typedef Tag tag_type;
+ static const std::size_t bits=BITS;
+};
+
+template <typename Tag>
+struct boolean : member<bool, Tag> {};
+
+template <typename Tag, std::size_t BITS=detail::max_bits<Tag>::value>
+struct signed_integer : member<signed int, Tag, BITS> {};
+
+template <typename Tag, std::size_t BITS=detail::max_bits<Tag>::value>
+struct unsigned_integer : member<unsigned int, Tag, BITS> {};
+
+template <typename Tag, std::size_t BITS=detail::max_bits<Tag>::value>
+struct signed_short : member<signed short, Tag, BITS> {};
+
+template <typename Tag, std::size_t BITS=detail::max_bits<Tag>::value>
+struct unsigned_short : member<unsigned short, Tag, BITS> {};
+
+template <typename Pointer, bool Compression, typename Member_1, typename Member_2=mpl::void_, typename Member_3=mpl::void_>
+struct pointer_plus_bitfields {
+
+};
+
+}}
+#endif // BOOST_INTEGER_BITFIELD_POINTER_PLUS_BITS_HPP
+
Deleted: sandbox/bitfield/boost/integer/bitfield_dcl.hpp
==============================================================================
--- sandbox/bitfield/boost/integer/bitfield_dcl.hpp 2011-01-23 09:04:49 EST (Sun, 23 Jan 2011)
+++ (empty file)
@@ -1,24 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-//
-// (C) Copyright Vicente J. Botet Escriba 2008-2009.
-// 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 http://www.boost.org/libs/integer for documentation.
-//
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef BOOST_INTEGER_BITFIELD_DCL__HPP
-#define BOOST_INTEGER_BITFIELD_DCL__HPP
-
-#include <boost/integer/bitfield.hpp>
-
-#define BOOST_BITFIELD_DCL(STORAGE_TYPE, STORAGE_VAR, VALUE_TYPE, FIELD, F, L) \
- typedef boost::integer::bitfield_traits<STORAGE_TYPE,F,L,VALUE_TYPE> FIELD##_type; \
- FIELD##_type::reference FIELD() { return FIELD##_type::reference(STORAGE_VAR); } \
- FIELD##_type::value::value_type FIELD() const { return FIELD##_type::value(STORAGE_VAR).get(); } \
- void set_##FIELD(VALUE_TYPE& val) { FIELD##_type::reference(STORAGE_VAR).set(val); } \
- FIELD##_type::value::value_type get_##FIELD() const { return FIELD##_type::value(STORAGE_VAR).get(); }
-
-#endif
Deleted: sandbox/bitfield/boost/integer/bitfield_group.hpp
==============================================================================
--- sandbox/bitfield/boost/integer/bitfield_group.hpp 2011-01-23 09:04:49 EST (Sun, 23 Jan 2011)
+++ (empty file)
@@ -1,151 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-//
-// (C) Copyright Vicente J. Botet Escriba 2008-2009.
-// 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 http://www.boost.org/libs/integer for documentation.
-//
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef BOOST_INTEGER_BITFIELD_GROUP__HPP
-#define BOOST_INTEGER_BITFIELD_GROUP__HPP
-
-#include <boost/integer/bitfield.hpp>
-
-namespace boost { namespace integer {
-
- namespace detail {
- }
-
- /*
- Used to easily manipulate groups of bitfields the same way as does C bitfields,
- but in a portable manner.
- \par Example declaration:
- \code
- struct Rgb565
- {
- struct red {};
- struct green {};
- struct blue {};
- typedef bitfields<mpl::vector<
- member<unsigned char, red, 5>,
- member<unsigned char, green, 6>,
- member<unsigned char, blue, 5>
- > > type;
- //typedef bitfields_group<mpl::vector_c<5,6,5> > type2;
- };
-
- \endcode
- \par Example usage:
- \code
- Rgb565::type r = make_bitfields<Rgb565::type, 1,2,3>;
-
- // Write to a bitfield.
- r.get<Rgb565::red>() = 23;same
- r.set<Rgb565::red>(23);
-
- // Read from a bitfield
- Rgb565::at<Rgb565::blue>::value_type b = r.get<Rgb565::blue>();
-
- // Access a bit within a bit field
- bool bit = r.get<Rgb565::blue>()[3];
- \endcode
- \note Bitfields within the word may overlap.
- \param STORAGE_TYPE Unsigned integer type of the word occupied by the bitfield
- \param F Position of the first bit (0 is the least significant bit)
- \param L Position of the last bit (0 is the least significant bit)
- \param VALUE_TYPE Value type of the bitfield itself
- \param REFERENCE_TYPE Reference type of the word occupied by the bitfield
- */
-
- template <typename IntegerType, typename Tag, std::size_t Bits>
- struct member {
- typedef IntegerType integer_type;
- typedef Tag tag_type;
- static const std::size_t BITS = Bits;
- };
-
- template <typename Member>
- struct bitfield_size {
- static const std::size_t value = Member::BITS;
- };
-
- template <typename StorageType>
- struct member_bitfield_type {
- template <typename Member, typename State>
- struct apply {
- static const std::size_t F= State::FIRST;
- struct type {
- static const FIRST=F+Member::BITS;
- typedef mpl::insert<State::map_type,
- mpl::pair<typename Member::tag_type, bitfield<StorageType, F, F+Member::BITS-1, typename Member::integer_type>
- >::type map_type;
- };
- };
- };
-
- struct bitfields_type_initial_state {
- struct type {
- static const FIRST=0;
- typedef mpl::map<> map_type;
- };
- };
-
- template <typename Members, typename Storage>
- struct bitfields_type {
- typedef mpl::fold<
- Members
- , bitfields_type_initial_state
- , member_bitfield_type<Storage>
- >::type::map_type type ;
- };
-
-
- template <typename Members>
- struct bitfields_size {
- typedef mpl::fold<
- Members
- , mpl::int_<0>
- , mpl::plus< _1, bitfield_size<_2> >
- >::type::value value ;
- };
-
- template <typename Members, typename Storage=mpl::void_>
- struct bitfields_group {
-
- // number of bits of all the bitfields
- static const std::size_t size = bitfields_size<Members>::value;
- // if not explicit select the storage associated to the number of bits of all the bitfields
- typedef mpl::if<is_void<Storage>, uint_t<size>::least, Storage> storage_type;
- // assert bits of storage_type >= size
-
- // mpl map of all the bitfields types
- typedef bitfields_type<Members, storage_type>::type map_type;
- storage_type value;
- bitfields_group() : value(0) {}
-
- };
-
- template <typename Key, typename typename Members, typename Storage>
- typename result_of::has_key<bitfields_group<Members, Storage>, Key>::type
- has_key(bitfields_group<Members, Storage> const& seq) {
- return mpl::has_key<bitfields_group<Members, Storage>::map_type>::type;
- };
-
- template <typename Key, typename typename Members, typename Storage>
- typename result_of::has_key<bitfields_group<Members, Storage>, Key>::type
- at_key(bitfields_group<Members, Storage> const& seq) {
- return mpl::at_key<Key,bitfields_group<Members, Storage>::map_type>::type(value);
- };
-
- template <typename Key, typename typename Members, typename Storage>
- typename result_of::has_key<bitfields_group<Members, Storage>, Key>::type
- at_key(bitfields_group<Members, Storage> & seq) {
- return mpl::at_key<Key,bitfields_group<Members, Storage>::map_type>::type(value);
- };
-
-}}
-#endif
-
Deleted: sandbox/bitfield/boost/integer/endian_bitfield_value_type.hpp.hpp
==============================================================================
--- sandbox/bitfield/boost/integer/endian_bitfield_value_type.hpp.hpp 2011-01-23 09:04:49 EST (Sun, 23 Jan 2011)
+++ (empty file)
@@ -1,29 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-//
-// (C) Copyright Emile Cormier 2006.
-// (C) Copyright Vicente J. Botet Escriba 2008-2009.
-// 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 http://www.boost.org/libs/integer for documentation.
-//
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef BOOST_INTEGER_BITFIELD__HPP
-#define BOOST_INTEGER_BITFIELD__HPP
-
-#include <cstddef>
-#include <boost/integer/endian.hpp>
-#include <boost/bitfield.hpp>
-
-namespace boost { namespace integer {
-
- template <endianness E, typename T, std::size_t n_bits, alignment A>
- struct bitfield_value_type<endian<E,T,n_bits,A> > {
- typedef typename endian<E,T,n_bits,A>::value_type type;
- };
-
-}}
-#endif
-
Deleted: sandbox/bitfield/boost/integer/pointer_plus_bits.hpp
==============================================================================
--- sandbox/bitfield/boost/integer/pointer_plus_bits.hpp 2011-01-23 09:04:49 EST (Sun, 23 Jan 2011)
+++ (empty file)
@@ -1,339 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-//
-// (C) Copyright Joaquín M Lopez Munoz 2008.
-// (C) Copyright Vicente J. Botet Escriba 2009.
-// 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 http://www.boost.org/libs/integer for documentation.
-//
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef BOOST_INTEGER_POINTER_PLUS_BITS__HPP
-#define BOOST_INTEGER_POINTER_PLUS_BITS__HPP
-
-#include <cstddef>
-#include <boost/static_assert.hpp>
-#include <boost/config.hpp>
-#include <boost/mpl/bool.hpp>
-#include <boost/mpl/if.hpp>
-#include <boost/type_traits/alignment_of.hpp>
-
-namespace boost { namespace integer {
-
-template<int N>struct uintptr_candidates;
-template<>struct uintptr_candidates<-1>{typedef unsigned int type;};
-template<>struct uintptr_candidates<0> {typedef unsigned int type;};
-template<>struct uintptr_candidates<1> {typedef unsigned short type;};
-template<>struct uintptr_candidates<2> {typedef unsigned long type;};
-
-#if defined(BOOST_HAS_LONG_LONG)
-template<>struct uintptr_candidates<3> {typedef boost::ulong_long_type type;};
-#else
-template<>struct uintptr_candidates<3> {typedef unsigned int type;};
-#endif
-
-#if defined(BOOST_HAS_MS_INT64)
-template<>struct uintptr_candidates<4> {typedef unsigned __int64 type;};
-#else
-template<>struct uintptr_candidates<4> {typedef unsigned int type;};
-#endif
-
-struct uintptr_aux
-{
- BOOST_STATIC_CONSTANT(int,index=
- sizeof(void*)==sizeof(uintptr_candidates<0>::type)?0:
- sizeof(void*)==sizeof(uintptr_candidates<1>::type)?1:
- sizeof(void*)==sizeof(uintptr_candidates<2>::type)?2:
- sizeof(void*)==sizeof(uintptr_candidates<3>::type)?3:
- sizeof(void*)==sizeof(uintptr_candidates<4>::type)?4:-1);
-
- BOOST_STATIC_CONSTANT(bool,has_uintptr_type=(index>=0));
-
- typedef uintptr_candidates<index>::type type;
-};
-
-typedef boost::mpl::bool_<uintptr_aux::has_uintptr_type> has_uintptr_type;
-typedef uintptr_aux::type uintptr_type;
-
-
-template <std::size_t ALIGN>
-struct num_low_bits_available_for_alignement {
- static const std::size_t value=0;
-};
-
-template <>
-struct num_low_bits_available_for_alignement<1> {
- static const std::size_t value=0;
-};
-
-template <>
-struct num_low_bits_available_for_alignement<2> {
- static const std::size_t value=1;
-};
-
-template <>
-struct num_low_bits_available_for_alignement<4> {
- static const std::size_t value=2;
-};
-
-template <>
-struct num_low_bits_available_for_alignement<8> {
- static const std::size_t value=3;
-};
-
-template <typename T>
-struct num_low_bits_available {
-};
-
-template <typename T>
-struct num_low_bits_available<T*> {
- static const std::size_t value=num_low_bits_available_for_alignement<boost::alignment_of<T>::value>::value;
-};
-
-namespace detail {
-
-// Selects between a compressed and a regular class depending on whether
-// * the user wants the compression,
-// * the compilers has a unsigned integer type with the size of the the pointer and
-// * the alignement of the structure let unsued the BITS
-
-template <bool Compression, typename Compressed, typename Regular>
-struct select_compressed_if_required_aux {
- typedef Compressed type;
-};
-
-template <typename Compressed, typename Regular>
-struct select_compressed_if_required_aux<false, Compressed, Regular> {
- typedef Regular type;
-};
-
-template <typename Pointer, typename Compressed, typename Regular, std::size_t BITS, bool Compression=true>
-struct select_compressed_if_required {
- static const bool cond = Compression && has_uintptr_type::value && (num_low_bits_available<Pointer>::value>=BITS);
- typedef typename select_compressed_if_required_aux<
- cond,
- Compressed,
- Regular
- >::type type;
-};
-
-
-
-// compressed version
-template <typename Pointer, std::size_t BITS, typename Int>
-class compressed_pointer_plus_bits {
- uintptr_type ui_;
- enum {
- /// pointer_bit_mask - The bits that come from the pointer.
- pointer_bit_mask =
- ~uintptr_type((uintptr_type(1) << num_low_bits_available<Pointer>::value)-1),
-
- /// int_shift - The number of low bits that we reserve for other uses, and
- /// keep zero.
- int_shift = num_low_bits_available<Pointer>::value-BITS,
-
- /// int_mask - This is the unshifted mask for valid bits of the int type.
- int_mask = uintptr_type((uintptr_type(1) << BITS)-1),
-
- // shifted_int_mask - This is the bits for the integer shifted in place.
- shifted_int_mask = uintptr_type(int_mask << BITS)
- };
-
- struct pointer_ref {
- uintptr_type& ui_;
- pointer_ref(uintptr_type& ui): ui_(ui) {}
- operator Pointer() const {
- return reinterpret_cast<Pointer>(ui_ & pointer_bit_mask);
- }
-
- operator Pointer() {
- return reinterpret_cast<Pointer>(ui_ & pointer_bit_mask);
- }
-
- pointer_ref& operator=(Pointer p) {
- uintptr_type ptr_val = reinterpret_cast<uintptr_type>(p);
- assert((ptr_val & ((1 << num_low_bits_available<Pointer>::value)-1)) == 0 &&
- "Pointer is not sufficiently aligned");
- // Preserve all low bits, just update the pointer.
- ui_ = ptr_val | (ui_ & ~pointer_bit_mask);
- return *this;
- }
- pointer_ref& operator=(const pointer_ref& x) {
- return operator=(x.operator Pointer());
- }
- // behaves like a pointer
- Pointer operator->() const {
- return operator Pointer();
- }
- };
-
- struct small_int_ref {
- uintptr_type& ui_;
- small_int_ref(uintptr_type& ui): ui_(ui) {}
-
- operator Int() const {
- return (Int)((ui_ >> int_shift) & int_mask);
- }
-
-
- small_int_ref& operator=(Int i) {
- uintptr_type int_val = i;
- assert(int_val < (1 << BITS) && "Integer too large for field");
-
- // Preserve all bits other than the ones we are updating.
- ui_ &= ~shifted_int_mask; // Remove integer field.
- ui_ |= int_val << int_shift; // Set new integer.
- return *this;
- }
- small_int_ref& operator=(const small_int_ref& x) {
- return operator=(x.operator Int());
- }
- };
-
-public:
- compressed_pointer_plus_bits (): ui_(0){}
- compressed_pointer_plus_bits (uintptr_type ui): ui_(ui){}
- compressed_pointer_plus_bits (Pointer p, Int i): ui_(0){
- set_pointer(p);
- set_int(i);
- }
-
- Pointer get_pointer() const {
- //return reinterpret_cast<Pointer>(ui_ & pointer_bit_mask);
- return Pointer(ui_ & pointer_bit_mask);
- }
-
- Int get_int() const {
- return (Int)((ui_ >> int_shift) & int_mask);
- }
-
- void set_pointer(Pointer p) {
- uintptr_type ptr_val = reinterpret_cast<uintptr_type>(p);
- assert((ptr_val & ((1 << num_low_bits_available<Pointer>::value)-1)) == 0 &&
- "Pointer is not sufficiently aligned");
- // Preserve all low bits, just update the pointer.
- ui_ = ptr_val | (ui_ & ~pointer_bit_mask);
- }
-
- void set_int(Int i) {
- uintptr_type int_val = i;
- assert(int_val < (1 << BITS) && "Integer too large for field");
-
- // Preserve all bits other than the ones we are updating.
- ui_ &= ~shifted_int_mask; // Remove integer field.
- ui_ |= int_val << int_shift; // Set new integer.
- }
-
- void *get_opaque_value() const { return reinterpret_cast<void*>(ui_); }
- void set_from_opaque_value(void *val) { ui_ = reinterpret_cast<uintptr_type>(val);}
-
- static compressed_pointer_plus_bits get_from_opaque_value(void *p) {
- compressed_pointer_plus_bits ppb; ppb.set_from_opaque_value(p); return ppb;
- }
-
- pointer_ref pointer() {return pointer_ref(ui_);}
- small_int_ref small_int() {return small_int_ref(ui_);}
- Pointer pointer() const {return get_pointer();}
- Int small_int() const {return get_int(ui_);}
-};
-
-// regular version
-template <typename Pointer, typename Int>
-class regular_pointer_plus_bits {
- Pointer pointer_;
- Int i_;
-public:
- regular_pointer_plus_bits ():pointer_(0),i_(0){}
- regular_pointer_plus_bits (Pointer p, Int b):pointer_(p),i_(b){}
-
- Pointer get_pointer() const {return pointer_;}
- Int get_int() const {return i_;}
- void set_pointer(Pointer p) {pointer_=p;}
- void set_int(Int i) {return i_=i;}
-
- Pointer& pointer() {return pointer_;}
- Pointer pointer() const {return pointer_;}
- Int& small_int() {return i_;}
- Int small_int() const {return i_;}
-};
-
-}
-
-// This class implements a pair of a pointer and small integer represented by the given nomber of BITS.
-// It is designed to represent this in the space required by one pointer by bitmangling the integer
-// into the low part of the pointer. This can only be done for small integers: typically up to 3 bits,
-// but it depends on the number of bits available according to the trait num_low_bits_available_for_alignement for the
-// type.
-//
-// Note that pointer_plus_bits always puts the Int part in the highest bits
-// possible. For example, pointer_plus_bits<uint_64*, 1, bool> will put the bit for
-// the bool into bit #2, not bit #0, which allows the low two bits to be used
-// for something else. For example, this allows:
-// pointer_plus_bits<pointer_plus_bits<uint_64*, 1, bool>, 1, bool>
-// ... and the two bools will land in different bits.
-//
-
-// selects the best of the compressed or the regular version
-template <typename Pointer, std::size_t BITS, typename Int, bool Compression=true>
-struct pointer_plus_bits {
- typedef typename detail::select_compressed_if_required<Pointer,
- detail::compressed_pointer_plus_bits<Pointer, BITS, Int>, //num_low_bits_available<Pointer>::value>,
- detail::regular_pointer_plus_bits<Pointer, Int>,
- BITS, Compression
- >::type type;
-};
-
-template <typename Pointer, std::size_t BITS, typename Int, bool Compression>
-struct num_low_bits_available<typename pointer_plus_bits<Pointer,BITS,Int,Compression>::type > {
- static const std::size_t value= num_low_bits_available<Pointer>::value - BITS;
-};
-
-template <typename Pointer, std::size_t BITS, typename Int>
-struct num_low_bits_available<detail::compressed_pointer_plus_bits<Pointer,BITS,Int> > {
- static const std::size_t value= num_low_bits_available<Pointer>::value - BITS;
-};
-
-namespace detail{
-template <typename T>
-struct max_bits {
- static const std::size_t value=3;
-};
-
-template <>
-struct max_bits<bool> {
- static const std::size_t value=1;
-};
-}
-
-template <typename T, typename Tag, std::size_t BITS=detail::max_bits<T>::value>
-struct member {
- typedef T type;
- typedef Tag tag_type;
- static const std::size_t bits=BITS;
-};
-
-template <typename Tag>
-struct boolean : member<bool, Tag> {};
-
-template <typename Tag, std::size_t BITS=detail::max_bits<Tag>::value>
-struct signed_integer : member<signed int, Tag, BITS> {};
-
-template <typename Tag, std::size_t BITS=detail::max_bits<Tag>::value>
-struct unsigned_integer : member<unsigned int, Tag, BITS> {};
-
-template <typename Tag, std::size_t BITS=detail::max_bits<Tag>::value>
-struct signed_short : member<signed short, Tag, BITS> {};
-
-template <typename Tag, std::size_t BITS=detail::max_bits<Tag>::value>
-struct unsigned_short : member<unsigned short, Tag, BITS> {};
-
-template <typename Pointer, bool Compression, typename Member_1, typename Member_2=mpl::void_, typename Member_3=mpl::void_>
-struct pointer_plus_bitfields {
-
-};
-
-}}
-#endif
-
Added: sandbox/bitfield/libs/bitfield/doc/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/bitfield/libs/bitfield/doc/Jamfile.v2 2011-01-23 09:04:49 EST (Sun, 23 Jan 2011)
@@ -0,0 +1,75 @@
+# Boost.Bitfield 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 bitfield : bitfield.qbk ;
+
+boostbook standalone
+ :
+ bitfield
+ :
+ # 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=0
+ # 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/src/boostbook.css
+
+ # PDF Options:
+ # TOC Generation: this is needed for FOP-0.9 and later:
+ #<xsl:param>fop1.extensions=0
+ # 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)/
+ #<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/libs/bitfield/doc/html
+ ;
+
+install pdf-install : standalone : <location>. <install-type>PDF ;
Added: sandbox/bitfield/libs/bitfield/doc/bitfield.pdf
==============================================================================
Binary file. No diff available.
Added: sandbox/bitfield/libs/bitfield/doc/bitfield.qbk
==============================================================================
--- (empty file)
+++ sandbox/bitfield/libs/bitfield/doc/bitfield.qbk 2011-01-23 09:04:49 EST (Sun, 23 Jan 2011)
@@ -0,0 +1,821 @@
+[/
+ / Copyright (c) 2008 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.Bitfield
+ [quickbook 1.5]
+ [version 0.2.0]
+ [authors [Botet Escriba, Vicente J.]]
+ [copyright 2009 Vicente J. Botet Escriba]
+ [purpose Bitfield portable traits]
+ [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 Bitfield is not a part of the Boost libraries.]
+
+[/========================]
+[section Overview]
+[/========================]
+
+[/====================================]
+[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].
+* Free functions are rendered in the code font followed by (), as in 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 Bitfield files
+ #include <boost/integer/bitfield.hpp>
+ using namespace boost::integer;
+
+[section Motivation]
+
+In order for an application or a device driver to use the same source code base on both platforms, it must either be endian neutral, or use conditional compilation to select appropriate code modules. A program module is considered endian neutral if it retains its functionality while being ported across platforms of different endianness. In other words, there is no relation between its functionality and the endianness of the platform it is running on.
+Endianness issues become important when porting the pieces of the application that relate to client communication over a heterogeneous network, persistent data storage on the disk, product tracing (it is important that trace generated on SPARC gets formatted correctly on x86) and other related areas.
+
+Boost.Endian handles with most of the issues related to the byte ordering, but do not manage the bit ordering. E.g. the following structure has a different layout in big and little endian machines.
+
+ struct X {
+ unsigned int d00:1;
+ unsigned int d01:7;
+ unsigned int d02:2;
+ unsigned int d03:6;
+ unsigned int d04:4;
+ unsigned int d05:4;
+ unsigned int d06:1;
+ unsigned int d07:3;
+ unsigned int d08:4;
+ };
+
+In order to make this structure endian neutral, we need to use conditional compilation, and swap on byte level of the fields
+
+
+ struct X {
+ #if __BYTE_ORDER == __BIG_ENDIAN
+ unsigned int d00:1;
+ unsigned int d01:7;
+ unsigned int d02:2;
+ unsigned int d03:6;
+ unsigned int d04:4;
+ unsigned int d05:4;
+ unsigned int d06:1;
+ unsigned int d07:3;
+ unsigned int d08:4;
+ #else
+ unsigned int d01:7;
+ unsigned int d00:1;
+ unsigned int d03:6;
+ unsigned int d02:2;
+ unsigned int d05:4;
+ unsigned int d04:4;
+ unsigned int d08:4;
+ unsigned int d07:3;
+ unsigned int d06:1;
+ #endif
+ }
+
+The preceding technique can be applied as far as the bitfield is contained on a byte boundary. But for bitfields using several bytes as in
+
+ struct X {
+ unsigned int d00:11;
+ unsigned int d01:21;
+ };
+
+there is no way using conditional compilation to adapt the structure and preserve the fields.
+
+Two approaches can be considered:
+
+[heading Decompose the fields not defined on a byte boundary on several bitfield defined on a byte boundary]
+
+ struct X {
+ #if __BYTE_ORDER == __BIG_ENDIAN
+ unsigned int d00_b0:8;
+ unsigned int d00_b1:3;
+ unsigned int d01_b0:5;
+ unsigned int d01_b1:8;
+ unsigned int d01_b2:8;
+ #else
+ unsigned int d01_b2:8;
+ unsigned int d01_b1:8;
+ unsigned int d01_b0:5;
+ unsigned int d00_b1:3;
+ unsigned int d00_b0:8;
+ #endif
+ };
+
+and define a way to access the bitfield information of the ENDIAN_UNSAFE structure. This library do not use this apprach.
+
+[heading Replace the bitfields by the integer type]
+
+When it is possible, a suggestion would be to transform the bitfields into integers, as follows:
+
+ struct X {
+ #ifdef ATRIUM_PORTABLE
+ unsigned int d0;
+ #else
+ unsigned int d00:11; /* ENDIAN_UNSAFE */
+ unsigned int d01:21; /* ENDIAN_UNSAFE */
+ #endif
+ };
+
+and define a way to access the bitfield information.
+
+When the structure is used by a C++ program, all the uses of the bit fields (d00 and d01) could be replaced by an inline function, so
+
+ y = x.d00;
+
+could be replaced by
+
+ y = x.d00();
+
+or
+
+ y = x.get_d00();
+
+and
+ x.d00= y;
+
+could be replaced by
+
+ x.d00()= y;
+
+or
+
+ x.set_d00(y)
+
+where
+
+ struct X {
+ typedef std::uint_32 storage_type;
+ storage_type d0;
+ typedef unsigned int value_type;
+ BOOST_BITFIELD_DCL(storage_type, d0, unsigned int, d00, 0, 10);
+ BOOST_BITFIELD_DCL(storage_type, d0, unsigned int, d01, 11, 31);
+ };
+
+
+The goal of Boost.Bitfield is to make possible this simple portable translation.
+
+If we want to write the storage type to a binary archive we need to precise which will be the endian format of the storage type. For this end, you can use any of the endian types provided by the Boost.Endian library. If the storage is big you can declare
+
+ struct X {
+ typedef boost::ubig_32 storage_type;
+ storage_type d0;
+ typedef unsigned int value_type;
+ BOOST_BITFIELD_DCL(storage_type, d0, unsigned int, d00, 0, 10);
+ BOOST_BITFIELD_DCL(storage_type, d0, unsigned int, d01, 11, 31);
+ };
+
+
+[endsect]
+
+[/==================]
+[section Description]
+[/==================]
+
+Portable bitfields.
+
+The main source of inspiration of this library was Boost.Bitfield from Emile Cormier.
+
+[*Boost.Bitfield] provides:
+
+* a generic bitfield traits class providing generic getter and setter.
+* a BOOST_BITFIELD_DCL macro making easier the definition of the bitfield helper type and the bitfield getter and setter functions.
+
+[endsect]
+
+[endsect]
+
+[/==============================]
+[section:users_guide Users'Guide]
+[/==============================]
+
+[/======================================]
+[section:getting_started Getting Started]
+[/======================================]
+
+[/======================================]
+[section:install Installing Bitfield]
+[/======================================]
+
+[/=================================]
+[heading Getting Boost.Bitfield]
+[/=================================]
+
+You can get the last stable release of Boost.Bitfield by downloading [^bitfield.zip] from the
+[@http://www.boost-consulting.com/vault/index.php?directory=Endianess%20Programming Boost Vault]
+
+You can also access the latest (unstable?) state from the [@https://svn.boost.org/svn/boost/sandbox/bitfield Boost Sandbox].
+
+[/=================================]
+[heading Building Boost.Bitfield]
+[/=================================]
+
+[*Boost.Bitfield] is a header only library, so no need to compile anything.
+
+[/=========================]
+[heading Requirements]
+[/=========================]
+
+[*Boost.Bitfield] 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, providing the strong exception safety guarantee.
+
+[/====================]
+[heading Thread safety]
+[/====================]
+
+All functions in the library are thread-unsafe except when noted explicitly.
+
+
+[/=======================]
+[heading Tested compilers]
+[/=======================]
+
+[*Boost.Bitfield] should work with an C++03 conforming compiler. The current version has been tested on:
+
+Windows with
+
+* MSVC 10.0
+
+Cygwin 1.5
+
+* GCC 3.4.4
+
+Cygwin 1.7
+
+* GCC 4.3.2
+
+MinGW with
+
+* GCC 4.4.0
+* GCC 4.5.0
+* GCC 4.5.0 c++0x
+* GCC 4.6.0
+* GCC 4.6.0 c++0x
+
+[note Please let us know how this works on other platforms/compilers.]
+
+[note Please send any questions, comments and bug reports to boost <at> lists <dot> boost <dot> org.]
+
+[endsect]
+[/
+[/=============================]
+[section Hello World! ]
+[/=============================]
+
+
+[endsect]
+]
+[endsect]
+
+[section Tutorial]
+
+[section Declaring a storage variable]
+
+The first thing to do is to declare a storage type able to store all the bitfields. In the following example we want to stor bits for the RGB encoding, so 16 bits is enough.
+
+ struct Rgb565
+ {
+ typedef ubig16_t storage_type;
+ storage_type storage;
+ };
+
+[endsect]
+
+[section Bitfieds helper classes and bitfield accessors]
+
+[heading Declaring a bitfield helper type]
+
+For each bitfields we need to declare a type that knows about the bitfield traits of the bitfield.
+
+ struct Rgb565
+ {
+ //...
+ typedef bitfield_traits<storage_type, 0, 4, unsigned char> red_type;
+ };
+
+
+[heading bitfield getters]
+
+Now we are ready to define the getter of this bitfield respect to the storage variable. My prefered form is just to name the getter function as the type, others will prefer the get_field() form.
+
+ struct Rgb565
+ {
+ //...
+ red_type::value::value_type red() const { return red_type::value(storage).get(); }
+ red_type::value::value_type get_red() const { return red_type::value(storage).get(); }
+ };
+
+[heading bitfield setters]
+
+
+There are two variants for the setter. My prefered form is just to name the setter function as the type and return a reference able to support assignations. The other is the traditional set_field() taking the new value as parameter.
+
+ struct Rgb565
+ {
+ //...
+ red_type::reference red() { return red_type::reference(storage); }
+ void set_red(unsigned char val) { return red_type::reference(storage).set(val); }
+ };
+
+
+[endsect]
+
+[section Using macros to declare portable bitfields ]
+
+All these stuf can be done at once using the BOOST_BITFIELD_DCL macro as follows.
+
+ struct Rgb565
+ {
+ typedef volatile uint16_t storage_type;
+ storage_type storage;
+ typedef volatile uint16_t value_type;
+ BOOST_BITFIELD_DCL(storage_type, storage, unsigned char, red, 0, 4);
+ BOOST_BITFIELD_DCL(storage_type, storage, unsigned char, green, 5, 10);
+ BOOST_BITFIELD_DCL(storage_type, storage, unsigned char, blue, 11,15);
+ };
+
+[endsect]
+
+[section Using bitfield getters and setters]
+
+Next follows some examples of how these bitfields can be used.
+
+ Rgb565 r;
+ r.storage= 0xffff;
+
+ // Write to a bitfield. Note that parenthesis are needed around the bitfield so
+ r.red() = 23;
+
+ // Read from a bitfield
+ Rgb565::value_type b = r.blue();
+
+ // Access a bit within a bit field
+ bool bit = r.blue()[3];
+
+[endsect]
+
+[endsect]
+
+
+[section:ext_references References]
+[variablelist
+
+[
+ [[@http://www.boost.org/libs/integer/endian.htm [*Boost.Endian]]]
+ [general integer-like byte-holder binary types with explicit control over byte order, value type, size, and alignment from Beman Dawes]
+]
+
+
+]
+
+[endsect]
+
+[endsect]
+
+
+[section Reference]
+[/==========================================================================================]
+[section:integer_bitfield_hpp Header `<boost/integer/bitfield.hpp>`]
+[/==========================================================================================]
+
+Include all the Boost.Bitfields header files
+
+[endsect]
+[/==========================================================================================]
+[section:bitfield_include_hpp Header `<boost/integer/bitfield/include.hpp>`]
+[/==========================================================================================]
+
+Include all the Boost.Bitfields header files
+
+[endsect]
+
+[/==========================================================================================]
+[section:bitfield_hpp Header `<boost/integer/bitfield/bitfield.hpp>`]
+[/==========================================================================================]
+
+This is the main file of Boost.Bitfield, which includes the definition of the bitfield<> class.
+
+ namespace boost { namespace integer {
+ template <typename T>
+ struct bitfield_default_value_type;
+
+ template <class, std::size, std::size, class, bool, class>
+ class bitfield;
+
+ template <typename STORAGE_TYPE, int F, int L
+ , typename VALUE_TYPE=bitfield_default_value_type<typename STORAGE_TYPE::type>
+ >
+ struct bitfield_traits;
+ }
+
+[/==========================================================================================]
+[section:bitfield_value_type Metafunction `bitfield_value_type<>`]
+[/==========================================================================================]
+
+The default value type associated to an storage type is the storage type itself.
+
+ template <typename T>
+ struct bitfield_value_type {
+ typedef T type;
+ };
+
+The user could need to specialize this metafunction for some specific types, as for example for types comming from the Boost.Endian library.
+
+[endsect]
+
+[/==========================================================================================]
+[section:bitfield Template class `bitfield<>`]
+[/==========================================================================================]
+
+The `bitfield` class is a wrapper to an storage type that allows to get/`set a bitfield of a given value type defined by the first and last bit that the bitfield occupes in the storage type. It defines the conversion to the bitfield value type as weel as all the arithmetic assignement operators.
+
+This template class behaves as a reference to a bit field. Note that C/C++ do not allows to take directly the address of a bit field.
+
+ template <typename STORAGE_TYPE, std::size F, std::size L
+ , typename VALUE_TYPE=typename bitfield_value_type<typename STORAGE_TYPE::type>
+ , typename REFERENCE_TYPE=STORAGE_TYPE&>
+ class bitfield {
+ public:
+ //! Reference type of the word occupied by the bitfield
+ typedef REFERENCE_TYPE reference_type;
+ //! Value type of the bitfield itself
+ typedef VALUE_TYPE value_type;
+ //! storage type of the bitfield support
+ typedef typename reference_traits<REFERENCE_TYPE>::value_type storage_type;
+
+ //! Useful constants
+ static const unsigned int FIRST; //!< Position of the first bit
+ static const unsigned int LAST; //!< Position of the last bit
+ static const unsigned int WIDTH; //!< Width in bits of the bitfield
+ static const unsigned int VAL_MASK; //!< Mask applied against assigned values
+ static const unsigned int FIELD_MASK; //!< Mask of the field's bit positions
+
+ static std::size_t first();
+ static std::size_t last();
+ static std::size_t width();
+ static storage_type val_mask();
+ static storage_type field_mask();
+
+ //! deleted because a reference is nedeed
+ bitfield() = delete;
+ //! explicit constructor from a reference
+ explicit bitfield(reference_type field);
+
+ //! Assignment from a value type
+ bitfield& operator=(value_type val);
+
+ //! value_type implicit conversion
+ operator value_type() const;
+
+ //! value_type explicit getter
+ value_type get() const;
+
+ //! Returns the negative of the bitfield value.
+ // this must be modified on the case of signed value_type
+ value_type operator~() const;
+
+ bit_reference_type operator[](std::size_t index);
+
+ bit_const_reference_type operator[](std::size_t index) const;
+
+ //! Returns the current bitfield value as bit flags.
+ /*! The returned bit flags can be ORed with other bit flags. */
+ storage_type flags() const;
+
+ //! Returns the current bitfield value as bit flags.
+ /*! The returned bit flags can be ORed with other bit flags. */
+ static storage_type flags(value_type val) const;
+
+ //! Arithmetic-assign operators
+ bitfield& operator++();
+ value_type operator++(int);
+
+ bitfield& operator--();
+ value_type operator--(int);
+
+ bitfield& operator+=(value_type rhs);
+ bitfield& operator-=(value_type rhs);
+
+ bitfield& operator*=(value_type rhs);
+ bitfield& operator/=(value_type rhs);
+ bitfield& operator%=(value_type rhs);
+
+ bitfield& operator<<=(int rhs);
+ bitfield& operator>>=(int rhs);
+
+ bitfield& operator&=(value_type rhs);
+ bitfield& operator|=(value_type rhs);
+ bitfield& operator^=(value_type rhs);
+ };
+
+[endsect]
+
+
+[/==========================================================================================]
+[section:bitfield_traits Template class `bitfield_traits<>`]
+[/==========================================================================================]
+
+This traits class defies two traits:
+
+* reference: used to modify a bitfield
+* value: used to get the value of a bitset
+
+ template <typename STORAGE_TYPE, int F, int L
+ , typename VALUE_TYPE=typename bitfield_value_type<typename STORAGE_TYPE::type>
+ >
+ struct bitfield_traits {
+ typedef bitfield<STORAGE_TYPE, F, L, VALUE_TYPE> reference;
+ typedef bitfield<const STORAGE_TYPE, F, L, VALUE_TYPE> value;
+ };
+
+[endsect]
+
+[endsect]
+
+[/==========================================================================================]
+[section:bitfield_dcl_hpp Header `<boost/integer/bitfield/bitfield_dcl.hpp>`]
+[/==========================================================================================]
+
+This file constains the macro making easier the definition of the bitfield helper type and the bitfield getter and setter functions.
+
+ #define BOOST_BITFIELD_DCL(STORAGE_TYPE, STORAGE_VAR, VALUE_TYPE, FIELD, F, L)
+
+[/==========================================================================================]
+[section:BOOST_BITFIELD_DCL Macro `BOOST_BITFIELD_DCL`]
+[/==========================================================================================]
+
+ #define BOOST_BITFIELD_DCL(STORAGE_TYPE, STORAGE_VAR, VALUE_TYPE, FIELD, F, L)
+
+* Parameters
+ * STORAGE_TYPE: the type to store the bitfield
+ * STORAGE_VAR: the variable used to store the bitfield
+ * VALUE_TYPE: the type for the bitfield
+ * FIELD: the name of the bitfield
+ * F: the first bit
+ * L: the last bit
+
+* Effect. This macro defines the bitfield traits and the functions necessary to make valid the following expressions:
+ * str.FIELD() = value;
+ * var= str.FIELD();
+ * str.set_FIELD(var);
+ * var= str.get_FIELD()
+
+
+Two styles of getter/setter are provided: one using overloading on the field name, the other using clasical prefix `get_`/`set_`.
+
+[endsect]
+
+[endsect]
+
+[/==========================================================================================]
+[section:endian_bitfield_value_type_hpp Header `<boost/integer/bitfield/endian_bitfield_value_type.hpp>`]
+[/==========================================================================================]
+
+This file includes the `bitfield_value_type` metafunction specialization for the endian types. You need to include this file if you use endian types as storage for the bitfields.
+
+ namespace boost { namespace integer {
+ template <endianness E, typename T, std::size_t n_bits, alignment A>
+ struct bitfield_value_type<endian<E,T,n_bits,A> > {
+ typedef typename endian<E,T,n_bits,A>::value_type type;
+ };
+ }
+
+[endsect]
+
+[endsect]
+
+[/
+[section Examples]
+[section bitfield signed value type]
+[SIGNED__HPP]
+
+[endsect]
+
+[endsect]
+]
+
+[/=================]
+[section Appendices]
+[/=================]
+
+[section:history Appendix A: History]
+
+[section [*Version 0.2.0, Jan 29, 2011] ['Bitfield porting to Windows and MSVC]]
+
+[*Bugs:]
+
+* Fix uses of specific POSIX files in test.
+* Adapt to MSVC constraints.
+
+[endsect]
+
+[section [*Version 0.1.0, April 29, 2009] ['Announcement of Bitfield]]
+
+[*Features:]
+
+* a generic bitfield traits class providing generic getter and setter for portable bitfields.
+* a BOOST_BITFIELD_DCL macro making easier the definition of the bitfield helper type and the bitfield getter and setter functions.
+
+[endsect]
+[endsect]
+
+[section:rationale Appendix B: Rationale]
+
+[heading Why we can not declare portable C/C++ bitfields ?]
+
+[endsect]
+
+[section:implementation Appendix C: Implementation Notes]
+
+[heading FAQ]
+
+* Why bother with endian bitfields ?
+
+External data portability and both speed and space efficiency.
+Availability of bit order representations is important in some applications.
+
+* Why not just use Boost.Serialization?
+
+Serialization involves a conversion for every object involved in I/O. Bitfields 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.
+
+* Do this type have any uses outside of I/O?
+
+Probably not.
+
+* Is there is a performance hit when doing arithmetic using these types?
+
+Yes, for sure, compared to arithmetic operations on native bitfields integer types.
+However, these types are usually faster, and sometimes much faster, for I/O compared to stream inserters and extractors, or to serialization.
+
+* These types are really just byte-holders. Why provide the arithmetic operations at all?
+
+The first goal of the library is to be as close as possible of the usage of bitfields on C/C++. 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.bf();
+
+Rather than:
+
+ int temp( record.bf());
+ ++temp;
+ record.vf() = temp;
+
+[heading Design considerations for Boost.Bitfield]
+
+* Must provide exactly the size and internal bit ordering specified.
+* It is better software engineering if the same implementation works regardless of the CPU endianness. In other words, #ifdefs should be avoided where possible.
+
+[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 aligned bitfields]
+[table
+ [[Name] [kind] [Description] [Result] [Ticket]]
+ [[get] [run] [check getters] [Pass] [#]]
+ [[assign] [run] [check setters] [Pass] [#]]
+ [[flags] [run] [check flags] [Pass] [#]]
+ [[traits] [run] [check the traits of bitfield] [Pass] [#]]
+ [[invert] [run] [check the `operator~`] [Pass] [#]]
+ [[bit] [run] [check the `operator[]`] [Pass] [#]]
+ [[signed] [run] [check signed bitfields] [Pass] [#]]
+]
+[endsect]
+
+
+[endsect]
+[section Appendix F: Tickets]
+
+[endsect]
+
+[/=====================================]
+[section:todo Appendix F: Future plans]
+[/=====================================]
+
+[heading Tasks to do before review]
+
+* Add test with the Boost.Endian types and binary archive.
+
+[heading For later releases]
+
+[*Add bitfields group]
+
+Used to easily manipulate groups of bitfields the same way as does C bitfields, but in a portable manner. Example declaration:
+
+ struct Rgb565
+ {
+ struct red {};
+ struct green {};
+ struct blue {};
+ typedef bitfields<mpl::vector<
+ member<unsigned char, red, 5>,
+ member<unsigned char, green, 6>,
+ member<unsigned char, blue, 5>
+ > > type;
+ };
+
+Example usage:
+
+ Rgb565::type r = make_bitfields<Rgb565::type, 1,2,3>;
+
+ // Write to a bitfield.
+ r.get<Rgb565::red>() = 23;
+ //or
+ r.set<Rgb565::red>(23);
+
+ // Read from a bitfield
+ Rgb565::at<Rgb565::blue>::value_type b = r.get<Rgb565::blue>();
+
+
+Other posibility could be to use unamed bitfields whic are accessed as tuples.
+
+ typedef bitfields_group<mpl::vector_c<5,6,5> > Rgb565;
+ Rgb565 r;
+
+ r.get<0>() = 23;
+ // or
+ r.set<0>(23);
+
+ // Read from a bitfield
+ Rgb565::at<2>::value_type b = r.get<2>();
+
+
+[*Add pointer_plus_bits]
+
+Based on
+
+* The article of Joaquin [@http://bannalia.blogspot.com/2008/11/optimizing-red-black-tree-color-bits.html Optimizing red-black tree color bits],
+* the implementation of Ion [@http://www.boost.org/boost/boost/intrusive/pointer_plus_bits.hpp pointer_plus_bits from Boost.Intrusive ], and
+* [@https://llvm.org/svn/llvm-project/llvm/trunk/include/llvm/ADT/PointerIntPair.h Clang's QualType smart pointer]
+
+This class will allows to use the unsused bits of a pointer to reduce the size of the nodes containing pointers and bits and sometimes improving also the performances.
+
+I have not reached yet the interface I would like to have. For the moment we can do
+
+ typedef pointer_plus_bits<int*,1,bool>::type pint_and_bool;
+
+ int i=0;
+ pint_and_bool v1;
+ ASSERT_EQUALS(v1.pointer(),0);
+ ASSERT_EQUALS(v1.small_int(),false);
+ pint_and_bool v2(&i, true);
+ ASSERT_EQUALS(v2.pointer(),&i);
+ ASSERT_EQUALS(v2.small_int(),true);
+ v1.pointer()=v2.pointer();
+ v1.small_int()=true;
+ ASSERT_EQUALS(v1.pointer(),&i);
+ ASSERT_EQUALS(v1.small_int(),true);
+
+ typedef pointer_plus_bits<
+ pointer_plus_bits<int*,1,bool>::type
+ ,1, bool>::type pint_and_bool_bool
+ pint_and_bool_bool v1;
+ ASSERT_EQUALS(v1.small_int(),false);
+ ASSERT_EQUALS(v1.pointer().get_pointer(),0);
+ ASSERT_EQUALS(v1.get_pointer().get_pointer(),0);
+ ASSERT_EQUALS(v1.get_pointer().small_int(),false);
+
+
+[endsect]
+[endsect]
+
+
+
Added: sandbox/bitfield/libs/bitfield/doc/html/index.html
==============================================================================
--- (empty file)
+++ sandbox/bitfield/libs/bitfield/doc/html/index.html 2011-01-23 09:04:49 EST (Sun, 23 Jan 2011)
@@ -0,0 +1,1558 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
+<title>Toward Boost.Bitfield 0.2.0</title>
+<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
+<link rel="start" href="index.html" title="Toward Boost.Bitfield 0.2.0">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav"></div>
+<div class="article" lang="en">
+<div class="titlepage">
+<div>
+<div><h2 class="title">
+<a name="toward_boost_bitfield"></a>Toward Boost.Bitfield 0.2.0</h2></div>
+<div><div class="authorgroup"><div class="author"><h3 class="author">
+<span class="firstname">Vicente J.</span> <span class="surname">Botet Escriba</span>
+</h3></div></div></div>
+<div><p class="copyright">Copyright © 2009 Vicente J. Botet Escriba</p></div>
+<div><div class="legalnotice">
+<a name="id4987072"></a><p>
+ 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)
+ </p>
+</div></div>
+</div>
+<hr>
+</div>
+<div class="toc">
+<p><b>Table of Contents</b></p>
+<dl>
+<dt><span class="section">Overview</span></dt>
+<dd><dl>
+<dt><span class="section">Motivation</span></dt>
+<dt><span class="section">Description</span></dt>
+</dl></dd>
+<dt><span class="section"> Users'Guide</span></dt>
+<dd><dl>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.users_guide.getting_started"> Getting
+ Started</a></span></dt>
+<dt><span class="section">Tutorial</span></dt>
+<dt><span class="section"> References</span></dt>
+</dl></dd>
+<dt><span class="section">Reference</span></dt>
+<dd><dl>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.reference.integer_bitfield_hpp">
+ Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">/</span><span class="identifier">bitfield</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.reference.bitfield_include_hpp">
+ Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">/</span><span class="identifier">bitfield</span><span class="special">/</span><span class="identifier">include</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.reference.bitfield_hpp"> Header
+ <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">/</span><span class="identifier">bitfield</span><span class="special">/</span><span class="identifier">bitfield</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.reference.bitfield_dcl_hpp"> Header
+ <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">/</span><span class="identifier">bitfield</span><span class="special">/</span><span class="identifier">bitfield_dcl</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.reference.endian_bitfield_value_type_hpp">
+ Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">/</span><span class="identifier">bitfield</span><span class="special">/</span><span class="identifier">endian_bitfield_value_type</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
+</dl></dd>
+<dt><span class="section">Appendices</span></dt>
+<dd><dl>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.appendices.history"> Appendix A:
+ History</a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.appendices.rationale"> Appendix
+ B: Rationale</a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.appendices.implementation"> Appendix
+ C: Implementation Notes</a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.appendices.acknowledgements"> Appendix
+ D: Acknowledgements</a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.appendices.appendix_e__tests">Appendix
+ E: Tests</a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.appendices.appendix_f__tickets">Appendix
+ F: Tickets</a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.appendices.todo"> Appendix F: Future
+ plans</a></span></dt>
+</dl></dd>
+</dl>
+</div>
+<div class="warning"><table border="0" summary="Warning">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../doc/src/images/warning.png"></td>
+<th align="left">Warning</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ Bitfield is not a part of the Boost libraries.
+ </p></td></tr>
+</table></div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="toward_boost_bitfield.overview"></a>Overview
+</h2></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section">Motivation</span></dt>
+<dt><span class="section">Description</span></dt>
+</dl></div>
+<a name="toward_boost_bitfield.overview.how_to_use_this_documentation"></a><h3>
+<a name="id4986988"></a>
+ <a href="index.html#toward_boost_bitfield.overview.how_to_use_this_documentation">How
+ to Use This Documentation</a>
+ </h3>
+<p>
+ This documentation makes use of the following naming and formatting conventions.
+ </p>
+<div class="itemizedlist"><ul type="disc">
+<li>
+ Code is in <code class="computeroutput"><span class="identifier">fixed</span> <span class="identifier">width</span>
+ <span class="identifier">font</span></code> and is syntax-highlighted.
+ </li>
+<li>
+ Replaceable text that you will need to supply is in
+ <em class="replaceable"><code>
+ italics
+ </code></em>
+ .
+ </li>
+<li>
+ Free functions are rendered in the code font followed by (), as in free_function().
+ </li>
+<li>
+ If a name refers to a class template, it is specified like this: <code class="computeroutput"><span class="identifier">class_template</span><span class="special"><></span></code>;
+ that is, it is in code font and its name is followed by <code class="computeroutput"><span class="special"><></span></code>
+ to indicate that it is a class template.
+ </li>
+<li>
+ If a name refers to a function-like macro, it is specified like this: <code class="computeroutput"><span class="identifier">MACRO</span><span class="special">()</span></code>;
+ that is, it is uppercase in code font and its name is followed by <code class="computeroutput"><span class="special">()</span></code> to indicate that it is a function-like
+ macro. Object-like macros appear without the trailing <code class="computeroutput"><span class="special">()</span></code>.
+ </li>
+<li>
+ Names that refer to <span class="emphasis"><em>concepts</em></span> in the generic programming
+ sense are specified in CamelCase.
+ </li>
+</ul></div>
+<div class="note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../doc/src/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ In addition, notes such as this one specify non-essential information that
+ provides additional background or rationale.
+ </p></td></tr>
+</table></div>
+<p>
+ Finally, you can mentally add the following to any code fragments in this document:
+ </p>
+<pre class="programlisting">
+<span class="comment">// Include all of Bitfield files
+</span><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">/</span><span class="identifier">bitfield</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">integer</span><span class="special">;</span>
+</pre>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="toward_boost_bitfield.overview.motivation"></a>Motivation
+</h3></div></div></div>
+<p>
+ In order for an application or a device driver to use the same source code
+ base on both platforms, it must either be endian neutral, or use conditional
+ compilation to select appropriate code modules. A program module is considered
+ endian neutral if it retains its functionality while being ported across
+ platforms of different endianness. In other words, there is no relation between
+ its functionality and the endianness of the platform it is running on. Endianness
+ issues become important when porting the pieces of the application that relate
+ to client communication over a heterogeneous network, persistent data storage
+ on the disk, product tracing (it is important that trace generated on SPARC
+ gets formatted correctly on x86) and other related areas.
+ </p>
+<p>
+ Boost.Endian handles with most of the issues related to the byte ordering,
+ but do not manage the bit ordering. E.g. the following structure has a different
+ layout in big and little endian machines.
+ </p>
+<pre class="programlisting">
+<span class="keyword">struct</span> <span class="identifier">X</span> <span class="special">{</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d00</span><span class="special">:</span><span class="number">1</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d01</span><span class="special">:</span><span class="number">7</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d02</span><span class="special">:</span><span class="number">2</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d03</span><span class="special">:</span><span class="number">6</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d04</span><span class="special">:</span><span class="number">4</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d05</span><span class="special">:</span><span class="number">4</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d06</span><span class="special">:</span><span class="number">1</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d07</span><span class="special">:</span><span class="number">3</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d08</span><span class="special">:</span><span class="number">4</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ In order to make this structure endian neutral, we need to use conditional
+ compilation, and swap on byte level of the fields
+ </p>
+<pre class="programlisting">
+<span class="keyword">struct</span> <span class="identifier">X</span> <span class="special">{</span>
+<span class="preprocessor">#if</span> <span class="identifier">__BYTE_ORDER</span> <span class="special">==</span> <span class="identifier">__BIG_ENDIAN</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d00</span><span class="special">:</span><span class="number">1</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d01</span><span class="special">:</span><span class="number">7</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d02</span><span class="special">:</span><span class="number">2</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d03</span><span class="special">:</span><span class="number">6</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d04</span><span class="special">:</span><span class="number">4</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d05</span><span class="special">:</span><span class="number">4</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d06</span><span class="special">:</span><span class="number">1</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d07</span><span class="special">:</span><span class="number">3</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d08</span><span class="special">:</span><span class="number">4</span><span class="special">;</span>
+<span class="preprocessor">#else</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d01</span><span class="special">:</span><span class="number">7</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d00</span><span class="special">:</span><span class="number">1</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d03</span><span class="special">:</span><span class="number">6</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d02</span><span class="special">:</span><span class="number">2</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d05</span><span class="special">:</span><span class="number">4</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d04</span><span class="special">:</span><span class="number">4</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d08</span><span class="special">:</span><span class="number">4</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d07</span><span class="special">:</span><span class="number">3</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d06</span><span class="special">:</span><span class="number">1</span><span class="special">;</span>
+<span class="preprocessor">#endif</span>
+<span class="special">}</span>
+</pre>
+<p>
+ The preceding technique can be applied as far as the bitfield is contained
+ on a byte boundary. But for bitfields using several bytes as in
+ </p>
+<pre class="programlisting">
+<span class="keyword">struct</span> <span class="identifier">X</span> <span class="special">{</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d00</span><span class="special">:</span><span class="number">11</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d01</span><span class="special">:</span><span class="number">21</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ there is no way using conditional compilation to adapt the structure and
+ preserve the fields.
+ </p>
+<p>
+ Two approaches can be considered:
+ </p>
+<a name="toward_boost_bitfield.overview.motivation.decompose_the_fields_not_defined_on_a_byte_boundary_on_several_bitfield_defined_on_a_byte_boundary"></a><h4>
+<a name="id4945430"></a>
+ <a href="index.html#toward_boost_bitfield.overview.motivation.decompose_the_fields_not_defined_on_a_byte_boundary_on_several_bitfield_defined_on_a_byte_boundary">Decompose
+ the fields not defined on a byte boundary on several bitfield defined on
+ a byte boundary</a>
+ </h4>
+<pre class="programlisting">
+<span class="keyword">struct</span> <span class="identifier">X</span> <span class="special">{</span>
+<span class="preprocessor">#if</span> <span class="identifier">__BYTE_ORDER</span> <span class="special">==</span> <span class="identifier">__BIG_ENDIAN</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d00_b0</span><span class="special">:</span><span class="number">8</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d00_b1</span><span class="special">:</span><span class="number">3</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d01_b0</span><span class="special">:</span><span class="number">5</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d01_b1</span><span class="special">:</span><span class="number">8</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d01_b2</span><span class="special">:</span><span class="number">8</span><span class="special">;</span>
+<span class="preprocessor">#else</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d01_b2</span><span class="special">:</span><span class="number">8</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d01_b1</span><span class="special">:</span><span class="number">8</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d01_b0</span><span class="special">:</span><span class="number">5</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d00_b1</span><span class="special">:</span><span class="number">3</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d00_b0</span><span class="special">:</span><span class="number">8</span><span class="special">;</span>
+<span class="preprocessor">#endif</span>
+<span class="special">};</span>
+</pre>
+<p>
+ and define a way to access the bitfield information of the ENDIAN_UNSAFE
+ structure. This library do not use this apprach.
+ </p>
+<a name="toward_boost_bitfield.overview.motivation.replace_the_bitfields_by_the_integer_type"></a><h4>
+<a name="id4942433"></a>
+ <a href="index.html#toward_boost_bitfield.overview.motivation.replace_the_bitfields_by_the_integer_type">Replace
+ the bitfields by the integer type</a>
+ </h4>
+<p>
+ When it is possible, a suggestion would be to transform the bitfields into
+ integers, as follows:
+ </p>
+<pre class="programlisting">
+<span class="keyword">struct</span> <span class="identifier">X</span> <span class="special">{</span>
+<span class="preprocessor">#ifdef</span> <span class="identifier">ATRIUM_PORTABLE</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d0</span><span class="special">;</span>
+<span class="preprocessor">#else</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d00</span><span class="special">:</span><span class="number">11</span><span class="special">;</span> <span class="comment">/* ENDIAN_UNSAFE */</span>
+ <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">d01</span><span class="special">:</span><span class="number">21</span><span class="special">;</span> <span class="comment">/* ENDIAN_UNSAFE */</span>
+<span class="preprocessor">#endif</span>
+<span class="special">};</span>
+</pre>
+<p>
+ and define a way to access the bitfield information.
+ </p>
+<p>
+ When the structure is used by a C++ program, all the uses of the bit fields
+ (d00 and d01) could be replaced by an inline function, so
+ </p>
+<pre class="programlisting">
+<span class="identifier">y</span> <span class="special">=</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">d00</span><span class="special">;</span>
+</pre>
+<p>
+ could be replaced by
+ </p>
+<pre class="programlisting">
+<span class="identifier">y</span> <span class="special">=</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">d00</span><span class="special">();</span>
+</pre>
+<p>
+ or
+ </p>
+<pre class="programlisting">
+<span class="identifier">y</span> <span class="special">=</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">get_d00</span><span class="special">();</span>
+</pre>
+<p>
+ and x.d00= y;
+ </p>
+<p>
+ could be replaced by
+ </p>
+<pre class="programlisting">
+<span class="identifier">x</span><span class="special">.</span><span class="identifier">d00</span><span class="special">()=</span> <span class="identifier">y</span><span class="special">;</span>
+</pre>
+<p>
+ or
+ </p>
+<pre class="programlisting">
+<span class="identifier">x</span><span class="special">.</span><span class="identifier">set_d00</span><span class="special">(</span><span class="identifier">y</span><span class="special">)</span>
+</pre>
+<p>
+ where
+ </p>
+<pre class="programlisting">
+<span class="keyword">struct</span> <span class="identifier">X</span> <span class="special">{</span>
+ <span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">uint_32</span> <span class="identifier">storage_type</span><span class="special">;</span>
+ <span class="identifier">storage_type</span> <span class="identifier">d0</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">value_type</span><span class="special">;</span>
+ <span class="identifier">BOOST_BITFIELD_DCL</span><span class="special">(</span><span class="identifier">storage_type</span><span class="special">,</span> <span class="identifier">d0</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">int</span><span class="special">,</span> <span class="identifier">d00</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="number">10</span><span class="special">);</span>
+ <span class="identifier">BOOST_BITFIELD_DCL</span><span class="special">(</span><span class="identifier">storage_type</span><span class="special">,</span> <span class="identifier">d0</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">int</span><span class="special">,</span> <span class="identifier">d01</span><span class="special">,</span> <span class="number">11</span><span class="special">,</span> <span class="number">31</span><span class="special">);</span>
+<span class="special">};</span>
+</pre>
+<p>
+ The goal of Boost.Bitfield is to make possible this simple portable translation.
+ </p>
+<p>
+ If we want to write the storage type to a binary archive we need to precise
+ which will be the endian format of the storage type. For this end, you can
+ use any of the endian types provided by the Boost.Endian library. If the
+ storage is big you can declare
+ </p>
+<pre class="programlisting">
+<span class="keyword">struct</span> <span class="identifier">X</span> <span class="special">{</span>
+ <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ubig_32</span> <span class="identifier">storage_type</span><span class="special">;</span>
+ <span class="identifier">storage_type</span> <span class="identifier">d0</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">value_type</span><span class="special">;</span>
+ <span class="identifier">BOOST_BITFIELD_DCL</span><span class="special">(</span><span class="identifier">storage_type</span><span class="special">,</span> <span class="identifier">d0</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">int</span><span class="special">,</span> <span class="identifier">d00</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="number">10</span><span class="special">);</span>
+ <span class="identifier">BOOST_BITFIELD_DCL</span><span class="special">(</span><span class="identifier">storage_type</span><span class="special">,</span> <span class="identifier">d0</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">int</span><span class="special">,</span> <span class="identifier">d01</span><span class="special">,</span> <span class="number">11</span><span class="special">,</span> <span class="number">31</span><span class="special">);</span>
+<span class="special">};</span>
+</pre>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="toward_boost_bitfield.overview.description"></a>Description
+</h3></div></div></div>
+<p>
+ Portable bitfields.
+ </p>
+<p>
+ The main source of inspiration of this library was Boost.Bitfield from Emile
+ Cormier.
+ </p>
+<p>
+ <span class="bold"><strong>Boost.Bitfield</strong></span> provides:
+ </p>
+<div class="itemizedlist"><ul type="disc">
+<li>
+ a generic bitfield traits class providing generic getter and setter.
+ </li>
+<li>
+ a BOOST_BITFIELD_DCL macro making easier the definition of the bitfield
+ helper type and the bitfield getter and setter functions.
+ </li>
+</ul></div>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="toward_boost_bitfield.users_guide"></a> Users'Guide
+</h2></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.users_guide.getting_started"> Getting
+ Started</a></span></dt>
+<dd><dl><dt><span class="section"><a href="index.html#toward_boost_bitfield.users_guide.getting_started.install">
+ Installing Bitfield</a></span></dt></dl></dd>
+<dt><span class="section">Tutorial</span></dt>
+<dd><dl>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.users_guide.tutorial.declaring_a_storage_variable">Declaring
+ a storage variable</a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.users_guide.tutorial.bitfieds_helper_classes_and_bitfield_accessors">Bitfieds
+ helper classes and bitfield accessors</a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.users_guide.tutorial.using_macros_to_declare_portable_bitfields_">Using
+ macros to declare portable bitfields </a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.users_guide.tutorial.using_bitfield_getters_and_setters">Using
+ bitfield getters and setters</a></span></dt>
+</dl></dd>
+<dt><span class="section"> References</span></dt>
+</dl></div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="toward_boost_bitfield.users_guide.getting_started"></a><a href="index.html#toward_boost_bitfield.users_guide.getting_started" title=" Getting
+ Started"> Getting
+ Started</a>
+</h3></div></div></div>
+<div class="toc"><dl><dt><span class="section"><a href="index.html#toward_boost_bitfield.users_guide.getting_started.install">
+ Installing Bitfield</a></span></dt></dl></div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="toward_boost_bitfield.users_guide.getting_started.install"></a><a href="index.html#toward_boost_bitfield.users_guide.getting_started.install" title="
+ Installing Bitfield">
+ Installing Bitfield</a>
+</h4></div></div></div>
+<a name="toward_boost_bitfield.users_guide.getting_started.install.getting_boost_bitfield"></a><h5>
+<a name="id4943415"></a>
+ <a href="index.html#toward_boost_bitfield.users_guide.getting_started.install.getting_boost_bitfield">Getting
+ Boost.Bitfield</a>
+ </h5>
+<p>
+ You can get the last stable release of Boost.Bitfield by downloading <code class="literal">bitfield.zip</code>
+ from the <a href="http://www.boost-consulting.com/vault/index.php?directory=Endianess%20Programming" target="_top">Boost
+ Vault</a>
+ </p>
+<p>
+ You can also access the latest (unstable?) state from the <a href="https://svn.boost.org/svn/boost/sandbox/bitfield" target="_top">Boost
+ Sandbox</a>.
+ </p>
+<a name="toward_boost_bitfield.users_guide.getting_started.install.building_boost_bitfield"></a><h5>
+<a name="id4943464"></a>
+ <a href="index.html#toward_boost_bitfield.users_guide.getting_started.install.building_boost_bitfield">Building
+ Boost.Bitfield</a>
+ </h5>
+<p>
+ <span class="bold"><strong>Boost.Bitfield</strong></span> is a header only library,
+ so no need to compile anything.
+ </p>
+<a name="toward_boost_bitfield.users_guide.getting_started.install.requirements"></a><h5>
+<a name="id4943496"></a>
+ Requirements
+ </h5>
+<p>
+ <span class="bold"><strong>Boost.Bitfield</strong></span> 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).
+ </p>
+<a name="toward_boost_bitfield.users_guide.getting_started.install.exceptions_safety"></a><h5>
+<a name="id4943529"></a>
+ <a href="index.html#toward_boost_bitfield.users_guide.getting_started.install.exceptions_safety">Exceptions
+ safety</a>
+ </h5>
+<p>
+ All functions in the library are exception-neutral, providing the strong
+ exception safety guarantee.
+ </p>
+<a name="toward_boost_bitfield.users_guide.getting_started.install.thread_safety"></a><h5>
+<a name="id4943556"></a>
+ <a href="index.html#toward_boost_bitfield.users_guide.getting_started.install.thread_safety">Thread
+ safety</a>
+ </h5>
+<p>
+ All functions in the library are thread-unsafe except when noted explicitly.
+ </p>
+<a name="toward_boost_bitfield.users_guide.getting_started.install.tested_compilers"></a><h5>
+<a name="id4943582"></a>
+ <a href="index.html#toward_boost_bitfield.users_guide.getting_started.install.tested_compilers">Tested
+ compilers</a>
+ </h5>
+<p>
+ <span class="bold"><strong>Boost.Bitfield</strong></span> should work with an C++03
+ conforming compiler. The current version has been tested on:
+ </p>
+<p>
+ Windows with
+ </p>
+<div class="itemizedlist"><ul type="disc"><li>
+ MSVC 10.0
+ </li></ul></div>
+<p>
+ Cygwin 1.5
+ </p>
+<div class="itemizedlist"><ul type="disc"><li>
+ GCC 3.4.4
+ </li></ul></div>
+<p>
+ Cygwin 1.7
+ </p>
+<div class="itemizedlist"><ul type="disc"><li>
+ GCC 4.3.2
+ </li></ul></div>
+<p>
+ MinGW with
+ </p>
+<div class="itemizedlist"><ul type="disc">
+<li>
+ GCC 4.4.0
+ </li>
+<li>
+ GCC 4.5.0
+ </li>
+<li>
+ GCC 4.5.0 c++0x
+ </li>
+<li>
+ GCC 4.6.0
+ </li>
+<li>
+ GCC 4.6.0 c++0x
+ </li>
+</ul></div>
+<div class="note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../doc/src/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ Please let us know how this works on other platforms/compilers.
+ </p></td></tr>
+</table></div>
+<div class="note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../doc/src/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ Please send any questions, comments and bug reports to boost <at>
+ lists <dot> boost <dot> org.
+ </p></td></tr>
+</table></div>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="toward_boost_bitfield.users_guide.tutorial"></a>Tutorial
+</h3></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.users_guide.tutorial.declaring_a_storage_variable">Declaring
+ a storage variable</a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.users_guide.tutorial.bitfieds_helper_classes_and_bitfield_accessors">Bitfieds
+ helper classes and bitfield accessors</a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.users_guide.tutorial.using_macros_to_declare_portable_bitfields_">Using
+ macros to declare portable bitfields </a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.users_guide.tutorial.using_bitfield_getters_and_setters">Using
+ bitfield getters and setters</a></span></dt>
+</dl></div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="toward_boost_bitfield.users_guide.tutorial.declaring_a_storage_variable"></a><a href="index.html#toward_boost_bitfield.users_guide.tutorial.declaring_a_storage_variable" title="Declaring
+ a storage variable">Declaring
+ a storage variable</a>
+</h4></div></div></div>
+<p>
+ The first thing to do is to declare a storage type able to store all the
+ bitfields. In the following example we want to stor bits for the RGB encoding,
+ so 16 bits is enough.
+ </p>
+<pre class="programlisting">
+<span class="keyword">struct</span> <span class="identifier">Rgb565</span>
+<span class="special">{</span>
+ <span class="keyword">typedef</span> <span class="identifier">ubig16_t</span> <span class="identifier">storage_type</span><span class="special">;</span>
+ <span class="identifier">storage_type</span> <span class="identifier">storage</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="toward_boost_bitfield.users_guide.tutorial.bitfieds_helper_classes_and_bitfield_accessors"></a><a href="index.html#toward_boost_bitfield.users_guide.tutorial.bitfieds_helper_classes_and_bitfield_accessors" title="Bitfieds
+ helper classes and bitfield accessors">Bitfieds
+ helper classes and bitfield accessors</a>
+</h4></div></div></div>
+<a name="toward_boost_bitfield.users_guide.tutorial.bitfieds_helper_classes_and_bitfield_accessors.declaring_a_bitfield_helper_type"></a><h5>
+<a name="id4996883"></a>
+ <a href="index.html#toward_boost_bitfield.users_guide.tutorial.bitfieds_helper_classes_and_bitfield_accessors.declaring_a_bitfield_helper_type">Declaring
+ a bitfield helper type</a>
+ </h5>
+<p>
+ For each bitfields we need to declare a type that knows about the bitfield
+ traits of the bitfield.
+ </p>
+<pre class="programlisting">
+<span class="keyword">struct</span> <span class="identifier">Rgb565</span>
+<span class="special">{</span>
+ <span class="comment">//...
+</span> <span class="keyword">typedef</span> <span class="identifier">bitfield_traits</span><span class="special"><</span><span class="identifier">storage_type</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="number">4</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">char</span><span class="special">></span> <span class="identifier">red_type</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<a name="toward_boost_bitfield.users_guide.tutorial.bitfieds_helper_classes_and_bitfield_accessors.bitfield_getters"></a><h5>
+<a name="id4997011"></a>
+ <a href="index.html#toward_boost_bitfield.users_guide.tutorial.bitfieds_helper_classes_and_bitfield_accessors.bitfield_getters">bitfield
+ getters</a>
+ </h5>
+<p>
+ Now we are ready to define the getter of this bitfield respect to the storage
+ variable. My prefered form is just to name the getter function as the type,
+ others will prefer the get_field() form.
+ </p>
+<pre class="programlisting">
+<span class="keyword">struct</span> <span class="identifier">Rgb565</span>
+<span class="special">{</span>
+ <span class="comment">//...
+</span> <span class="identifier">red_type</span><span class="special">::</span><span class="identifier">value</span><span class="special">::</span><span class="identifier">value_type</span> <span class="identifier">red</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">red_type</span><span class="special">::</span><span class="identifier">value</span><span class="special">(</span><span class="identifier">storage</span><span class="special">).</span><span class="identifier">get</span><span class="special">();</span> <span class="special">}</span>
+ <span class="identifier">red_type</span><span class="special">::</span><span class="identifier">value</span><span class="special">::</span><span class="identifier">value_type</span> <span class="identifier">get_red</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">red_type</span><span class="special">::</span><span class="identifier">value</span><span class="special">(</span><span class="identifier">storage</span><span class="special">).</span><span class="identifier">get</span><span class="special">();</span> <span class="special">}</span>
+<span class="special">};</span>
+</pre>
+<a name="toward_boost_bitfield.users_guide.tutorial.bitfieds_helper_classes_and_bitfield_accessors.bitfield_setters"></a><h5>
+<a name="id4997245"></a>
+ <a href="index.html#toward_boost_bitfield.users_guide.tutorial.bitfieds_helper_classes_and_bitfield_accessors.bitfield_setters">bitfield
+ setters</a>
+ </h5>
+<p>
+ There are two variants for the setter. My prefered form is just to name
+ the setter function as the type and return a reference able to support
+ assignations. The other is the traditional set_field() taking the new value
+ as parameter.
+ </p>
+<pre class="programlisting">
+<span class="keyword">struct</span> <span class="identifier">Rgb565</span>
+<span class="special">{</span>
+ <span class="comment">//...
+</span> <span class="identifier">red_type</span><span class="special">::</span><span class="identifier">reference</span> <span class="identifier">red</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">red_type</span><span class="special">::</span><span class="identifier">reference</span><span class="special">(</span><span class="identifier">storage</span><span class="special">);</span> <span class="special">}</span>
+ <span class="keyword">void</span> <span class="identifier">set_red</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="keyword">char</span> <span class="identifier">val</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">red_type</span><span class="special">::</span><span class="identifier">reference</span><span class="special">(</span><span class="identifier">storage</span><span class="special">).</span><span class="identifier">set</span><span class="special">(</span><span class="identifier">val</span><span class="special">);</span> <span class="special">}</span>
+<span class="special">};</span>
+</pre>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="toward_boost_bitfield.users_guide.tutorial.using_macros_to_declare_portable_bitfields_"></a><a href="index.html#toward_boost_bitfield.users_guide.tutorial.using_macros_to_declare_portable_bitfields_" title="Using
+ macros to declare portable bitfields ">Using
+ macros to declare portable bitfields </a>
+</h4></div></div></div>
+<p>
+ All these stuf can be done at once using the BOOST_BITFIELD_DCL macro as
+ follows.
+ </p>
+<pre class="programlisting">
+<span class="keyword">struct</span> <span class="identifier">Rgb565</span>
+<span class="special">{</span>
+ <span class="keyword">typedef</span> <span class="keyword">volatile</span> <span class="identifier">uint16_t</span> <span class="identifier">storage_type</span><span class="special">;</span>
+ <span class="identifier">storage_type</span> <span class="identifier">storage</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">volatile</span> <span class="identifier">uint16_t</span> <span class="identifier">value_type</span><span class="special">;</span>
+ <span class="identifier">BOOST_BITFIELD_DCL</span><span class="special">(</span><span class="identifier">storage_type</span><span class="special">,</span> <span class="identifier">storage</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">char</span><span class="special">,</span> <span class="identifier">red</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="number">4</span><span class="special">);</span>
+ <span class="identifier">BOOST_BITFIELD_DCL</span><span class="special">(</span><span class="identifier">storage_type</span><span class="special">,</span> <span class="identifier">storage</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">char</span><span class="special">,</span> <span class="identifier">green</span><span class="special">,</span> <span class="number">5</span><span class="special">,</span> <span class="number">10</span><span class="special">);</span>
+ <span class="identifier">BOOST_BITFIELD_DCL</span><span class="special">(</span><span class="identifier">storage_type</span><span class="special">,</span> <span class="identifier">storage</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">char</span><span class="special">,</span> <span class="identifier">blue</span><span class="special">,</span> <span class="number">11</span><span class="special">,</span><span class="number">15</span><span class="special">);</span>
+<span class="special">};</span>
+</pre>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="toward_boost_bitfield.users_guide.tutorial.using_bitfield_getters_and_setters"></a><a href="index.html#toward_boost_bitfield.users_guide.tutorial.using_bitfield_getters_and_setters" title="Using
+ bitfield getters and setters">Using
+ bitfield getters and setters</a>
+</h4></div></div></div>
+<p>
+ Next follows some examples of how these bitfields can be used.
+ </p>
+<pre class="programlisting">
+<span class="identifier">Rgb565</span> <span class="identifier">r</span><span class="special">;</span>
+<span class="identifier">r</span><span class="special">.</span><span class="identifier">storage</span><span class="special">=</span> <span class="number">0xffff</span><span class="special">;</span>
+
+<span class="comment">// Write to a bitfield. Note that parenthesis are needed around the bitfield so
+</span><span class="identifier">r</span><span class="special">.</span><span class="identifier">red</span><span class="special">()</span> <span class="special">=</span> <span class="number">23</span><span class="special">;</span>
+
+<span class="comment">// Read from a bitfield
+</span><span class="identifier">Rgb565</span><span class="special">::</span><span class="identifier">value_type</span> <span class="identifier">b</span> <span class="special">=</span> <span class="identifier">r</span><span class="special">.</span><span class="identifier">blue</span><span class="special">();</span>
+
+<span class="comment">// Access a bit within a bit field
+</span><span class="keyword">bool</span> <span class="identifier">bit</span> <span class="special">=</span> <span class="identifier">r</span><span class="special">.</span><span class="identifier">blue</span><span class="special">()[</span><span class="number">3</span><span class="special">];</span>
+</pre>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="toward_boost_bitfield.users_guide.ext_references"></a> References
+</h3></div></div></div>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Boost.Endian</span></dt>
+<dd><p>
+ general integer-like byte-holder binary types with explicit control over
+ byte order, value type, size, and alignment from Beman Dawes
+ </p></dd>
+</dl>
+</div>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="toward_boost_bitfield.reference"></a>Reference
+</h2></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.reference.integer_bitfield_hpp">
+ Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">/</span><span class="identifier">bitfield</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.reference.bitfield_include_hpp">
+ Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">/</span><span class="identifier">bitfield</span><span class="special">/</span><span class="identifier">include</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.reference.bitfield_hpp"> Header
+ <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">/</span><span class="identifier">bitfield</span><span class="special">/</span><span class="identifier">bitfield</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
+<dd><dl>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.reference.bitfield_hpp.bitfield_value_type">
+ Metafunction <code class="computeroutput"><span class="identifier">bitfield_value_type</span><span class="special"><></span></code></a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.reference.bitfield_hpp.bitfield">
+ Template class <code class="computeroutput"><span class="identifier">bitfield</span><span class="special"><></span></code></a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.reference.bitfield_hpp.bitfield_traits">
+ Template class <code class="computeroutput"><span class="identifier">bitfield_traits</span><span class="special"><></span></code></a></span></dt>
+</dl></dd>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.reference.bitfield_dcl_hpp"> Header
+ <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">/</span><span class="identifier">bitfield</span><span class="special">/</span><span class="identifier">bitfield_dcl</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
+<dd><dl><dt><span class="section"><a href="index.html#toward_boost_bitfield.reference.bitfield_dcl_hpp.BOOST_BITFIELD_DCL">
+ Macro <code class="computeroutput"><span class="identifier">BOOST_BITFIELD_DCL</span></code></a></span></dt></dl></dd>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.reference.endian_bitfield_value_type_hpp">
+ Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">/</span><span class="identifier">bitfield</span><span class="special">/</span><span class="identifier">endian_bitfield_value_type</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
+</dl></div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="toward_boost_bitfield.reference.integer_bitfield_hpp"></a><a href="index.html#toward_boost_bitfield.reference.integer_bitfield_hpp" title="
+ Header <boost/integer/bitfield.hpp>">
+ Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">/</span><span class="identifier">bitfield</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a>
+</h3></div></div></div>
+<p>
+ Include all the Boost.Bitfields header files
+ </p>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="toward_boost_bitfield.reference.bitfield_include_hpp"></a><a href="index.html#toward_boost_bitfield.reference.bitfield_include_hpp" title="
+ Header <boost/integer/bitfield/include.hpp>">
+ Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">/</span><span class="identifier">bitfield</span><span class="special">/</span><span class="identifier">include</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a>
+</h3></div></div></div>
+<p>
+ Include all the Boost.Bitfields header files
+ </p>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="toward_boost_bitfield.reference.bitfield_hpp"></a><a href="index.html#toward_boost_bitfield.reference.bitfield_hpp" title=" Header
+ <boost/integer/bitfield/bitfield.hpp>"> Header
+ <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">/</span><span class="identifier">bitfield</span><span class="special">/</span><span class="identifier">bitfield</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a>
+</h3></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.reference.bitfield_hpp.bitfield_value_type">
+ Metafunction <code class="computeroutput"><span class="identifier">bitfield_value_type</span><span class="special"><></span></code></a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.reference.bitfield_hpp.bitfield">
+ Template class <code class="computeroutput"><span class="identifier">bitfield</span><span class="special"><></span></code></a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.reference.bitfield_hpp.bitfield_traits">
+ Template class <code class="computeroutput"><span class="identifier">bitfield_traits</span><span class="special"><></span></code></a></span></dt>
+</dl></div>
+<p>
+ This is the main file of Boost.Bitfield, which includes the definition of
+ the bitfield<> class.
+ </p>
+<pre class="programlisting">
+<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">integer</span> <span class="special">{</span>
+ <span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">></span>
+ <span class="keyword">struct</span> <span class="identifier">bitfield_default_value_type</span><span class="special">;</span>
+
+ <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size</span><span class="special">,</span> <span class="keyword">class</span><span class="special">,</span> <span class="keyword">bool</span><span class="special">,</span> <span class="keyword">class</span><span class="special">></span>
+ <span class="keyword">class</span> <span class="identifier">bitfield</span><span class="special">;</span>
+
+ <span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">STORAGE_TYPE</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">L</span>
+ <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">VALUE_TYPE</span><span class="special">=</span><span class="identifier">bitfield_default_value_type</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">STORAGE_TYPE</span><span class="special">::</span><span class="identifier">type</span><span class="special">></span>
+ <span class="special">></span>
+ <span class="keyword">struct</span> <span class="identifier">bitfield_traits</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="toward_boost_bitfield.reference.bitfield_hpp.bitfield_value_type"></a><a href="index.html#toward_boost_bitfield.reference.bitfield_hpp.bitfield_value_type" title="
+ Metafunction bitfield_value_type<>">
+ Metafunction <code class="computeroutput"><span class="identifier">bitfield_value_type</span><span class="special"><></span></code></a>
+</h4></div></div></div>
+<p>
+ The default value type associated to an storage type is the storage type
+ itself.
+ </p>
+<pre class="programlisting">
+<span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">></span>
+<span class="keyword">struct</span> <span class="identifier">bitfield_value_type</span> <span class="special">{</span>
+ <span class="keyword">typedef</span> <span class="identifier">T</span> <span class="identifier">type</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ The user could need to specialize this metafunction for some specific types,
+ as for example for types comming from the Boost.Endian library.
+ </p>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="toward_boost_bitfield.reference.bitfield_hpp.bitfield"></a><a href="index.html#toward_boost_bitfield.reference.bitfield_hpp.bitfield" title="
+ Template class bitfield<>">
+ Template class <code class="computeroutput"><span class="identifier">bitfield</span><span class="special"><></span></code></a>
+</h4></div></div></div>
+<p>
+ The <code class="computeroutput"><span class="identifier">bitfield</span></code> class is a
+ wrapper to an storage type that allows to get/`set a bitfield of a given
+ value type defined by the first and last bit that the bitfield occupes
+ in the storage type. It defines the conversion to the bitfield value type
+ as weel as all the arithmetic assignement operators.
+ </p>
+<p>
+ This template class behaves as a reference to a bit field. Note that C/C++
+ do not allows to take directly the address of a bit field.
+ </p>
+<pre class="programlisting">
+<span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">STORAGE_TYPE</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size</span> <span class="identifier">F</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size</span> <span class="identifier">L</span>
+ <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">VALUE_TYPE</span><span class="special">=</span><span class="keyword">typename</span> <span class="identifier">bitfield_value_type</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">STORAGE_TYPE</span><span class="special">::</span><span class="identifier">type</span><span class="special">></span>
+ <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">REFERENCE_TYPE</span><span class="special">=</span><span class="identifier">STORAGE_TYPE</span><span class="special">&></span>
+<span class="keyword">class</span> <span class="identifier">bitfield</span> <span class="special">{</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="comment">//! Reference type of the word occupied by the bitfield
+</span> <span class="keyword">typedef</span> <span class="identifier">REFERENCE_TYPE</span> <span class="identifier">reference_type</span><span class="special">;</span>
+ <span class="comment">//! Value type of the bitfield itself
+</span> <span class="keyword">typedef</span> <span class="identifier">VALUE_TYPE</span> <span class="identifier">value_type</span><span class="special">;</span>
+ <span class="comment">//! storage type of the bitfield support
+</span> <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">reference_traits</span><span class="special"><</span><span class="identifier">REFERENCE_TYPE</span><span class="special">>::</span><span class="identifier">value_type</span> <span class="identifier">storage_type</span><span class="special">;</span>
+
+ <span class="comment">//! Useful constants
+</span> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">FIRST</span><span class="special">;</span> <span class="comment">//!< Position of the first bit
+</span> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">LAST</span><span class="special">;</span> <span class="comment">//!< Position of the last bit
+</span> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">WIDTH</span><span class="special">;</span> <span class="comment">//!< Width in bits of the bitfield
+</span> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">VAL_MASK</span><span class="special">;</span> <span class="comment">//!< Mask applied against assigned values
+</span> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">FIELD_MASK</span><span class="special">;</span> <span class="comment">//!< Mask of the field's bit positions
+</span>
+ <span class="keyword">static</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">first</span><span class="special">();</span>
+ <span class="keyword">static</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">last</span><span class="special">();</span>
+ <span class="keyword">static</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">width</span><span class="special">();</span>
+ <span class="keyword">static</span> <span class="identifier">storage_type</span> <span class="identifier">val_mask</span><span class="special">();</span>
+ <span class="keyword">static</span> <span class="identifier">storage_type</span> <span class="identifier">field_mask</span><span class="special">();</span>
+
+ <span class="comment">//! deleted because a reference is nedeed
+</span> <span class="identifier">bitfield</span><span class="special">()</span> <span class="special">=</span> <span class="keyword">delete</span><span class="special">;</span>
+ <span class="comment">//! explicit constructor from a reference
+</span> <span class="keyword">explicit</span> <span class="identifier">bitfield</span><span class="special">(</span><span class="identifier">reference_type</span> <span class="identifier">field</span><span class="special">);</span>
+
+ <span class="comment">//! Assignment from a value type
+</span> <span class="identifier">bitfield</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">=(</span><span class="identifier">value_type</span> <span class="identifier">val</span><span class="special">);</span>
+
+ <span class="comment">//! value_type implicit conversion
+</span> <span class="keyword">operator</span> <span class="identifier">value_type</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
+
+ <span class="comment">//! value_type explicit getter
+</span> <span class="identifier">value_type</span> <span class="identifier">get</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
+
+ <span class="comment">//! Returns the negative of the bitfield value.
+</span> <span class="comment">// this must be modified on the case of signed value_type
+</span> <span class="identifier">value_type</span> <span class="keyword">operator</span><span class="special">~()</span> <span class="keyword">const</span><span class="special">;</span>
+
+ <span class="identifier">bit_reference_type</span> <span class="keyword">operator</span><span class="special">[](</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">index</span><span class="special">);</span>
+
+ <span class="identifier">bit_const_reference_type</span> <span class="keyword">operator</span><span class="special">[](</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">index</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
+
+ <span class="comment">//! Returns the current bitfield value as bit flags.
+</span> <span class="comment">/*! The returned bit flags can be ORed with other bit flags. */</span>
+ <span class="identifier">storage_type</span> <span class="identifier">flags</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
+
+ <span class="comment">//! Returns the current bitfield value as bit flags.
+</span> <span class="comment">/*! The returned bit flags can be ORed with other bit flags. */</span>
+ <span class="keyword">static</span> <span class="identifier">storage_type</span> <span class="identifier">flags</span><span class="special">(</span><span class="identifier">value_type</span> <span class="identifier">val</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
+
+ <span class="comment">//! Arithmetic-assign operators
+</span> <span class="identifier">bitfield</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">++();</span>
+ <span class="identifier">value_type</span> <span class="keyword">operator</span><span class="special">++(</span><span class="keyword">int</span><span class="special">);</span>
+
+ <span class="identifier">bitfield</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">--();</span>
+ <span class="identifier">value_type</span> <span class="keyword">operator</span><span class="special">--(</span><span class="keyword">int</span><span class="special">);</span>
+
+ <span class="identifier">bitfield</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">+=(</span><span class="identifier">value_type</span> <span class="identifier">rhs</span><span class="special">);</span>
+ <span class="identifier">bitfield</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">-=(</span><span class="identifier">value_type</span> <span class="identifier">rhs</span><span class="special">);</span>
+
+ <span class="identifier">bitfield</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">*=(</span><span class="identifier">value_type</span> <span class="identifier">rhs</span><span class="special">);</span>
+ <span class="identifier">bitfield</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">/=(</span><span class="identifier">value_type</span> <span class="identifier">rhs</span><span class="special">);</span>
+ <span class="identifier">bitfield</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">%=(</span><span class="identifier">value_type</span> <span class="identifier">rhs</span><span class="special">);</span>
+
+ <span class="identifier">bitfield</span><span class="special">&</span> <span class="keyword">operator</span><span class="special"><<=(</span><span class="keyword">int</span> <span class="identifier">rhs</span><span class="special">);</span>
+ <span class="identifier">bitfield</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">>>=(</span><span class="keyword">int</span> <span class="identifier">rhs</span><span class="special">);</span>
+
+ <span class="identifier">bitfield</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">&=(</span><span class="identifier">value_type</span> <span class="identifier">rhs</span><span class="special">);</span>
+ <span class="identifier">bitfield</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">|=(</span><span class="identifier">value_type</span> <span class="identifier">rhs</span><span class="special">);</span>
+ <span class="identifier">bitfield</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">^=(</span><span class="identifier">value_type</span> <span class="identifier">rhs</span><span class="special">);</span>
+<span class="special">};</span>
+</pre>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="toward_boost_bitfield.reference.bitfield_hpp.bitfield_traits"></a><a href="index.html#toward_boost_bitfield.reference.bitfield_hpp.bitfield_traits" title="
+ Template class bitfield_traits<>">
+ Template class <code class="computeroutput"><span class="identifier">bitfield_traits</span><span class="special"><></span></code></a>
+</h4></div></div></div>
+<p>
+ This traits class defies two traits:
+ </p>
+<div class="itemizedlist"><ul type="disc">
+<li>
+ reference: used to modify a bitfield
+ </li>
+<li>
+ value: used to get the value of a bitset
+ </li>
+</ul></div>
+<pre class="programlisting">
+<span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">STORAGE_TYPE</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">L</span>
+ <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">VALUE_TYPE</span><span class="special">=</span><span class="keyword">typename</span> <span class="identifier">bitfield_value_type</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">STORAGE_TYPE</span><span class="special">::</span><span class="identifier">type</span><span class="special">></span>
+<span class="special">></span>
+<span class="keyword">struct</span> <span class="identifier">bitfield_traits</span> <span class="special">{</span>
+ <span class="keyword">typedef</span> <span class="identifier">bitfield</span><span class="special"><</span><span class="identifier">STORAGE_TYPE</span><span class="special">,</span> <span class="identifier">F</span><span class="special">,</span> <span class="identifier">L</span><span class="special">,</span> <span class="identifier">VALUE_TYPE</span><span class="special">></span> <span class="identifier">reference</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">bitfield</span><span class="special"><</span><span class="keyword">const</span> <span class="identifier">STORAGE_TYPE</span><span class="special">,</span> <span class="identifier">F</span><span class="special">,</span> <span class="identifier">L</span><span class="special">,</span> <span class="identifier">VALUE_TYPE</span><span class="special">></span> <span class="identifier">value</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="toward_boost_bitfield.reference.bitfield_dcl_hpp"></a><a href="index.html#toward_boost_bitfield.reference.bitfield_dcl_hpp" title=" Header
+ <boost/integer/bitfield/bitfield_dcl.hpp>"> Header
+ <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">/</span><span class="identifier">bitfield</span><span class="special">/</span><span class="identifier">bitfield_dcl</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a>
+</h3></div></div></div>
+<div class="toc"><dl><dt><span class="section"><a href="index.html#toward_boost_bitfield.reference.bitfield_dcl_hpp.BOOST_BITFIELD_DCL">
+ Macro <code class="computeroutput"><span class="identifier">BOOST_BITFIELD_DCL</span></code></a></span></dt></dl></div>
+<p>
+ This file constains the macro making easier the definition of the bitfield
+ helper type and the bitfield getter and setter functions.
+ </p>
+<pre class="programlisting">
+<span class="preprocessor">#define</span> <span class="identifier">BOOST_BITFIELD_DCL</span><span class="special">(</span><span class="identifier">STORAGE_TYPE</span><span class="special">,</span> <span class="identifier">STORAGE_VAR</span><span class="special">,</span> <span class="identifier">VALUE_TYPE</span><span class="special">,</span> <span class="identifier">FIELD</span><span class="special">,</span> <span class="identifier">F</span><span class="special">,</span> <span class="identifier">L</span><span class="special">)</span>
+</pre>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="toward_boost_bitfield.reference.bitfield_dcl_hpp.BOOST_BITFIELD_DCL"></a><a href="index.html#toward_boost_bitfield.reference.bitfield_dcl_hpp.BOOST_BITFIELD_DCL" title="
+ Macro BOOST_BITFIELD_DCL">
+ Macro <code class="computeroutput"><span class="identifier">BOOST_BITFIELD_DCL</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting">
+<span class="preprocessor">#define</span> <span class="identifier">BOOST_BITFIELD_DCL</span><span class="special">(</span><span class="identifier">STORAGE_TYPE</span><span class="special">,</span> <span class="identifier">STORAGE_VAR</span><span class="special">,</span> <span class="identifier">VALUE_TYPE</span><span class="special">,</span> <span class="identifier">FIELD</span><span class="special">,</span> <span class="identifier">F</span><span class="special">,</span> <span class="identifier">L</span><span class="special">)</span>
+</pre>
+<div class="itemizedlist"><ul type="disc">
+<li>
+ Parameters
+ <div class="itemizedlist"><ul type="circle">
+<li>
+ STORAGE_TYPE: the type to store the bitfield
+ </li>
+<li>
+ STORAGE_VAR: the variable used to store the bitfield
+ </li>
+<li>
+ VALUE_TYPE: the type for the bitfield
+ </li>
+<li>
+ FIELD: the name of the bitfield
+ </li>
+<li>
+ F: the first bit
+ </li>
+<li>
+ L: the last bit
+ </li>
+</ul></div>
+</li>
+<li>
+ Effect. This macro defines the bitfield traits and the functions necessary
+ to make valid the following expressions:
+ <div class="itemizedlist"><ul type="circle">
+<li>
+ str.FIELD() = value;
+ </li>
+<li>
+ var= str.FIELD();
+ </li>
+<li>
+ str.set_FIELD(var);
+ </li>
+<li>
+ var= str.get_FIELD()
+ </li>
+</ul></div>
+</li>
+</ul></div>
+<p>
+ Two styles of getter<span class="emphasis"><em>setter are provided: one using overloading
+ on the field name, the other using clasical prefix `get_`</em></span><code class="computeroutput"><span class="identifier">set_</span></code>.
+ </p>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="toward_boost_bitfield.reference.endian_bitfield_value_type_hpp"></a><a href="index.html#toward_boost_bitfield.reference.endian_bitfield_value_type_hpp" title="
+ Header <boost/integer/bitfield/endian_bitfield_value_type.hpp>">
+ Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">/</span><span class="identifier">bitfield</span><span class="special">/</span><span class="identifier">endian_bitfield_value_type</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a>
+</h3></div></div></div>
+<p>
+ This file includes the <code class="computeroutput"><span class="identifier">bitfield_value_type</span></code>
+ metafunction specialization for the endian types. You need to include this
+ file if you use endian types as storage for the bitfields.
+ </p>
+<pre class="programlisting">
+<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">integer</span> <span class="special">{</span>
+ <span class="keyword">template</span> <span class="special"><</span><span class="identifier">endianness</span> <span class="identifier">E</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">T</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">n_bits</span><span class="special">,</span> <span class="identifier">alignment</span> <span class="identifier">A</span><span class="special">></span>
+ <span class="keyword">struct</span> <span class="identifier">bitfield_value_type</span><span class="special"><</span><span class="identifier">endian</span><span class="special"><</span><span class="identifier">E</span><span class="special">,</span><span class="identifier">T</span><span class="special">,</span><span class="identifier">n_bits</span><span class="special">,</span><span class="identifier">A</span><span class="special">></span> <span class="special">></span> <span class="special">{</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">endian</span><span class="special"><</span><span class="identifier">E</span><span class="special">,</span><span class="identifier">T</span><span class="special">,</span><span class="identifier">n_bits</span><span class="special">,</span><span class="identifier">A</span><span class="special">>::</span><span class="identifier">value_type</span> <span class="identifier">type</span><span class="special">;</span>
+ <span class="special">};</span>
+<span class="special">}</span>
+</pre>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="toward_boost_bitfield.appendices"></a>Appendices
+</h2></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.appendices.history"> Appendix A:
+ History</a></span></dt>
+<dd><dl>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.appendices.history.__version_0_2_0__jan_29__2011____bitfield_porting_to_windows_and_msvc_"><span class="bold"><strong>Version 0.2.0, Jan 29, 2011</strong></span> <span class="emphasis"><em>Bitfield porting
+ to Windows and MSVC</em></span></a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.appendices.history.__version_0_1_0__april_29__2009____announcement_of_bitfield_"><span class="bold"><strong>Version 0.1.0, April 29, 2009</strong></span> <span class="emphasis"><em>Announcement
+ of Bitfield</em></span></a></span></dt>
+</dl></dd>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.appendices.rationale"> Appendix
+ B: Rationale</a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.appendices.implementation"> Appendix
+ C: Implementation Notes</a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.appendices.acknowledgements"> Appendix
+ D: Acknowledgements</a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.appendices.appendix_e__tests">Appendix
+ E: Tests</a></span></dt>
+<dd><dl><dt><span class="section"><a href="index.html#toward_boost_bitfield.appendices.appendix_e__tests.aligned_bitfields">aligned
+ bitfields</a></span></dt></dl></dd>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.appendices.appendix_f__tickets">Appendix
+ F: Tickets</a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.appendices.todo"> Appendix F: Future
+ plans</a></span></dt>
+</dl></div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="toward_boost_bitfield.appendices.history"></a><a href="index.html#toward_boost_bitfield.appendices.history" title=" Appendix A:
+ History"> Appendix A:
+ History</a>
+</h3></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.appendices.history.__version_0_2_0__jan_29__2011____bitfield_porting_to_windows_and_msvc_"><span class="bold"><strong>Version 0.2.0, Jan 29, 2011</strong></span> <span class="emphasis"><em>Bitfield porting
+ to Windows and MSVC</em></span></a></span></dt>
+<dt><span class="section"><a href="index.html#toward_boost_bitfield.appendices.history.__version_0_1_0__april_29__2009____announcement_of_bitfield_"><span class="bold"><strong>Version 0.1.0, April 29, 2009</strong></span> <span class="emphasis"><em>Announcement
+ of Bitfield</em></span></a></span></dt>
+</dl></div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="toward_boost_bitfield.appendices.history.__version_0_2_0__jan_29__2011____bitfield_porting_to_windows_and_msvc_"></a><a href="index.html#toward_boost_bitfield.appendices.history.__version_0_2_0__jan_29__2011____bitfield_porting_to_windows_and_msvc_" title="Version 0.2.0, Jan 29, 2011 Bitfield porting
+ to Windows and MSVC"><span class="bold"><strong>Version 0.2.0, Jan 29, 2011</strong></span> <span class="emphasis"><em>Bitfield porting
+ to Windows and MSVC</em></span></a>
+</h4></div></div></div>
+<p>
+ <span class="bold"><strong>Bugs:</strong></span>
+ </p>
+<div class="itemizedlist"><ul type="disc">
+<li>
+ Fix uses of specific POSIX files in test.
+ </li>
+<li>
+ Adapt to MSVC constraints.
+ </li>
+</ul></div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="toward_boost_bitfield.appendices.history.__version_0_1_0__april_29__2009____announcement_of_bitfield_"></a><a href="index.html#toward_boost_bitfield.appendices.history.__version_0_1_0__april_29__2009____announcement_of_bitfield_" title="Version 0.1.0, April 29, 2009 Announcement
+ of Bitfield"><span class="bold"><strong>Version 0.1.0, April 29, 2009</strong></span> <span class="emphasis"><em>Announcement
+ of Bitfield</em></span></a>
+</h4></div></div></div>
+<p>
+ <span class="bold"><strong>Features:</strong></span>
+ </p>
+<div class="itemizedlist"><ul type="disc">
+<li>
+ a generic bitfield traits class providing generic getter and setter for
+ portable bitfields.
+ </li>
+<li>
+ a BOOST_BITFIELD_DCL macro making easier the definition of the bitfield
+ helper type and the bitfield getter and setter functions.
+ </li>
+</ul></div>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="toward_boost_bitfield.appendices.rationale"></a><a href="index.html#toward_boost_bitfield.appendices.rationale" title=" Appendix
+ B: Rationale"> Appendix
+ B: Rationale</a>
+</h3></div></div></div>
+<a name="toward_boost_bitfield.appendices.rationale.why_we_can_not_declare_portable_c_c___bitfields__"></a><h4>
+<a name="id5001192"></a>
+ <a href="index.html#toward_boost_bitfield.appendices.rationale.why_we_can_not_declare_portable_c_c___bitfields__">Why
+ we can not declare portable C/C++ bitfields ?</a>
+ </h4>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="toward_boost_bitfield.appendices.implementation"></a><a href="index.html#toward_boost_bitfield.appendices.implementation" title=" Appendix
+ C: Implementation Notes"> Appendix
+ C: Implementation Notes</a>
+</h3></div></div></div>
+<a name="toward_boost_bitfield.appendices.implementation.faq"></a><h4>
+<a name="id5001231"></a>
+ FAQ
+ </h4>
+<div class="itemizedlist"><ul type="disc"><li>
+ Why bother with endian bitfields ?
+ </li></ul></div>
+<p>
+ External data portability and both speed and space efficiency. Availability
+ of bit order representations is important in some applications.
+ </p>
+<div class="itemizedlist"><ul type="disc"><li>
+ Why not just use Boost.Serialization?
+ </li></ul></div>
+<p>
+ Serialization involves a conversion for every object involved in I/O. Bitfields
+ objects require no conversion or copying. They are already in the desired
+ format for binary I/O. Thus they can be read or written in bulk.
+ </p>
+<div class="itemizedlist"><ul type="disc"><li>
+ Do this type have any uses outside of I/O?
+ </li></ul></div>
+<p>
+ Probably not.
+ </p>
+<div class="itemizedlist"><ul type="disc"><li>
+ Is there is a performance hit when doing arithmetic using these types?
+ </li></ul></div>
+<p>
+ Yes, for sure, compared to arithmetic operations on native bitfields integer
+ types. However, these types are usually faster, and sometimes much faster,
+ for I/O compared to stream inserters and extractors, or to serialization.
+ </p>
+<div class="itemizedlist"><ul type="disc"><li>
+ These types are really just byte-holders. Why provide the arithmetic operations
+ at all?
+ </li></ul></div>
+<p>
+ The first goal of the library is to be as close as possible of the usage
+ of bitfields on C/C++. Providing a full set of operations reduces program
+ clutter and makes code both easier to write and to read. Consider incrementing
+ a variable in a record. It is very convenient to write:
+ </p>
+<pre class="programlisting">
+<span class="special">++</span><span class="identifier">record</span><span class="special">.</span><span class="identifier">bf</span><span class="special">();</span>
+</pre>
+<p>
+ Rather than:
+ </p>
+<pre class="programlisting">
+<span class="keyword">int</span> <span class="identifier">temp</span><span class="special">(</span> <span class="identifier">record</span><span class="special">.</span><span class="identifier">bf</span><span class="special">());</span>
+<span class="special">++</span><span class="identifier">temp</span><span class="special">;</span>
+<span class="identifier">record</span><span class="special">.</span><span class="identifier">vf</span><span class="special">()</span> <span class="special">=</span> <span class="identifier">temp</span><span class="special">;</span>
+</pre>
+<a name="toward_boost_bitfield.appendices.implementation.design_considerations_for_boost_bitfield"></a><h4>
+<a name="id5001438"></a>
+ <a href="index.html#toward_boost_bitfield.appendices.implementation.design_considerations_for_boost_bitfield">Design
+ considerations for Boost.Bitfield</a>
+ </h4>
+<div class="itemizedlist"><ul type="disc">
+<li>
+ Must provide exactly the size and internal bit ordering specified.
+ </li>
+<li>
+ It is better software engineering if the same implementation works regardless
+ of the CPU endianness. In other words, #ifdefs should be avoided where
+ possible.
+ </li>
+</ul></div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="toward_boost_bitfield.appendices.acknowledgements"></a><a href="index.html#toward_boost_bitfield.appendices.acknowledgements" title=" Appendix
+ D: Acknowledgements"> Appendix
+ D: Acknowledgements</a>
+</h3></div></div></div>
+<p>
+ 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.
+ </p>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="toward_boost_bitfield.appendices.appendix_e__tests"></a><a href="index.html#toward_boost_bitfield.appendices.appendix_e__tests" title="Appendix
+ E: Tests">Appendix
+ E: Tests</a>
+</h3></div></div></div>
+<div class="toc"><dl><dt><span class="section"><a href="index.html#toward_boost_bitfield.appendices.appendix_e__tests.aligned_bitfields">aligned
+ bitfields</a></span></dt></dl></div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="toward_boost_bitfield.appendices.appendix_e__tests.aligned_bitfields"></a><a href="index.html#toward_boost_bitfield.appendices.appendix_e__tests.aligned_bitfields" title="aligned
+ bitfields">aligned
+ bitfields</a>
+</h4></div></div></div>
+<div class="informaltable"><table class="table">
+<colgroup>
+<col>
+<col>
+<col>
+<col>
+<col>
+</colgroup>
+<thead><tr>
+<th>
+ <p>
+ Name
+ </p>
+ </th>
+<th>
+ <p>
+ kind
+ </p>
+ </th>
+<th>
+ <p>
+ Description
+ </p>
+ </th>
+<th>
+ <p>
+ Result
+ </p>
+ </th>
+<th>
+ <p>
+ Ticket
+ </p>
+ </th>
+</tr></thead>
+<tbody>
+<tr>
+<td>
+ <p>
+ get
+ </p>
+ </td>
+<td>
+ <p>
+ run
+ </p>
+ </td>
+<td>
+ <p>
+ check getters
+ </p>
+ </td>
+<td>
+ <p>
+ Pass
+ </p>
+ </td>
+<td>
+ <p>
+ #
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ assign
+ </p>
+ </td>
+<td>
+ <p>
+ run
+ </p>
+ </td>
+<td>
+ <p>
+ check setters
+ </p>
+ </td>
+<td>
+ <p>
+ Pass
+ </p>
+ </td>
+<td>
+ <p>
+ #
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ flags
+ </p>
+ </td>
+<td>
+ <p>
+ run
+ </p>
+ </td>
+<td>
+ <p>
+ check flags
+ </p>
+ </td>
+<td>
+ <p>
+ Pass
+ </p>
+ </td>
+<td>
+ <p>
+ #
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ traits
+ </p>
+ </td>
+<td>
+ <p>
+ run
+ </p>
+ </td>
+<td>
+ <p>
+ check the traits of bitfield
+ </p>
+ </td>
+<td>
+ <p>
+ Pass
+ </p>
+ </td>
+<td>
+ <p>
+ #
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ invert
+ </p>
+ </td>
+<td>
+ <p>
+ run
+ </p>
+ </td>
+<td>
+ <p>
+ check the <code class="computeroutput"><span class="keyword">operator</span><span class="special">~</span></code>
+ </p>
+ </td>
+<td>
+ <p>
+ Pass
+ </p>
+ </td>
+<td>
+ <p>
+ #
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ bit
+ </p>
+ </td>
+<td>
+ <p>
+ run
+ </p>
+ </td>
+<td>
+ <p>
+ check the <code class="computeroutput"><span class="keyword">operator</span><span class="special">[]</span></code>
+ </p>
+ </td>
+<td>
+ <p>
+ Pass
+ </p>
+ </td>
+<td>
+ <p>
+ #
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ signed
+ </p>
+ </td>
+<td>
+ <p>
+ run
+ </p>
+ </td>
+<td>
+ <p>
+ check signed bitfields
+ </p>
+ </td>
+<td>
+ <p>
+ Pass
+ </p>
+ </td>
+<td>
+ <p>
+ #
+ </p>
+ </td>
+</tr>
+</tbody>
+</table></div>
+</div>
+</div>
+<div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title">
+<a name="toward_boost_bitfield.appendices.appendix_f__tickets"></a><a href="index.html#toward_boost_bitfield.appendices.appendix_f__tickets" title="Appendix
+ F: Tickets">Appendix
+ F: Tickets</a>
+</h3></div></div></div></div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="toward_boost_bitfield.appendices.todo"></a><a href="index.html#toward_boost_bitfield.appendices.todo" title=" Appendix F: Future
+ plans"> Appendix F: Future
+ plans</a>
+</h3></div></div></div>
+<a name="toward_boost_bitfield.appendices.todo.tasks_to_do_before_review"></a><h4>
+<a name="id5001888"></a>
+ <a href="index.html#toward_boost_bitfield.appendices.todo.tasks_to_do_before_review">Tasks
+ to do before review</a>
+ </h4>
+<div class="itemizedlist"><ul type="disc"><li>
+ Add test with the Boost.Endian types and binary archive.
+ </li></ul></div>
+<a name="toward_boost_bitfield.appendices.todo.for_later_releases"></a><h4>
+<a name="id5001916"></a>
+ <a href="index.html#toward_boost_bitfield.appendices.todo.for_later_releases">For
+ later releases</a>
+ </h4>
+<p>
+ <span class="bold"><strong>Add bitfields group</strong></span>
+ </p>
+<p>
+ Used to easily manipulate groups of bitfields the same way as does C bitfields,
+ but in a portable manner. Example declaration:
+ </p>
+<pre class="programlisting">
+<span class="keyword">struct</span> <span class="identifier">Rgb565</span>
+<span class="special">{</span>
+ <span class="keyword">struct</span> <span class="identifier">red</span> <span class="special">{};</span>
+ <span class="keyword">struct</span> <span class="identifier">green</span> <span class="special">{};</span>
+ <span class="keyword">struct</span> <span class="identifier">blue</span> <span class="special">{};</span>
+ <span class="keyword">typedef</span> <span class="identifier">bitfields</span><span class="special"><</span><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span>
+ <span class="identifier">member</span><span class="special"><</span><span class="keyword">unsigned</span> <span class="keyword">char</span><span class="special">,</span> <span class="identifier">red</span><span class="special">,</span> <span class="number">5</span><span class="special">>,</span>
+ <span class="identifier">member</span><span class="special"><</span><span class="keyword">unsigned</span> <span class="keyword">char</span><span class="special">,</span> <span class="identifier">green</span><span class="special">,</span> <span class="number">6</span><span class="special">>,</span>
+ <span class="identifier">member</span><span class="special"><</span><span class="keyword">unsigned</span> <span class="keyword">char</span><span class="special">,</span> <span class="identifier">blue</span><span class="special">,</span> <span class="number">5</span><span class="special">></span>
+ <span class="special">></span> <span class="special">></span> <span class="identifier">type</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ Example usage:
+ </p>
+<pre class="programlisting">
+<span class="identifier">Rgb565</span><span class="special">::</span><span class="identifier">type</span> <span class="identifier">r</span> <span class="special">=</span> <span class="identifier">make_bitfields</span><span class="special"><</span><span class="identifier">Rgb565</span><span class="special">::</span><span class="identifier">type</span><span class="special">,</span> <span class="number">1</span><span class="special">,</span><span class="number">2</span><span class="special">,</span><span class="number">3</span><span class="special">>;</span>
+
+<span class="comment">// Write to a bitfield.
+</span><span class="identifier">r</span><span class="special">.</span><span class="identifier">get</span><span class="special"><</span><span class="identifier">Rgb565</span><span class="special">::</span><span class="identifier">red</span><span class="special">>()</span> <span class="special">=</span> <span class="number">23</span><span class="special">;</span>
+<span class="comment">//or
+</span><span class="identifier">r</span><span class="special">.</span><span class="identifier">set</span><span class="special"><</span><span class="identifier">Rgb565</span><span class="special">::</span><span class="identifier">red</span><span class="special">>(</span><span class="number">23</span><span class="special">);</span>
+
+<span class="comment">// Read from a bitfield
+</span><span class="identifier">Rgb565</span><span class="special">::</span><span class="identifier">at</span><span class="special"><</span><span class="identifier">Rgb565</span><span class="special">::</span><span class="identifier">blue</span><span class="special">>::</span><span class="identifier">value_type</span> <span class="identifier">b</span> <span class="special">=</span> <span class="identifier">r</span><span class="special">.</span><span class="identifier">get</span><span class="special"><</span><span class="identifier">Rgb565</span><span class="special">::</span><span class="identifier">blue</span><span class="special">>();</span>
+</pre>
+<p>
+ Other posibility could be to use unamed bitfields whic are accessed as tuples.
+ </p>
+<pre class="programlisting">
+<span class="keyword">typedef</span> <span class="identifier">bitfields_group</span><span class="special"><</span><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">vector_c</span><span class="special"><</span><span class="number">5</span><span class="special">,</span><span class="number">6</span><span class="special">,</span><span class="number">5</span><span class="special">></span> <span class="special">></span> <span class="identifier">Rgb565</span><span class="special">;</span>
+<span class="identifier">Rgb565</span> <span class="identifier">r</span><span class="special">;</span>
+
+<span class="identifier">r</span><span class="special">.</span><span class="identifier">get</span><span class="special"><</span><span class="number">0</span><span class="special">>()</span> <span class="special">=</span> <span class="number">23</span><span class="special">;</span>
+<span class="comment">// or
+</span><span class="identifier">r</span><span class="special">.</span><span class="identifier">set</span><span class="special"><</span><span class="number">0</span><span class="special">>(</span><span class="number">23</span><span class="special">);</span>
+
+<span class="comment">// Read from a bitfield
+</span><span class="identifier">Rgb565</span><span class="special">::</span><span class="identifier">at</span><span class="special"><</span><span class="number">2</span><span class="special">>::</span><span class="identifier">value_type</span> <span class="identifier">b</span> <span class="special">=</span> <span class="identifier">r</span><span class="special">.</span><span class="identifier">get</span><span class="special"><</span><span class="number">2</span><span class="special">>();</span>
+</pre>
+<p>
+ <span class="bold"><strong>Add pointer_plus_bits</strong></span>
+ </p>
+<p>
+ Based on
+ </p>
+<div class="itemizedlist"><ul type="disc">
+<li>
+ The article of Joaquin <a href="http://bannalia.blogspot.com/2008/11/optimizing-red-black-tree-color-bits.html" target="_top">Optimizing
+ red-black tree color bits</a>,
+ </li>
+<li>
+ the implementation of Ion <a href="http://www.boost.org/boost/boost/intrusive/pointer_plus_bits.hpp" target="_top">pointer_plus_bits
+ from Boost.Intrusive </a>, and
+ </li>
+<li><a href="https://llvm.org/svn/llvm-project/llvm/trunk/include/llvm/ADT/PointerIntPair.h" target="_top">Clang's
+ QualType smart pointer</a></li>
+</ul></div>
+<p>
+ This class will allows to use the unsused bits of a pointer to reduce the
+ size of the nodes containing pointers and bits and sometimes improving also
+ the performances.
+ </p>
+<p>
+ I have not reached yet the interface I would like to have. For the moment
+ we can do
+ </p>
+<pre class="programlisting">
+<span class="keyword">typedef</span> <span class="identifier">pointer_plus_bits</span><span class="special"><</span><span class="keyword">int</span><span class="special">*,</span><span class="number">1</span><span class="special">,</span><span class="keyword">bool</span><span class="special">>::</span><span class="identifier">type</span> <span class="identifier">pint_and_bool</span><span class="special">;</span>
+
+<span class="keyword">int</span> <span class="identifier">i</span><span class="special">=</span><span class="number">0</span><span class="special">;</span>
+<span class="identifier">pint_and_bool</span> <span class="identifier">v1</span><span class="special">;</span>
+<span class="identifier">ASSERT_EQUALS</span><span class="special">(</span><span class="identifier">v1</span><span class="special">.</span><span class="identifier">pointer</span><span class="special">(),</span><span class="number">0</span><span class="special">);</span>
+<span class="identifier">ASSERT_EQUALS</span><span class="special">(</span><span class="identifier">v1</span><span class="special">.</span><span class="identifier">small_int</span><span class="special">(),</span><span class="keyword">false</span><span class="special">);</span>
+<span class="identifier">pint_and_bool</span> <span class="identifier">v2</span><span class="special">(&</span><span class="identifier">i</span><span class="special">,</span> <span class="keyword">true</span><span class="special">);</span>
+<span class="identifier">ASSERT_EQUALS</span><span class="special">(</span><span class="identifier">v2</span><span class="special">.</span><span class="identifier">pointer</span><span class="special">(),&</span><span class="identifier">i</span><span class="special">);</span>
+<span class="identifier">ASSERT_EQUALS</span><span class="special">(</span><span class="identifier">v2</span><span class="special">.</span><span class="identifier">small_int</span><span class="special">(),</span><span class="keyword">true</span><span class="special">);</span>
+<span class="identifier">v1</span><span class="special">.</span><span class="identifier">pointer</span><span class="special">()=</span><span class="identifier">v2</span><span class="special">.</span><span class="identifier">pointer</span><span class="special">();</span>
+<span class="identifier">v1</span><span class="special">.</span><span class="identifier">small_int</span><span class="special">()=</span><span class="keyword">true</span><span class="special">;</span>
+<span class="identifier">ASSERT_EQUALS</span><span class="special">(</span><span class="identifier">v1</span><span class="special">.</span><span class="identifier">pointer</span><span class="special">(),&</span><span class="identifier">i</span><span class="special">);</span>
+<span class="identifier">ASSERT_EQUALS</span><span class="special">(</span><span class="identifier">v1</span><span class="special">.</span><span class="identifier">small_int</span><span class="special">(),</span><span class="keyword">true</span><span class="special">);</span>
+
+<span class="keyword">typedef</span> <span class="identifier">pointer_plus_bits</span><span class="special"><</span>
+ <span class="identifier">pointer_plus_bits</span><span class="special"><</span><span class="keyword">int</span><span class="special">*,</span><span class="number">1</span><span class="special">,</span><span class="keyword">bool</span><span class="special">>::</span><span class="identifier">type</span>
+ <span class="special">,</span><span class="number">1</span><span class="special">,</span> <span class="keyword">bool</span><span class="special">>::</span><span class="identifier">type</span> <span class="identifier">pint_and_bool_bool</span>
+<span class="identifier">pint_and_bool_bool</span> <span class="identifier">v1</span><span class="special">;</span>
+<span class="identifier">ASSERT_EQUALS</span><span class="special">(</span><span class="identifier">v1</span><span class="special">.</span><span class="identifier">small_int</span><span class="special">(),</span><span class="keyword">false</span><span class="special">);</span>
+<span class="identifier">ASSERT_EQUALS</span><span class="special">(</span><span class="identifier">v1</span><span class="special">.</span><span class="identifier">pointer</span><span class="special">().</span><span class="identifier">get_pointer</span><span class="special">(),</span><span class="number">0</span><span class="special">);</span>
+<span class="identifier">ASSERT_EQUALS</span><span class="special">(</span><span class="identifier">v1</span><span class="special">.</span><span class="identifier">get_pointer</span><span class="special">().</span><span class="identifier">get_pointer</span><span class="special">(),</span><span class="number">0</span><span class="special">);</span>
+<span class="identifier">ASSERT_EQUALS</span><span class="special">(</span><span class="identifier">v1</span><span class="special">.</span><span class="identifier">get_pointer</span><span class="special">().</span><span class="identifier">small_int</span><span class="special">(),</span><span class="keyword">false</span><span class="special">);</span>
+</pre>
+</div>
+</div>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"><p><small>Last revised: January 23, 2011 at 13:22:57 GMT</small></p></td>
+<td align="right"><div class="copyright-footer"></div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav"></div>
+</body>
+</html>
Added: sandbox/bitfield/libs/bitfield/doc/html/standalone_HTML.manifest
==============================================================================
--- (empty file)
+++ sandbox/bitfield/libs/bitfield/doc/html/standalone_HTML.manifest 2011-01-23 09:04:49 EST (Sun, 23 Jan 2011)
@@ -0,0 +1 @@
+index.html
Added: sandbox/bitfield/libs/bitfield/doc/index.html
==============================================================================
--- (empty file)
+++ sandbox/bitfield/libs/bitfield/doc/index.html 2011-01-23 09:04:49 EST (Sun, 23 Jan 2011)
@@ -0,0 +1,9 @@
+<html>
+<head>
+<meta http-equiv="refresh" content="0; URL=html/index.html">
+</head>
+<body>
+Automatic redirection failed, please go to
+../../doc/html/integer.html
+</body>
+</html>
Added: sandbox/bitfield/libs/bitfield/test/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/bitfield/libs/bitfield/test/Jamfile.v2 2011-01-23 09:04:49 EST (Sun, 23 Jan 2011)
@@ -0,0 +1,43 @@
+#
+# Boost.Bitfield
+# Build script for tests.
+#
+# Copyright (c) 2008-2009 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)
+
+using testing ;
+
+if ! $(BOOST_ROOT)
+{
+ BOOST_ROOT = [ modules.peek : BOOST_ROOT ] ;
+}
+
+# bjam -V2 threading=multi target-os=cygwin threadapi=pthread variant=debug
+
+project :
+ : requirements
+ <include>../../..
+ <include>$(BOOST_ROOT)
+ <include>/sandbox/endian
+
+# <threading>multi
+# <target-os>cygwin
+# <threadapi>pthread
+# <variant>debug
+
+ #<library>/boost/test//boost_unit_test_framework/<link>static
+
+# <library>/boost/test///boost_unit_test_framework/<link>static
+# <library>/sandbox/libs/endia/build//boost_endian/<link>static
+
+;
+
+
+
+
+test-suite "bitfield" :
+ [ run bitfield_test.cpp ]
+ #[ run pointer_plus_small_int_test.cpp ]
+ ;
+
Added: sandbox/bitfield/libs/bitfield/test/bitfield_group_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/bitfield/libs/bitfield/test/bitfield_group_test.cpp 2011-01-23 09:04:49 EST (Sun, 23 Jan 2011)
@@ -0,0 +1,228 @@
+#include <iostream>
+#include <cassert>
+#include "boost/integer/bitfield.hpp"
+#include "boost/integer/bitfield_dcl.hpp"
+
+#include <sys/stat.h>
+#include <errno.h>
+#include <unistd.h>
+#include <netinet/in.h>
+
+#define ASSERT_EQUALS(a,b) assert((a) == (b))
+#define ASSERT_UNEQUALS(a,b) assert((a) != (b))
+#define ASSERT(a) assert((a))
+
+//typedef unsigned short uint16_t;
+//typedef unsigned char uint8_t;
+using namespace boost;
+using namespace boost::integer;
+
+struct Register
+{
+ typedef uint16_t T;
+ T word;
+ struct STR {
+ uint8_t f:3;
+ uint16_t m:9;
+ uint32_t l:4;
+ };
+ union {
+ uint16_t padd;
+ STR value;
+ } s, sl;
+
+ typedef boost::integer::bitfield_traits<T, 0, 2, uint8_t> f_type;
+ typedef boost::integer::bitfield_traits<T, 3, 11> m_type;
+ typedef boost::integer::bitfield_traits<T, 12, 15, uint32_t> l_type;
+ typedef boost::integer::bitfield_traits<T, 0, 7> high_type;
+ typedef boost::integer::bitfield_traits<T, 4, 11> mid_type; // Intentionally overlap
+ typedef boost::integer::bitfield_traits<T, 8, 15> low_type;
+ typedef boost::integer::bitfield_traits<T, 0, 15> all_type;
+ typedef boost::integer::bitfield_traits<T, 4, 4> single_type;
+ //typedef bitfield_traits<T, 2, 4, signed char> ss_type;
+ typedef boost::integer::bitfield_traits<T, 2, 4, signed char> ss_type;
+
+ f_type::reference f() { return f_type::reference(s.padd); }
+ l_type::reference l() { return l_type::reference(s.padd); }
+ m_type::reference m() { return m_type::reference(s.padd); }
+
+ high_type::reference high() { return high_type::reference(word); }
+ mid_type::reference mid() { return mid_type::reference(word); }
+ low_type::reference low() { return low_type::reference(word); }
+ all_type::reference all() { return all_type::reference(word); }
+ single_type::reference single() { return single_type::reference(word); }
+ ss_type::reference ss() { return ss_type::reference(word); }
+
+
+ f_type::value::value_type f() const { return f_type::value(word).get(); }
+ l_type::value::value_type l() const { return l_type::value(word).get(); }
+ m_type::value::value_type m() const { return m_type::value(word).get(); }
+ high_type::value::value_type high() const { return high_type::value(word).get(); }
+ mid_type::value::value_type mid() const { return mid_type::value(word).get(); }
+ low_type::value::value_type low() const { return low_type::value(word).get(); }
+ all_type::value::value_type all() const { return all_type::value(word).get(); }
+ single_type::value::value_type single() const { return single_type::value(word).get(); }
+ ss_type::value::value_type ss() const { return ss_type::value(word).get(); }
+
+
+};
+
+struct Register {
+ struct f_tag{};
+ struct m_tag{};
+ struct l_tag{};
+ typedef bitfield_group<mpl::vector<
+ member<uint8_t, f_tag, 3>,
+ member<uint16_t, m_tag, 9>,
+ member<uint32_t, l_tag, 4>
+ > > type;
+ type word;
+
+ struct STR {
+ uint8_t f:3;
+ uint16_t m:9;
+ uint32_t l:4;
+ };
+ union {
+ uint16_t padd;
+ STR value;
+ } s, sl;
+
+ f_type::reference f() { return f_type::reference(s.padd); }
+ l_type::reference l() { return l_type::reference(s.padd); }
+ m_type::reference m() { return m_type::reference(s.padd); }
+};
+
+
+void test_tt()
+{
+ Register r;
+ // 0001|0001|0001|0010
+
+ r.s.padd=0x1112;
+ std::cout << "f=" << std::hex << int(r.s.value.f) << std::endl;
+ std::cout << "m=" << std::hex << int(r.s.value.m) << std::endl;
+ std::cout << "l=" << std::hex << int(r.s.value.l) << std::endl;
+
+ r.word=0x1112;
+ // 0001|001000110|100
+ std::cout << "f()=" << std::hex << int(r.f()) << std::endl;
+ std::cout << "m()=" << std::hex << int(r.m()) << std::endl;
+ std::cout << "l()=" << std::hex << int(r.l()) << std::endl;
+
+
+ //ASSERT_EQUALS(0, 1);
+
+}
+
+struct Register2 {
+ struct high_tag{};
+ struct low_tag{};
+ struct mid_tag{};
+ typedef bitfield_group<mpl::vector<
+ member<uint16_t, high_tag, 4>,
+ member<uint16_t, mid_tag, 8>,
+ member<uint16_t, low_tag, 4>
+ > > type;
+ type word;
+
+ result_of::at_key<type, high_tag>::type high() { return at_key<high_tag>(word); }
+ result_of::at_key<type, mid_tag>::type mid() { return at_key<mid_tag>(word); }
+ result_of::at_key<type, low_tag>::type low() { return at_key<low_tag>(word); }
+
+ result_of::at_key<type, high_tag>::type::value_type get_high() const { return at_key<high_tag>(word).get(); }
+ result_of::at_key<type, mid_tag>::type::value_type get_mid() const { return at_key<mid_tag>(word).get(); }
+ result_of::at_key<type, low_tag>::type::value_type get_low() const { return at_key<low_tag>(word).get(); }
+
+ uint16_t& all() { return word.value; }
+ uint16_t all() const { return word.value; }
+
+};
+
+//-----------------------------------------------------------------------------
+void test_assign()
+{
+ Register2 r;
+ r.all() = 0;
+ r.high() = 0x12;
+ //printf("word=%x\n",int(r.word));
+ //printf("all=%x\n",int(r.all()));
+ ASSERT_EQUALS(r.all(), 0x1200);
+ r.low() = 0x34;
+ //printf("word=%x\n",int(r.word));
+ //printf("all=%x\n",int(r.all()));
+ ASSERT_EQUALS(r.all(), 0x1234);
+ r.mid() = 0xab;
+ //printf("word=%x\n",int(r.word));
+ //printf("all=%x\n",int(r.all()));
+
+ ASSERT_EQUALS(r.all(), 0x1ab4);
+ r.all() = 0x4321;
+ //printf("word=%x\n",int(r.word));
+ //printf("all=%x\n",int(r.all()));
+ ASSERT_EQUALS(r.all(), 0x4321);
+ r.single() = 1;
+ //printf("word=%x\n",int(r.word));
+ //printf("all=%x\n",int(r.all()));
+ ASSERT_EQUALS(r.all(), 0x4b21);
+}
+
+//-----------------------------------------------------------------------------
+void test_get()
+{
+ Register2 r;
+ r.all() = 0x1234;
+ ASSERT_EQUALS(r.high(), 0x12);
+ ASSERT_EQUALS(r.low(), 0x34);
+ ASSERT_EQUALS(r.mid(), 0x23);
+ ASSERT_EQUALS(r.all(), 0x1234);
+ ASSERT_EQUALS(r.single(), 0);
+ r.all() = 0x1A34;
+}
+
+//-----------------------------------------------------------------------------
+void test_invert()
+{
+ Register2 r;
+ r.all() = 0xff00;
+ ASSERT_EQUALS(~r.high(), 0x00);
+ ASSERT_EQUALS(~r.mid(), 0x0f);
+ ASSERT_EQUALS(~r.low(), 0xff);
+ ASSERT_EQUALS(~r.all(), 0x00ff);
+}
+
+//-----------------------------------------------------------------------------
+
+void test_signed_unsigned() {
+ r.word = 0;
+
+ r.ss() = -2;
+ r.ss()++;
+ r.ss()--;
+ int i = r.ss();
+ signed char c= r.ss();
+ //printf("----- l=%d %x\n", int(r.ss()), int(r.ss()));
+ //std::cout << std::hex << -2 << " " << r.word << " " << int(r.ss) << std::endl;
+ ASSERT_EQUALS(r.ss(), -2);
+ ASSERT_EQUALS(i, -2);
+ ASSERT_EQUALS(c, -2);
+
+}
+
+//-----------------------------------------------------------------------------
+int main(int argc, char *argv[])
+{
+ test_tt();
+ test_assign();
+
+ test_get();
+ test_flags();
+ test_invert();
+ test_traits();
+ test_bit_access();
+ test_signed_unsigned();
+
+ std::cout << "All tests successful!\n";
+ return 0;
+}
+
Added: sandbox/bitfield/libs/bitfield/test/bitfield_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/bitfield/libs/bitfield/test/bitfield_test.cpp 2011-01-23 09:04:49 EST (Sun, 23 Jan 2011)
@@ -0,0 +1,317 @@
+#include <iostream>
+#include <cassert>
+#include <boost/integer/bitfield.hpp>
+//~ #include <boost/integer/bitfield/bitfield_dcl.hpp>
+
+#include <sys/stat.h>
+#include <errno.h>
+#include <libs/bitfield/test/endian_flip.hpp>
+
+#define ASSERT_EQUALS(a,b) assert((a) == (b))
+#define ASSERT_UNEQUALS(a,b) assert((a) != (b))
+#define ASSERT(a) assert((a))
+
+//typedef unsigned short uint16_t;
+//typedef unsigned char uint8_t;
+
+struct Register
+{
+ typedef uint16_t T;
+ T word;
+ struct STR {
+ uint8_t f:3;
+ uint16_t m:9;
+ uint32_t l:4;
+ };
+ union {
+ uint16_t padd;
+ STR value;
+ } s, sl;
+
+ typedef boost::integer::bitfield_traits<T, 0, 2, uint8_t> f_type;
+ typedef boost::integer::bitfield_traits<T, 3, 11> m_type;
+ typedef boost::integer::bitfield_traits<T, 12, 15, uint32_t> l_type;
+ typedef boost::integer::bitfield_traits<T, 0, 7> high_type;
+ typedef boost::integer::bitfield_traits<T, 4, 11> mid_type; // Intentionally overlap
+ typedef boost::integer::bitfield_traits<T, 8, 15> low_type;
+ typedef boost::integer::bitfield_traits<T, 0, 15> all_type;
+ typedef boost::integer::bitfield_traits<T, 4, 4> single_type;
+ //typedef bitfield_traits<T, 2, 4, signed char> ss_type;
+ typedef boost::integer::bitfield_traits<T, 2, 4, signed char> ss_type;
+
+ f_type::reference f() { return f_type::reference(s.padd); }
+ l_type::reference l() { return l_type::reference(s.padd); }
+ m_type::reference m() { return m_type::reference(s.padd); }
+
+ high_type::reference high() { return high_type::reference(word); }
+ mid_type::reference mid() { return mid_type::reference(word); }
+ low_type::reference low() { return low_type::reference(word); }
+ all_type::reference all() { return all_type::reference(word); }
+ single_type::reference single() { return single_type::reference(word); }
+ ss_type::reference ss() { return ss_type::reference(word); }
+
+
+ f_type::value::value_type f() const { return f_type::value(word).get(); }
+ l_type::value::value_type l() const { return l_type::value(word).get(); }
+ m_type::value::value_type m() const { return m_type::value(word).get(); }
+ high_type::value::value_type high() const { return high_type::value(word).get(); }
+ mid_type::value::value_type mid() const { return mid_type::value(word).get(); }
+ low_type::value::value_type low() const { return low_type::value(word).get(); }
+ all_type::value::value_type all() const { return all_type::value(word).get(); }
+ single_type::value::value_type single() const { return single_type::value(word).get(); }
+ ss_type::value::value_type ss() const { return ss_type::value(word).get(); }
+
+
+};
+
+struct Register2
+{
+ typedef uint32_t T;
+ T word;
+ struct STR {
+ unsigned char f:3;
+ uint16_t m:9;
+ int32_t l:4;
+ };
+ union {
+ uint32_t padd;
+ STR value;
+ } s, sl;
+
+ BOOST_BITFIELD_DCL(uint32_t, word, unsigned char, f, 0, 2);
+ BOOST_BITFIELD_DCL(uint32_t, word, uint32_t, m, 3, 11);
+ BOOST_BITFIELD_DCL(uint32_t, word, uint32_t, l, 12, 15);
+
+ typedef boost::integer::bitfield_traits<T, 0, 7> high_type;
+ typedef boost::integer::bitfield_traits<T, 4, 11> mid_type; // Intentionally overlap
+ typedef boost::integer::bitfield_traits<T, 8, 15> low_type;
+ typedef boost::integer::bitfield_traits<T, 0, 15> all_type;
+ typedef boost::integer::bitfield_traits<T, 4, 4> single_type;
+ typedef boost::integer::bitfield_traits<T, 2, 4, signed char> ss_type;
+
+ high_type::reference high() { return high_type::reference(word); }
+ mid_type::reference mid() { return mid_type::reference(word); }
+ low_type::reference low() { return low_type::reference(word); }
+ all_type::reference all() { return all_type::reference(word); }
+ single_type::reference single() { return single_type::reference(word); }
+ ss_type::reference ss() { return ss_type::reference(word); }
+
+ high_type::value::value_type high() const { return high_type::value(word).get(); }
+ mid_type::value::value_type mid() const { return mid_type::value(word).get(); }
+ low_type::value::value_type low() const { return low_type::value(word).get(); }
+ all_type::value::value_type all() const { return all_type::value(word).get(); }
+ single_type::value::value_type single() const { return single_type::value(word).get(); }
+ ss_type::value::value_type ss() const { return ss_type::value(word).get(); }
+
+
+};
+
+
+namespace
+{
+ Register r;
+}
+
+void test_tt()
+{
+ Register r;
+ // 0001|0001|0001|0010
+
+ r.s.padd=0x1112;
+ std::cout << "f=" << std::hex << int(r.s.value.f) << std::endl;
+ std::cout << "m=" << std::hex << int(r.s.value.m) << std::endl;
+ std::cout << "l=" << std::hex << int(r.s.value.l) << std::endl;
+
+ r.s.padd=0x1112;
+ // 0001|001000110|100
+ std::cout << "f()=" << std::hex << int(r.f()) << std::endl;
+ std::cout << "m()=" << std::hex << int(r.m()) << std::endl;
+ std::cout << "l()=" << std::hex << int(r.l()) << std::endl;
+
+
+ //ASSERT_EQUALS(0, 1);
+
+}
+
+//-----------------------------------------------------------------------------
+void test_assign()
+{
+ r.word = 0;
+ r.high() = 0x12;
+ ASSERT_EQUALS(r.all(), 0x1200);
+ r.low() = 0x34;
+ ASSERT_EQUALS(r.all(), 0x1234);
+ r.mid() = 0xab;
+
+ ASSERT_EQUALS(r.all(), 0x1ab4);
+ r.all() = 0x4321;
+ ASSERT_EQUALS(r.all(), 0x4321);
+ r.single() = 1;
+ ASSERT_EQUALS(r.all(), 0x4b21);
+}
+
+//-----------------------------------------------------------------------------
+void test_get()
+{
+ r.word = 0x1234;
+ ASSERT_EQUALS(r.high(), 0x12);
+ ASSERT_EQUALS(r.low(), 0x34);
+ ASSERT_EQUALS(r.mid(), 0x23);
+ ASSERT_EQUALS(r.all(), 0x1234);
+ ASSERT_EQUALS(r.single(), 0);
+ r.word = 0x1A34;
+ ASSERT_EQUALS(r.single(), 1);
+}
+
+//-----------------------------------------------------------------------------
+void test_flags()
+{
+
+
+ typedef uint16_t T;
+ ASSERT_EQUALS((boost::integer::bitfield_value_to_stprage<boost::integer::bitfield<T, 8, 15>, 0x12>::value), 0x0012);
+ ASSERT_EQUALS((boost::integer::bitfield<T, 8, 15>::get_flags(0x12)), 0x0012);
+ ASSERT_EQUALS((boost::integer::bitfield_value_to_stprage<boost::integer::bitfield<T, 4, 11>, 0x34>::value), 0x0340);
+ ASSERT_EQUALS((boost::integer::bitfield<T, 4, 11>::get_flags(0x34)), 0x0340);
+ ASSERT_EQUALS((boost::integer::bitfield_value_to_stprage<boost::integer::bitfield<T, 0, 7>, 0x56>::value), 0x5600);
+ ASSERT_EQUALS((boost::integer::bitfield<T, 0, 7>::get_flags(0x56)), 0x5600);
+ ASSERT_EQUALS((boost::integer::bitfield<T, 0, 15>::get_flags(0xabcd)), 0xabcd);
+ ASSERT_EQUALS((boost::integer::bitfield<T, 4, 4>::get_flags(0)), 0);
+ ASSERT_EQUALS((boost::integer::bitfield<T, 4, 4>::get_flags(1)), 0x0800);
+}
+
+//-----------------------------------------------------------------------------
+void test_invert()
+{
+ r.word = 0xff00;
+ ASSERT_EQUALS(~r.high(), 0x00);
+ ASSERT_EQUALS(~r.mid(), 0x0f);
+ ASSERT_EQUALS(~r.low(), 0xff);
+ ASSERT_EQUALS(~r.all(), 0x00ff);
+ ASSERT_EQUALS(~r.single(), 0);
+}
+
+//-----------------------------------------------------------------------------
+void test_traits()
+{
+ typedef uint8_t T;
+ ASSERT_EQUALS((boost::integer::bitfield<T, 0, 0>::FIRST), 0);
+ ASSERT_EQUALS((boost::integer::bitfield<T, 3, 5>::FIRST), 3);
+ ASSERT_EQUALS((boost::integer::bitfield<T, 7, 7>::FIRST), 7);
+
+ ASSERT_EQUALS((boost::integer::bitfield<T, 0, 0>::LAST), 0);
+ ASSERT_EQUALS((boost::integer::bitfield<T, 3, 5>::LAST), 5);
+ ASSERT_EQUALS((boost::integer::bitfield<T, 7, 7>::LAST), 7);
+
+ ASSERT_EQUALS((boost::integer::bitfield<T, 0, 0>::WIDTH), 1);
+ ASSERT_EQUALS((boost::integer::bitfield<T, 4, 7>::WIDTH), 4);
+ ASSERT_EQUALS((boost::integer::bitfield<T, 0, 7>::WIDTH), 8);
+
+ ASSERT_EQUALS((boost::integer::bitfield<T, 0, 0>::VAL_MASK), 0x01);
+ ASSERT_EQUALS((boost::integer::bitfield<T, 4, 4>::VAL_MASK), 0x01);
+ ASSERT_EQUALS((boost::integer::bitfield<T, 1, 3>::VAL_MASK), 0x07);
+ ASSERT_EQUALS((boost::integer::bitfield<T, 7, 7>::VAL_MASK), 0x01);
+ ASSERT_EQUALS((boost::integer::bitfield<T, 0, 7>::VAL_MASK), 0xff);
+
+ ASSERT_EQUALS((boost::integer::bitfield<T, 0, 0>::FIELD_MASK), 0x80);
+ ASSERT_EQUALS((boost::integer::bitfield<T, 0, 3>::FIELD_MASK), 0xf0);
+ ASSERT_EQUALS((boost::integer::bitfield<T, 4, 7>::FIELD_MASK), 0x0f);
+ ASSERT_EQUALS((boost::integer::bitfield<T, 7, 7>::FIELD_MASK), 0x01);
+ ASSERT_EQUALS((boost::integer::bitfield<T, 0, 7>::FIELD_MASK), 0xff);
+}
+
+#if 0
+//-----------------------------------------------------------------------------
+template <class B, class CB>
+void do_bit_access_test(B bf, CB& cbf)
+{
+ // Manually set and clear each bit (using r.word) in the bitfield and verify
+ // that the changes are reflected while reading bf[i].
+ // Also test bit inversion and constant access at the same time.
+ for (int i=0; i<B::WIDTH; ++i)
+ {
+ r.word = 1u << (B::FIRST + i);
+ boost::integer::endian_flip(r.word);
+ ASSERT_EQUALS(cbf[i], true);
+ ASSERT_EQUALS(~cbf[i], false);
+
+ r.word = (~ (1u << (B::FIRST + i)));
+ r.word = boost::integer::endian_flip(r.word);
+ ASSERT_EQUALS(bf[i], false);
+ ASSERT_EQUALS(~cbf[i], true);
+ }
+
+ // Set and clear bf[i] and verify that the changes are reflected while
+ // reading r.word.
+ for (int i=0; i<B::WIDTH; ++i)
+ {
+ r.word = 0;
+ boost::integer::endian_flip(r.word);
+ bf[i] = 1u;
+ boost::integer::endian_flip(r.word);
+ ASSERT_EQUALS(r.word, 1u << (B::FIRST + i));
+
+ r.word = 0xfffful;
+ boost::integer::endian_flip(r.word);
+ bf[i] = 0;
+ boost::integer::endian_flip(r.word);
+ ASSERT_EQUALS( r.word, (uint16_t)(~(1u << (B::FIRST + i))) );
+ }
+}
+#endif
+//-----------------------------------------------------------------------------
+void test_bit_access()
+{
+ r.high()=0;
+ bool b = r.high()[0];
+ ASSERT_EQUALS(b, false);
+ r.high() = 0x01;
+ ASSERT_EQUALS(r.high(), 0x01);
+ ASSERT_EQUALS(r.high()[0], true);
+ ASSERT_EQUALS(r.high()[1], false);
+ ASSERT_EQUALS(r.high()[2], false);
+ ASSERT_EQUALS(r.high()[3], false);
+
+#if 0
+ Register& cr = r;
+ do_bit_access_test(r.high(), cr.high());
+ do_bit_access_test(r.mid(), cr.mid());
+ do_bit_access_test(r.low(), cr.low());
+ do_bit_access_test(r.all(), cr.all());
+ do_bit_access_test(r.single(), cr.single());
+#endif
+}
+
+//-----------------------------------------------------------------------------
+
+void test_signed_unsigned() {
+ r.word = 0;
+
+ r.ss() = -2;
+ r.ss()++;
+ r.ss()--;
+ int i = r.ss();
+ signed char c= r.ss();
+ ASSERT_EQUALS(r.ss(), -2);
+ ASSERT_EQUALS(i, -2);
+ ASSERT_EQUALS(c, -2);
+
+}
+
+//-----------------------------------------------------------------------------
+int main(int argc, char *argv[])
+{
+ test_tt();
+ test_assign();
+
+ test_get();
+ test_flags();
+ test_invert();
+ test_traits();
+ test_bit_access();
+ test_signed_unsigned();
+
+ std::cout << "All tests successful!\n";
+ return 0;
+}
+
Added: sandbox/bitfield/libs/bitfield/test/endian_flip.hpp
==============================================================================
--- (empty file)
+++ sandbox/bitfield/libs/bitfield/test/endian_flip.hpp 2011-01-23 09:04:49 EST (Sun, 23 Jan 2011)
@@ -0,0 +1,96 @@
+// endian_flip.hpp -------------------------------------------------------------------//
+
+// Copyright Beman Dawes 2010
+
+// Distributed under the Boost Software License, Version 1.0.
+// http://www.boost.org/LICENSE_1_0.txt
+
+#ifndef BOOST_ENDIAN_FLIP_HPP
+#define BOOST_ENDIAN_FLIP_HPP
+
+#include <boost/integer.hpp>
+namespace boost
+{
+namespace integer
+{
+ inline void endian_flip(int16_t& x)
+ {
+ char* rep = reinterpret_cast<char*>(&x);
+ char tmp;
+ tmp = *rep;
+ *rep = *(rep+1);
+ *(rep+1) = tmp;
+ }
+
+ inline void endian_flip(int32_t& x)
+ {
+ char* rep = reinterpret_cast<char*>(&x);
+ char tmp;
+ tmp = *rep;
+ *rep = *(rep+3);
+ *(rep+3) = tmp;
+ tmp = *(rep+1);
+ *(rep+1) = *(rep+2);
+ *(rep+2) = tmp;
+ }
+
+ inline void endian_flip(int64_t& x)
+ {
+ char* rep = reinterpret_cast<char*>(&x);
+ char tmp;
+ tmp = *rep;
+ *rep = *(rep+7);
+ *(rep+7) = tmp;
+ tmp = *(rep+1);
+ *(rep+1) = *(rep+6);
+ *(rep+6) = tmp;
+ tmp = *(rep+2);
+ *(rep+2) = *(rep+5);
+ *(rep+5) = tmp;
+ tmp = *(rep+3);
+ *(rep+3) = *(rep+4);
+ *(rep+4) = tmp;
+ }
+
+ inline void endian_flip(uint16_t& x)
+ {
+ char* rep = reinterpret_cast<char*>(&x);
+ char tmp;
+ tmp = *rep;
+ *rep = *(rep+1);
+ *(rep+1) = tmp;
+ }
+
+ inline void endian_flip(uint32_t& x)
+ {
+ char* rep = reinterpret_cast<char*>(&x);
+ char tmp;
+ tmp = *rep;
+ *rep = *(rep+3);
+ *(rep+3) = tmp;
+ tmp = *(rep+1);
+ *(rep+1) = *(rep+2);
+ *(rep+2) = tmp;
+ }
+
+ inline void endian_flip(uint64_t& x)
+ {
+ char* rep = reinterpret_cast<char*>(&x);
+ char tmp;
+ tmp = *rep;
+ *rep = *(rep+7);
+ *(rep+7) = tmp;
+ tmp = *(rep+1);
+ *(rep+1) = *(rep+6);
+ *(rep+6) = tmp;
+ tmp = *(rep+2);
+ *(rep+2) = *(rep+5);
+ *(rep+5) = tmp;
+ tmp = *(rep+3);
+ *(rep+3) = *(rep+4);
+ *(rep+4) = tmp;
+ }
+} // namespace integer
+} // namespace boost
+
+#endif // BOOST_ENDIAN_FLIP_HPP
Added: sandbox/bitfield/libs/bitfield/test/pointer_plus_small_int_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/bitfield/libs/bitfield/test/pointer_plus_small_int_test.cpp 2011-01-23 09:04:49 EST (Sun, 23 Jan 2011)
@@ -0,0 +1,75 @@
+#include <iostream>
+#include <cassert>
+#include "boost/integer/bitfield/pointer_plus_bits.hpp"
+
+#include <sys/stat.h>
+#include <errno.h>
+#include <unistd.h>
+#include <netinet/in.h>
+
+#define ASSERT_EQUALS(a,b) assert((a) == (b))
+#define ASSERT_UNEQUALS(a,b) assert((a) != (b))
+#define ASSERT(a) assert((a))
+
+
+void test_tt()
+{
+ typedef boost::integer::pointer_plus_bits<int*,1,bool>::type pint_and_bool;
+
+ int i=0;
+ pint_and_bool v1;
+ ASSERT_EQUALS(v1.pointer(),0);
+ ASSERT_EQUALS(v1.small_int(),false);
+ pint_and_bool v2(&i, true);
+ ASSERT_EQUALS(v2.pointer(),&i);
+ ASSERT_EQUALS(v2.small_int(),true);
+ v1.pointer()=v2.pointer();
+ v1.small_int()=true;
+ ASSERT_EQUALS(v1.pointer(),&i);
+ ASSERT_EQUALS(v1.small_int(),true);
+ //ASSERT_EQUALS(0, 1);
+
+}
+
+void test_tt2()
+{
+ typedef boost::integer::pointer_plus_bits<boost::integer::pointer_plus_bits<int*,1,bool>::type,1, bool>::type pint_and_bool;
+
+ //int i=0;
+ pint_and_bool v1;
+ boost::integer::pointer_plus_bits<int*,1,bool>::type p1 = v1.get_pointer();
+// ASSERT_EQUALS(v1.pointer(),0);
+ ASSERT_EQUALS(v1.small_int(),false);
+ ASSERT_EQUALS(v1.pointer().get_pointer(),0);
+ ASSERT_EQUALS(v1.get_pointer().get_pointer(),0);
+ ASSERT_EQUALS(v1.get_pointer().small_int(),false);
+
+}
+
+#if 0
+void test_tt3()
+{
+ typedef boost::integer::pointer_plus_bitfields<int*,
+ boolean<a>,boolean<b> >::type pint_and_bool;
+
+ //int i=0;
+ pint_and_bool v1;
+ int* p1 = v1.get_pointer();
+// ASSERT_EQUALS(v1.pointer(),0);
+ ASSERT_EQUALS(get<a>(v1),false);
+ ASSERT_EQUALS(get<b>(v1),false);
+
+}
+
+#endif
+
+//-----------------------------------------------------------------------------
+int main(int argc, char *argv[])
+{
+ test_tt();
+ test_tt2();
+
+ std::cout << "All tests successful!\n";
+ 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