|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r64124 - in sandbox/SOC/2010/bit_masks: boost/bitfield boost/integer boost/integer/detail/bft lib/integer/test/bft_testing
From: bbartmanboost_at_[hidden]
Date: 2010-07-18 10:59:27
Author: bbartman
Date: 2010-07-18 10:59:26 EDT (Sun, 18 Jul 2010)
New Revision: 64124
URL: http://svn.boost.org/trac/boost/changeset/64124
Log:
the pointer member is off to a good start and is currently sortof working
Text files modified:
sandbox/SOC/2010/bit_masks/boost/bitfield/bitfield.hpp | 74 ++++++++++++++++++++++++++++++++++++---
sandbox/SOC/2010/bit_masks/boost/integer/bitfield_tuple.hpp | 18 ++++++++-
sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/arg_parse_impl.hpp | 2
sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/pointer_parsing_meta_functions.hpp | 6 ++
sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/pointer_member_test.cpp | 28 ++++++++++++--
5 files changed, 114 insertions(+), 14 deletions(-)
Modified: sandbox/SOC/2010/bit_masks/boost/bitfield/bitfield.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/bitfield/bitfield.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/bitfield/bitfield.hpp 2010-07-18 10:59:26 EDT (Sun, 18 Jul 2010)
@@ -12,10 +12,10 @@
#ifndef BOOST_INTEGER_BITFIELD__HPP
#define BOOST_INTEGER_BITFIELD__HPP
-
+#include <boost/integer/detail/bft/pointer_parsing_meta_functions.hpp>
#include <cstddef>
#include <boost/static_assert.hpp>
-
+#include <boost/mpl/void.hpp>
#include <cassert>
#include <limits>
//#include <netinet/in.h>
@@ -28,7 +28,7 @@
};
//-----------------------------------------------------------------------------
- template <class, std::size_t, std::size_t, class, class> class bitfield;
+ // template <class, std::size_t, std::size_t, class, class> class bitfield;
#if 0
template <class R, class V>
@@ -156,9 +156,17 @@
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;
+ , typename REFERENCE_TYPE=VALUE_TYPE&, typename PACKAGE_INFO = mpl::void_ >
+ class bitfield;
+
+ template <
+ typename STORAGE_TYPE,
+ std::size_t F,
+ std::size_t L,
+ typename VALUE_TYPE,
+ typename REFERENCE_TYPE>
+ class bitfield <STORAGE_TYPE, F,L,VALUE_TYPE, REFERENCE_TYPE,mpl::void_ >{
+ typedef bitfield<STORAGE_TYPE, F, L, VALUE_TYPE, REFERENCE_TYPE,mpl::void_> this_type;
public:
//! storage type of the bitfield support
typedef STORAGE_TYPE storage_type;
@@ -411,6 +419,60 @@
);
+
+template <
+ typename STORAGE_TYPE,
+ std::size_t F,
+ std::size_t L,
+ typename VALUE_TYPE,
+ typename REFERENCE_TYPE,
+ typename MASK,
+ typename POLICY
+>
+class bitfield <
+ STORAGE_TYPE,
+ F,
+ L,
+ VALUE_TYPE,
+ REFERENCE_TYPE,
+ ::boost::detail::pointer_member::pointer_member_info<MASK,POLICY> >
+{
+ typedef bitfield <
+ STORAGE_TYPE,
+ F,
+ L,
+ VALUE_TYPE,
+ REFERENCE_TYPE,
+ ::boost::detail::pointer_member::pointer_member_info<MASK,POLICY>
+ > _self;
+public:
+
+ typedef STORAGE_TYPE storage_type;
+ typedef VALUE_TYPE value_type;
+ typedef REFERENCE_TYPE reference_type;
+
+ typedef MASK get_mask;
+ typedef integral_constant< typename MASK::value_type, ~MASK::value > set_mask;
+ typedef POLICY field_policy;
+
+ /** constructor over the storage type. */
+ explicit bitfield(storage_type& field) :_field(field) { }
+
+ /** Copy Constructor. TODO: figure out if i need this or not. */
+ bitfield(_self const& x) :_field( x._field ) { }
+
+ /** Set function. */
+ void set( value_type x) {
+ _field = (_field & set_mask::value) | (typename get_mask::value_type(x) & get_mask::value);
+ }
+
+ value_type get() const {
+ return value_type(_field & get_mask::value);
+ }
+private:
+ storage_type& _field;
+};
+
}}
#endif
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-07-18 10:59:26 EDT (Sun, 18 Jul 2010)
@@ -6,6 +6,7 @@
#ifndef BOOST_BITFIELD_TUPLE_HPP
#define BOOST_BITFIELD_TUPLE_HPP
+
#include <boost/config.hpp>
#ifdef BOOST_MSVC
#pragma warning(push)
@@ -23,6 +24,7 @@
#include <boost/mpl/at.hpp>
#include <boost/mpl/less.hpp>
#include <boost/mpl/size.hpp>
+#include <boost/type_traits/add_reference.hpp>
#include <boost/integer/detail/bft/reference_builder.hpp>
#include <boost/integer/detail/bft/ext/bitfield_tuple_fusion_includes.hpp>
#include <boost/integer/detail/fusion_ext_includes.hpp>
@@ -74,7 +76,19 @@
BitfieldElement::offset::value
+
BitfieldElement::field_width::value - 1,
- return_type
+ return_type,
+ typename add_reference<return_type>::type,
+ typename mpl::if_<
+ is_same<
+ typename BitfieldElement::mask,
+ mpl::void_
+ >,
+ mpl::void_,
+ detail::pointer_member::pointer_member_info<
+ typename BitfieldElement::mask,
+ typename BitfieldElement::policy
+ >
+ >::type
> field_type;
/** Reference constructor. */
@@ -101,7 +115,7 @@
* This allows values to be assigned to the get function, as part of
* the tuple like interface.
*/
- _self const& operator=(return_type const& rhs) {
+ _self const& operator=(return_type rhs) {
field_.set( rhs );
return *this;
}
Modified: sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/arg_parse_impl.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/arg_parse_impl.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/arg_parse_impl.hpp 2010-07-18 10:59:26 EDT (Sun, 18 Jul 2010)
@@ -457,7 +457,7 @@
typedef typename mpl::push_back<
FieldVector,
bitfield_element<
- ReturnType,
+ ReturnType*,
Name,
data_offset,
size_of_storage,
Modified: sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/pointer_parsing_meta_functions.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/pointer_parsing_meta_functions.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/pointer_parsing_meta_functions.hpp 2010-07-18 10:59:26 EDT (Sun, 18 Jul 2010)
@@ -137,7 +137,11 @@
};
-
+template <typename Mask, typename Policy>
+struct pointer_member_info {
+ typedef Mask mask;
+ typedef Policy policy;
+};
}}} // end boost::detail::pointer_member
Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/pointer_member_test.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/pointer_member_test.cpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/pointer_member_test.cpp 2010-07-18 10:59:26 EDT (Sun, 18 Jul 2010)
@@ -6,14 +6,34 @@
#include <boost/integer/bitfield_tuple.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/type_traits/is_same.hpp>
+#include <iostream>
+
using namespace boost;
using namespace boost::bitfields;
struct rd;
-typedef bitfield_tuple<pointer<int, rd> > test_type;
+typedef bitfield_tuple< pointer<int, rd> > test_type_1;
+// typedef bitfield_tuple< member<int*,rd, bit_width<int*>::value - 2> > test_type_2;
int main() {
- test_type t;
-
- return 0;
+ {
+ test_type_1 t1;
+ int i=0;
+ // std::cout << sizeof(&i) << std::endl;
+ // BOOST_TEST(false);
+ t1.get<rd>() = &i;
+ BOOST_TEST(*t1.get<rd>() == 0);
+ }
+ // testing member<int*,rd, width of pointer-2>
+ {
+
+ // int i = 0;
+ // test_type_2 t2;
+ // main issue with this is that the pointer type may not be retrieved
+ // correctly using bitfield however this shouldn't be an issue if I provide
+ // a specialization for bitfield to operate on pointer types.
+ // t2.get<rd>() = &i;
+ // BOOST_TEST( t2.get<rd>() == &i );
+ }
+ return boost::report_errors();
}
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