Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63300 - in sandbox/SOC/2010/bit_masks: boost/integer boost/integer/details/bft lib/integer/test/bft_testing
From: bbartmanboost_at_[hidden]
Date: 2010-06-24 19:01:29


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

Log:
finished first steps to switching to a singe reference type
Text files modified:
   sandbox/SOC/2010/bit_masks/boost/integer/bitfield_tuple.hpp | 46 +++++++++++++++++++++++++++---
   sandbox/SOC/2010/bit_masks/boost/integer/details/bft/reference_builder.hpp | 59 +++++++++++++++++++++++++++++++++------
   sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/reference_builder_test.cpp | 22 ++++++++++++++
   3 files changed, 112 insertions(+), 15 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 19:01:28 EDT (Thu, 24 Jun 2010)
@@ -339,18 +339,54 @@
     private:
         typedef bitfield_reference<BitfieldElement> _self;
     public:
+ typedef typename BitfieldElement::return_type return_type;
+ typedef typename mpl::if_<
+ is_const< BitfieldElement >,
+ const storage_type,
+ storage_type
+ >::type storage_t;
             
- /*typedef typename integer::bitfield<
- storage_type,
- MaskInfo::offset::value,
- MaskInfo::offset::value + MaskInfo::field_width::value - 1,
+ // typedef typename Bitfield
+ typedef integer::bitfield<
+ storage_t,
+ BitfieldElement::offset::value,
+ BitfieldElement::offset::value
+ +
+ BitfieldElement::field_width::value - 1,
             return_type
> field_type;
 
+ /** Reference constructor. */
+ explicit bitfield_reference(storage_t& field)
+ :field_( field )
+ { }
+
+
+ /** copy constructor.
+ * This is because references are copy constructible.
+ */
+ bitfield_reference( _self const& x)
+ :field_( x.field_ )
+ { }
+
+ /** Implicit conversion operator
+ * Returns the value retrieved from the mask.
+ */
+ inline operator return_type() const {
+ return field_.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) {
+ field_.set( rhs );
+ return *this;
+ }
 
     private:
         field_type field_;
- */
     };
 
     

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 19:01:28 EDT (Thu, 24 Jun 2010)
@@ -15,7 +15,7 @@
  * and returning the correct reference type which will allow for only one
  * reference type class within bitfield_tuple.
  */
-namespace boost { namespace detials {
+namespace boost { namespace details {
 
 
 
@@ -84,7 +84,7 @@
  * correct qualifiers. This will take most or all of the guess work out of
  * creating reference types when needed.
  */
-template <typename BitfieldTuple, typename Name, typename CVQualifiers>
+template <typename BitfieldTuple, typename Name, typename CQualifier>
 struct make_reference_type_by_name {
 
     typedef typename find_by_element_name<BitfieldTuple,Name>::type bft_element;
@@ -94,22 +94,61 @@
     // correctly.
     
     typedef typename mpl::if_<
- typename is_const<CVQualifiers>::type,
+ typename is_const<CQualifier>::type,
         typename add_const<bft_element>::type,
         bft_element
>::type bft_element_c_qualifier_applied;
 
- typedef typename mpl::if_<
- typename is_volatile<CVQualifiers>::type,
- typename add_volatile<bft_element_c_qualifier_applied>::type,
- bft_element_c_qualifier_applied
- >::type bft_element_v_qualifier_applied;
 
- // typedef
- // volatile
+ typedef typename BitfieldTuple::template bitfield_reference<
+ bft_element_c_qualifier_applied
+ > type;
 };
 
 
+template <typename BitfieldTuple, typename Name>
+struct disable_if_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 reference type what 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
+ > reference_type;
+
+ // make disable_if statement.
+ typedef typename disable_if<
+ is_same <
+ element_iter,
+ member_end
+ >,
+ reference_type
+ >::type type;
+
+
+};
 
 }} // end boost::details
 

Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/reference_builder_test.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/reference_builder_test.cpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/reference_builder_test.cpp 2010-06-24 19:01:28 EDT (Thu, 24 Jun 2010)
@@ -10,8 +10,30 @@
 
 using namespace boost;
 
+struct red;
+struct green;
+struct salmon;
+struct blue;
+
+typedef bitfield_tuple<
+ member<char,red,4>,
+ member<unsigned char, green,5>,
+ storage<std::size_t>,
+ filler<3>,
+ member<int, salmon, 16>,
+ flag<blue>,
+ bit_align<32>
+> test_tuple_1;
 
 int main() {
+ {
+ typedef details::disable_if_reference_type_by_name<
+ const test_tuple_1,
+ salmon
+ >::type ref_t;
+ std::size_t store_house = 0 ;
+ ref_t ref(store_house);
+ }
 
     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