Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63302 - in sandbox/SOC/2010/bit_masks: boost/integer boost/integer/details/bft boost/integer/details/bft/ext boost/integer/details/bft/ext/fusion lib/integer/test lib/integer/test/bft_testing
From: bbartmanboost_at_[hidden]
Date: 2010-06-24 22:01:04


Author: bbartman
Date: 2010-06-24 22:01:01 EDT (Thu, 24 Jun 2010)
New Revision: 63302
URL: http://svn.boost.org/trac/boost/changeset/63302

Log:
Now currently down two one reference type and refactored, retested all functions related to the bitfield_tuple and its internal reference type
Removed:
   sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/ref_type_testing.cpp
Text files modified:
   sandbox/SOC/2010/bit_masks/boost/integer/bitfield_tuple.hpp | 273 +++------------------------------------
   sandbox/SOC/2010/bit_masks/boost/integer/details/bft/ext/bitfield_iterator.hpp | 10
   sandbox/SOC/2010/bit_masks/boost/integer/details/bft/ext/fusion/at_impl.hpp | 12 -
   sandbox/SOC/2010/bit_masks/boost/integer/details/bft/reference_builder.hpp | 99 ++++++++++++++
   sandbox/SOC/2010/bit_masks/lib/integer/test/Jamfile.v2 | 1
   5 files changed, 135 insertions(+), 260 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-24 22:01:01 EDT (Thu, 24 Jun 2010)
@@ -389,115 +389,6 @@
         field_type field_;
     };
 
-
- /** Proxy type returned by get functions.
- * This serves as the go between things within this class.
- */
- template <typename MaskInfo>
- struct bitfield_ref {
- private:
- typedef bitfield_ref<MaskInfo> _self;
- public:
- typedef typename MaskInfo::return_type return_type;
-
- /** Internals.
- * bitfield type for extracting individual fields from within the
- * storage_type.
- */
- typedef typename integer::bitfield<
- storage_type,
- MaskInfo::offset::value,
- MaskInfo::offset::value + MaskInfo::field_width::value - 1,
- return_type
- > bitfield_type;
-
-
- /** Reference constructor. */
- explicit bitfield_ref(storage_type& ref)
- :_ref( ref )
- { }
-
-
- /** copy constructor.
- * This is because references are copy constructible.
- */
- bitfield_ref( bitfield_ref<MaskInfo> const& x)
- :_ref( x._ref)
- { }
-
- /** Implicit conversion operator
- * Returns the value retrieved from the mask.
- */
- operator return_type() const {
- return static_cast< return_type >( _ref.get() );
- }
-
- /** Assignment Of return_type into reference.
- * This allows values to be assigned to the get function, as part of
- * the tuple like interface.
- */
- _self const& operator=(return_type const& rhs) {
- _ref.set( rhs );
- return *this;
- }
-
- private:
- // storage reference.
- bitfield_type _ref;
-
- // not default constructible because this is a reference type
- bitfield_ref();
- };
-
- /** Const reference type.
- * This class is used when the storage type is const so that mutability
- * can be removed from the reference type.
- */
- template <typename MaskInfo>
- struct const_bitfield_ref {
- private:
- typedef bitfield_ref<MaskInfo> _self;
- public:
- typedef typename MaskInfo::return_type return_type;
-
- /** Internals bitfield type for extracting individual fields from
- * within the storage_type.
- */
- typedef typename integer::bitfield<
- const storage_type,
- MaskInfo::offset::value,
- MaskInfo::offset::value + MaskInfo::field_width::value - 1,
- return_type
- > bitfield_type;
-
-
- /** Reference constructor. */
- explicit const_bitfield_ref(storage_type const& ref)
- :_ref( ref )
- { }
-
- /** copy constructor.
- * This is because references are copy constructible.
- */
- const_bitfield_ref( bitfield_ref<MaskInfo> const& x)
- :_ref( x.ref)
- { }
-
- /** Implicit conversion operator
- * Returns the value of the bit mask.
- */
- operator return_type() const {
- return _ref.get();
- }
-
- private:
- // storage reference.
- bitfield_type _ref;
-
- // not default constructible because this is a reference type
- const_bitfield_ref();
- };
-
     /** Value constructor.
      * This sets the initial value of the internal data to x.
      * Also functions as the default constructor.
@@ -542,29 +433,6 @@
     }
     //@}
 
-
- /** Meta-member-function
- * searches within member for a bft_element with name_type the same as Name
- * and returns mpl::true_ if it found it and mpl::false_ if not.
- */
- template <typename Name>
- struct name_exists {
- typedef typename mpl::not_<
- is_same <
- typename ::boost::mpl::find_if<
- members,
- details::match_name<
- mpl::_1,
- Name
- >
- >::type,
- typename mpl::end<
- members
- >::type
- >
- >::type type;
- };
-
     /** Get function interfaces.
      * These provide access into the tuple via "reference".
      * If an invalid index or name is provided then then the user will cause
@@ -572,139 +440,52 @@
      */
     //@{
     template <typename Name>
- inline typename disable_if<
- is_same <
- typename mpl::find_if<
- members,
- details::match_name<
- mpl::_1,
- Name
- >
- >::type,
- typename mpl::end<
- members
- >::type
- >,
- bitfield_ref<
- typename mpl::deref<
- typename mpl::find_if<
- members,
- details::match_name<
- mpl::_1,
- Name
- >
- >::type
- >::type
- >
- >::type
+ inline typename details::disable_if_reference_type_by_name<_self,Name>::type
     get() {
- typedef bitfield_ref<
- typename mpl::deref<
- typename mpl::find_if<
- members,
- details::match_name<
- mpl::_1,
- Name
- >
- >::type
- >::type
- > reference_info;
+ typedef typename details::disable_if_reference_type_by_name<
+ _self,
+ Name
+ >::type reference_info;
         return reference_info( _data );
     }
 
 
     template <typename Name>
- inline typename disable_if<
- is_same <
- typename mpl::find_if<
- members,
- details::match_name<
- mpl::_1,
- Name
- >
- >::type,
- typename mpl::end<
- members
- >::type
- >,
- const_bitfield_ref<
- typename mpl::deref<
- typename mpl::find_if<
- members,
- details::match_name<
- mpl::_1,
- Name
- >
- >::type
- >::type
- >
- >::type const
+ inline typename details::disable_if_reference_type_by_name<
+ const _self,
+ Name
+ >::type
     get() const {
- typedef const_bitfield_ref<
- typename mpl::deref<
- typename mpl::find_if<
- members,
- details::match_name<
- mpl::_1,
- Name
- >
- >::type
- >::type
- > const reference_info;
+ typedef typename details::disable_if_reference_type_by_name<
+ const _self,
+ Name
+ >::type reference_info;
         return reference_info( _data );
     }
 
     template <std::size_t Index>
- inline typename enable_if<
- typename mpl::less<
- mpl::size_t<
- Index
- >,
- mpl::size<
- members
- >
- >,
- bitfield_ref<
- typename mpl::at_c<
- members,
- Index
- >::type
- >
+ inline typename details::enable_if_reference_type_by_index<
+ _self,
+ Index
>::type
     get() {
- typedef bitfield_ref<
- typename mpl::at_c<
- members,
- Index
- >::type
- > reference_info;
+ typedef typename details::enable_if_reference_type_by_index<
+ _self,
+ Index
+ >::type reference_info;
         return reference_info(_data);
     }
 
     template <std::size_t Index>
- inline typename enable_if<
- typename mpl::less<
- mpl::size_t<
- Index
- >,
- mpl::size<
- members
- >
- >,
- const_bitfield_ref<
- typename mpl::at_c<
- members,
- Index
- >::type
- >
+ inline typename details::enable_if_reference_type_by_index<
+ const _self,
+ Index
>::type
     get() const {
- typedef const_bitfield_ref<
- typename mpl::at_c<
- members,
- Index
- >::type
- > const reference_info;
+ typedef typename details::enable_if_reference_type_by_index<
+ const _self,
+ Index
+ >::type reference_info;
         return reference_info( _data );
     }
     //@}

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-24 22:01:01 EDT (Thu, 24 Jun 2010)
@@ -54,12 +54,10 @@
     /** Fusion Extension: value_of */
     template<typename Iter>
     struct value_of {
- typedef typename Iter::bitfield_tuple_type::template bitfield_ref<
- typename mpl::at<
- typename Iter::bitfield_tuple_type::members,
- typename Iter::index
- >::type
- > type;
+ typedef typename details::get_reference_type_by_index<
+ BitfieldTuple,
+ Iter::index::value
+ >::type type;
     };
 
     /** Fusion Extension: deref */

Modified: sandbox/SOC/2010/bit_masks/boost/integer/details/bft/ext/fusion/at_impl.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/details/bft/ext/fusion/at_impl.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/details/bft/ext/fusion/at_impl.hpp 2010-06-24 22:01:01 EDT (Thu, 24 Jun 2010)
@@ -21,13 +21,11 @@
 
     template <typename BitfieldTuple, typename N>
     struct apply {
- typedef typename BitfieldTuple::
- template bitfield_ref<
- typename mpl::at<
- typename BitfieldTuple::members,
- N
- >::type
- > type;
+ typedef typename details::get_reference_type_by_index<
+ BitfieldTuple,
+ N::value
+ >::type type;
+
         // non-const at function.
         static type call(BitfieldTuple& bft) {
             return type( bft.template get<N::value>() );

Modified: sandbox/SOC/2010/bit_masks/boost/integer/details/bft/reference_builder.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/details/bft/reference_builder.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/details/bft/reference_builder.hpp 2010-06-24 22:01:01 EDT (Thu, 24 Jun 2010)
@@ -148,6 +148,105 @@
>::type type;
 };
 
+
+template <typename BitfieldTuple, std::size_t Index>
+struct enable_if_reference_type_by_index {
+ // check to make sure index is valid
+ typedef typename mpl::less<
+ mpl::size_t<
+ Index
+ >,
+ mpl::size<
+ typename BitfieldTuple::members
+ >
+ > is_valid_index;
+
+ // get the bitfield_element from members.
+ typedef typename mpl::at_c<
+ typename BitfieldTuple::members,
+ Index
+ >::type bft_element_t;
+
+ // create the reference type
+ typedef typename BitfieldTuple::template bitfield_reference<
+ typename mpl::if_<
+ is_const<BitfieldTuple>,
+ typename add_const<bft_element_t>::type,
+ bft_element_t
+ >::type
+ > reference_type;
+
+ // return the reference type if its valid.
+ typedef typename enable_if<
+ is_valid_index,
+ reference_type
+ >::type type;
+};
+
+
+template <typename BitfieldTuple, typename Name>
+struct get_reference_type_by_name {
+ // search for the name,
+ typedef typename mpl::find_if<
+ typename BitfieldTuple::members,
+ details::match_name<
+ mpl::_1,
+ Name
+ >
+ >::type element_iter;
+
+ // get the end iterator from members.
+ typedef typename mpl::end<
+ typename BitfieldTuple::members
+ >::type member_end;
+
+ // create the bitfield_reference type that will be returned if
+ // disable_if is enabled.
+ typedef typename BitfieldTuple::template bitfield_reference<
+ typename mpl::if_<
+ is_const<BitfieldTuple>,
+ typename add_const<
+ typename mpl::deref<
+ element_iter
+ >::type
+ >::type,
+ typename mpl::deref<
+ element_iter
+ >::type
+ >::type
+ > type;
+
+};
+
+template <typename BitfieldTuple, std::size_t Index>
+struct get_reference_type_by_index {
+ // check to make sure index is valid
+ typedef typename mpl::less<
+ mpl::size_t<
+ Index
+ >,
+ mpl::size<
+ typename BitfieldTuple::members
+ >
+ > is_valid_index;
+
+ // get the bitfield_element from members.
+ typedef typename mpl::at_c<
+ typename BitfieldTuple::members,
+ Index
+ >::type bft_element_t;
+
+ // create the reference type
+ typedef typename BitfieldTuple::template bitfield_reference<
+ typename mpl::if_<
+ is_const<BitfieldTuple>,
+ typename add_const<bft_element_t>::type,
+ bft_element_t
+ >::type
+ > type;
+};
+
+
 }} // end boost::details
 
 #endif

Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/Jamfile.v2
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/Jamfile.v2 (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/Jamfile.v2 2010-06-24 22:01:01 EDT (Thu, 24 Jun 2010)
@@ -33,7 +33,6 @@
         [ compile-fail bft_testing/compile_fail/one_name_two_members.cpp ]
         [ compile bft_testing/compile_pass/bft_member_max_out.cpp ]
         [ run bitfield_tuple_test.cpp ]
- [ run bft_testing/ref_type_testing.cpp ]
         [ run bft_testing/name_accessor_test.cpp ]
         [ run bft_testing/get_interface_test.cpp ]
         [ run bft_testing/compile_pass/fusion_includes.cpp ]

Deleted: sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/ref_type_testing.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/ref_type_testing.cpp 2010-06-24 22:01:01 EDT (Thu, 24 Jun 2010)
+++ (empty file)
@@ -1,103 +0,0 @@
-// Copyright 2010 Brian Bartman.
-// 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)
-
-
-#include <boost/integer/bitfield_tuple.hpp>
-#include <boost/assert.hpp>
-using namespace boost;
-struct red { };
-struct blue { };
-
-
-typedef bitfield_tuple<
- storage<int>,
- member<int, red, 15u>,
- member<int, blue, 17u>
-> bft;
-
-
-typedef details::bitfield_element< char,
-red,mpl::size_t<9>,mpl::size_t<8> > element_1;
-
-typedef details::bitfield_element< char,
-red, mpl::size_t<0>, mpl::size_t<8> > element_2;
-
-typedef details::bitfield_element< char,
-red, mpl::size_t<8>, mpl::size_t<8> > element_3;
-
-typedef details::bitfield_element< char,
-red, mpl::size_t<16>, mpl::size_t<8> > element_4;
-
-typedef details::bitfield_element< char,
-red, mpl::size_t<24>, mpl::size_t<8> > element_5;
-
-int main() {
-
- int data_storage(0);
-
- // simple test entery and retreval.
- {
- typedef bft::bitfield_ref<element_1> ref_type_1;
-
- ref_type_1 test_1( data_storage );
-
- char temp = 'a';
- test_1 = temp;
- BOOST_ASSERT(( test_1 == temp ));
- }
-
- data_storage = 0;
-
- // slightly more complex.
- // multiple fields which arn't next to one another.
- {
- typedef bft::bitfield_ref<element_2> ref_type_1;
- typedef bft::bitfield_ref<element_4> ref_type_2;
-
- // constructing reference types.
- ref_type_1 ref_1(data_storage);
- ref_type_2 ref_2(data_storage);
- ref_1 = 'q';
- ref_2 = 'p';
-
- BOOST_ASSERT(( ref_1 == 'q' ));
- BOOST_ASSERT(( ref_2 == 'p' ));
- }
-
- data_storage = 0;
-
- // case the integer storage type is completely filled with fields.
- {
- // create fake reference type to test..
- typedef bft::bitfield_ref<element_2> ref_type_1;
- typedef bft::bitfield_ref<element_3> ref_type_2;
- typedef bft::bitfield_ref<element_4> ref_type_3;
- typedef bft::bitfield_ref<element_5> ref_type_4;
- //
- ref_type_1 ref_1(data_storage);
- ref_type_2 ref_2(data_storage);
- ref_type_3 ref_3(data_storage);
- ref_type_4 ref_4(data_storage);
-
- ref_1 = 'p';
- ref_2 = 'q';
- ref_3 = 'r';
- ref_4 = 's';
-
- BOOST_ASSERT(( ref_1 == 'p' ));
- BOOST_ASSERT(( ref_2 == 'q' ));
- BOOST_ASSERT(( ref_3 == 'r' ));
- BOOST_ASSERT(( ref_4 == 's' ));
-
- // testing copy constructor
- // ref_type_1 copy_of_ref_1( ref_1 );
- // BOOST_ASSERT(( copy_of_ref_1 == ref_1 ));
- // BOOST_ASSERT(( copy_of_ref_1 == 'p' ));
-
- }
-
-
- 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