Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62983 - in sandbox/SOC/2010/bit_masks: boost/integer boost/integer/details/bft/ext boost/integer/details/bit_mask_group_fusion_ext lib/integer/test/bft_testing
From: bbartmanboost_at_[hidden]
Date: 2010-06-15 13:06:17


Author: bbartman
Date: 2010-06-15 13:06:16 EDT (Tue, 15 Jun 2010)
New Revision: 62983
URL: http://svn.boost.org/trac/boost/changeset/62983

Log:
fixed const correctness issue within the get interface of the bitfield_tuple
Text files modified:
   sandbox/SOC/2010/bit_masks/boost/integer/bitfield_tuple.hpp | 80 ++++++++++++++++++++++++++++++++++------
   sandbox/SOC/2010/bit_masks/boost/integer/details/bft/ext/bitfield_iterator.hpp | 30 +++++++++++++++
   sandbox/SOC/2010/bit_masks/boost/integer/details/bit_mask_group_fusion_ext/bit_mask_group_iterator.hpp | 7 ++-
   sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/fusion_integration_testing.cpp | 8 +++
   sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/get_interface_test.cpp | 24 ++++++++----
   5 files changed, 125 insertions(+), 24 deletions(-)

Modified: sandbox/SOC/2010/bit_masks/boost/integer/bitfield_tuple.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/bitfield_tuple.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/bitfield_tuple.hpp 2010-06-15 13:06:16 EDT (Tue, 15 Jun 2010)
@@ -17,7 +17,6 @@
 #include <boost/mpl/less.hpp>
 #include <boost/mpl/size.hpp>
 #include <string>
-
 #include <boost/integer/details/bft/ext/bitfield_tuple_fusion_includes.hpp>
 
 namespace boost {
@@ -52,7 +51,7 @@
     /** Proxy type returned by get functions.
      * This serves as the go between things within this class.
      */
- template <typename MaskInfo>
+ template <typename Mask_Info>
     struct bit_ref {
 
         /** typedefs
@@ -62,8 +61,8 @@
          * mask - contains all information needed to iteract with data in the
          * the stroage.
          */
- typedef typename MaskInfo::return_type return_type;
- typedef bit_ref<MaskInfo> _self;
+ typedef typename Mask_Info::return_type return_type;
+ typedef bit_ref<Mask_Info> _self;
         typedef typename make_unsigned<return_type>::type unsigned_return_type;
         typedef typename make_unsigned<
             storage_type
@@ -74,8 +73,8 @@
          */
         typedef typename integer::bitfield<
             unsigned_storage_type,
- MaskInfo::offset::value,
- MaskInfo::offset::value + MaskInfo::field_width::value - 1
+ Mask_Info::offset::value,
+ Mask_Info::offset::value + Mask_Info::field_width::value - 1
> bitfield_type;
 
 
@@ -98,7 +97,7 @@
         /** copy constructor.
          * This is because references are copy construtible.
          */
- // bit_ref( bit_ref<MaskInfo> const& x)
+ // bit_ref( bit_ref<Mask_Info> const& x)
         // :_ref( x )
         // { }
         
@@ -127,6 +126,63 @@
         bit_ref();
     };
 
+ template <typename Mask_Info>
+ struct const_bit_ref {
+
+ /** typedefs
+ * return_type - is the type which is retrieved from
+ * within storage is turned into and returned as.
+ *
+ * mask - contains all information needed to iteract with data in the
+ * the stroage.
+ */
+ typedef typename Mask_Info::return_type return_type;
+ typedef bit_ref<Mask_Info> _self;
+ typedef typename make_unsigned<return_type>::type unsigned_return_type;
+ typedef typename make_unsigned<
+ storage_type
+ >::type const unsigned_storage_type;
+
+ /** Internals bitfield type for extracting individual fields from
+ * within the storage_type.
+ */
+ typedef typename integer::bitfield<
+ unsigned_storage_type,
+ Mask_Info::offset::value,
+ Mask_Info::offset::value + Mask_Info::field_width::value - 1
+ > bitfield_type;
+
+
+ /** Reference constructor.
+ * Because the bit_ref is an abstraction of a reference then it also
+ * must behave like a reference type.
+ */
+ const_bit_ref(storage_type const& ref)
+ :_ref( *reinterpret_cast<unsigned_storage_type*>(&ref) )
+ { }
+
+ /** copy constructor.
+ * This is because references are copy construtible.
+ */
+ // bit_ref( bit_ref<Mask_Info> const& x)
+ // :_ref( x )
+ // { }
+
+ /** Implicit conversion operator
+ * this allows for implicit conversion to the return_type.
+ */
+ operator return_type() const {
+ return static_cast< return_type >( _ref.get() );
+ }
+
+ private:
+ // storage reference.
+ bitfield_type _ref;
+
+ // not default constructible because this is a reference type
+ const_bit_ref();
+ };
+
 
     /** Value constructor.
      * This sets the initial value of the internal data to x.
@@ -241,7 +297,7 @@
                 members
>::type
>,
- bit_ref<
+ const_bit_ref<
             typename mpl::deref<
                 typename mpl::find_if<
                     members,
@@ -254,7 +310,7 @@
>
>::type const
     get() const {
- typedef bit_ref<
+ typedef const_bit_ref<
             typename mpl::deref<
                 typename mpl::find_if<
                     members,
@@ -305,15 +361,15 @@
                     members
>
>,
- bit_ref<
+ const_bit_ref<
                 typename mpl::at_c<
                     members,
                     Index
>::type
>
- >::type const
+ >::type
     get() const {
- typedef bit_ref<
+ typedef const_bit_ref<
             typename mpl::at_c<
                 members,
                 Index

Modified: sandbox/SOC/2010/bit_masks/boost/integer/details/bft/ext/bitfield_iterator.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/details/bft/ext/bitfield_iterator.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/details/bft/ext/bitfield_iterator.hpp 2010-06-15 13:06:16 EDT (Tue, 15 Jun 2010)
@@ -2,3 +2,33 @@
 // 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)
+
+#ifndef BOOST_BITFIELD_FUSION_ITERATOR_HPP
+#define BOOST_BITFIELD_FUSION_ITERATOR_HPP
+#include <cstddef>
+#include <boost/mpl/int.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/minus.hpp>
+#include <boost/type_traits/is_const.hpp>
+#include <boost/fusion/iterator/iterator_facade.hpp>
+
+namespace boost { namespace fusion {
+
+/** Fusion Iterator for bitfield_tuple class.
+ * This is an iterator over an associative array type.
+ */
+template <typename Bitfeid_Tuple, std::size_t Pos>
+struct bitfield_tuple_iterator
+ : iterator_facade<
+ bitfield_tuple_iterator<Bitfeid_Tuple, Pos>,
+ random_access_traversal_tag
+ >
+{
+
+};
+
+}} // end boost::fusion
+
+
+#endif

Modified: sandbox/SOC/2010/bit_masks/boost/integer/details/bit_mask_group_fusion_ext/bit_mask_group_iterator.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/details/bit_mask_group_fusion_ext/bit_mask_group_iterator.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/details/bit_mask_group_fusion_ext/bit_mask_group_iterator.hpp 2010-06-15 13:06:16 EDT (Tue, 15 Jun 2010)
@@ -20,15 +20,16 @@
  * As the type bit_mask_group is trivially constructible, copyable and
  * destructable there is no member to actually hold any data.
  */
-template<typename MaskGroup, unsigned int Pos>
+template<typename Mask_Group, unsigned int Pos>
 struct bit_mask_group_iterator
     : iterator_facade<
- bit_mask_group_iterator<MaskGroup, Pos>,
+ bit_mask_group_iterator<Mask_Group, Pos>,
         random_access_traversal_tag
>
 {
     // TODO: At a later time add preconditions for the iterator.
- typedef MaskGroup mask_group;
+ // maybe
+ typedef Mask_Group mask_group;
     typedef boost::mpl::int_<Pos> index;
     typedef boost::fusion::random_access_traversal_tag category;
 

Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/fusion_integration_testing.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/fusion_integration_testing.cpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/fusion_integration_testing.cpp 2010-06-15 13:06:16 EDT (Tue, 15 Jun 2010)
@@ -6,7 +6,7 @@
 
 #include <boost/integer/bitfield_tuple.hpp>
 #include <boost/assert.hpp>
-
+#include <boost/mpl/assert.hpp>
 
 using namespace boost;
 
@@ -25,6 +25,12 @@
 
 
 int main() {
+ // tag of testing
+ {
+ // bitfield_tuple_tag
+ typedef fusion::traits::tag_of<test_tuple>::type tag;
+ BOOST_MPL_ASSERT(( is_same< tag, fusion::bitfield_tuple_tag> ));
+ }
     /*
     bmg_t bmg;
 

Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/get_interface_test.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/get_interface_test.cpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/get_interface_test.cpp 2010-06-15 13:06:16 EDT (Tue, 15 Jun 2010)
@@ -35,20 +35,28 @@
         BOOST_ASSERT((test_1.get<red>() == 14));
         BOOST_ASSERT(( test_1.get<salmon>() == 6));
 
-/* BOOST_ASSERT((
+ BOOST_ASSERT((
             const_cast<
                 test_tuple const&
>(test_1).get<salmon>() == 6
         ));
-*/
- // XXX fix this at a later time maybe in a subsequent draft of the
- // data structure.
- // testing negative values
- // test_1.get<salmon>() = -6;
- //BOOST_ASSERT(( test_1.get<salmon>() == -6));
     }
+
+ // get using an index.
     {
-
+ test_tuple test_2;
+ test_2.get<0>() = 15;
+ test_2.get<1>() = 14;
+ test_2.get<2>() = 6;
+ BOOST_ASSERT((test_2.get<0>() == 15));
+ BOOST_ASSERT((test_2.get<1>() == 14));
+ BOOST_ASSERT((test_2.get<2>() == 6));
+
+ BOOST_ASSERT((
+ const_cast<
+ test_tuple const&
+ >(test_2).get<2>() == 6
+ ));
     }
     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