Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62728 - in sandbox/SOC/2010/bit_masks: boost/integer lib/integer/test
From: bbartmanboost_at_[hidden]
Date: 2010-06-10 08:34:57


Author: bbartman
Date: 2010-06-10 08:34:55 EDT (Thu, 10 Jun 2010)
New Revision: 62728
URL: http://svn.boost.org/trac/boost/changeset/62728

Log:
added stack allocated base class and unit tests for it as well as data accessing mechanisms
Text files modified:
   sandbox/SOC/2010/bit_masks/boost/integer/bitfield_tuple.hpp | 236 ++++++++++++++++++++++++++++++++++-----
   sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_tuple_test.cpp | 53 ++++++++
   2 files changed, 252 insertions(+), 37 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-10 08:34:55 EDT (Thu, 10 Jun 2010)
@@ -177,52 +177,124 @@
     };
 };
 
-
-/** This structure does all of the assertions related to constraints
- * which must be enforced after all of the arguments have been delt with.
- * This class is a planned refactoring for later on.
+/** This structure is going to be used when an allocator isn't assked for.
+ * This means that the entire class is allocated on the stack.
  */
-template <typename Impl>
-struct bft_base {
+template <typename T>
+struct stack_alloc_base_policy {
+ /** Default Constructor. */
+ stack_alloc_base_policy()
+ :_data()
+ { }
+
+ /** Copy constructor. */
+ stack_alloc_base_policy( stack_alloc_base_policy<T> const& x )
+ :_data( x._data )
+ { }
+
+ /** Value constructor. */
+ stack_alloc_base_policy( T x )
+ :_data( x )
+ { }
+
+ stack_alloc_base_policy<T> const& operator=( stack_alloc_base_policy const& x ) {
+ _data = x._data;
+ return *this;
+ }
+
+ /** get_data () this function exists within this class and the
+ * allocator_base_policy.
+ * Returns a copy of _data.
+ */
+ //@{
+ T const get_data() const { return _data; }
+ T get_data() { return _data; }
+ //@}
 
+ T _data;
 };
 
+/** This isn't implemented yet and shouldn't be used just yet.
+ * This is eventually going to wrap up an pointer to an allocated object which
+ * will be retrievable via a alloc_get function.
+ */
+template <typename T, typename Alloc>
+struct allocator_wraper_base_policy {
+ T const get_data() const { return _data; }
+ T get_data() { return _data; }
+ T _data;
+};
 
-} // end details
-
-
+// Only used for writing clarity and only used once and then undef'ed when
+// before the end of the details namespace/after the end of the
+// bitfield_tuple_base
+#define BOOST_BFT_ARG_PROCESSING_CLASS \
+ details::bft_impl_<T0, \
+ mpl::void_,\
+ mpl::vector<>,\
+ mpl::size_t<0>\
+ >::\
+ template process<T1>::type::\
+ template process<T2>::type::\
+ template process<T3>::type::\
+ template process<T4>::type::\
+ template process<T5>::type::\
+ template process<T6>::type::\
+ template process<T7>::type::\
+ template process<T8>::type::\
+ template process<T9>::type
+
+/** bitfield_tuple base class
+ * This class is responsible for preforming static assertions and dealing with
+ * the parsing of arguments.
+ *
+ * Base Class preconditions.
+ *
+ * 1) Storage policy must not be set to mpl::void_.
+ * (this means that the user didn't specify a stroage policy.)
+ * Enforced, May be removed at a later time when the class is able to
+ * deduce the ammount of storage space, and set the storage policy to
+ * that.
+ *
+ * 2) The storage type must be a POD type.
+ * (This may be changed to possibly allow for array types of PODs.)
+ * Enforced, This may be best suited to being part of the unpacking
+ * of the arguments so that it can be caught earlier then inside the
+ * base class.
+ *
+ * 3) The bitfields specified must not exceed the bitwidth of the storage type.
+ * Enforced. Not going any where, but may be redefined or altered based
+ * on if I allow the supplied storage type to be an array.
+ *
+ *
+ *
+ *
+ *
+ */
 template < typename T0,
- typename T1 = mpl::void_,
- typename T2 = mpl::void_,
- typename T3 = mpl::void_,
- typename T4 = mpl::void_,
- typename T5 = mpl::void_,
- typename T6 = mpl::void_,
- typename T7 = mpl::void_,
- typename T8 = mpl::void_,
- typename T9 = mpl::void_
+ typename T1,
+ typename T2,
+ typename T3,
+ typename T4,
+ typename T5,
+ typename T6,
+ typename T7,
+ typename T8,
+ typename T9
>
-struct bitfield_tuple {
+struct bitfield_tuple_base
+ : BOOST_BFT_ARG_PROCESSING_CLASS
+{
 
- typedef typename details::bft_impl_<T0,
- mpl::void_,
- mpl::vector<>,
- mpl::size_t<0>
- >::
- template process<T1>::type::
- template process<T2>::type::
- template process<T3>::type::
- template process<T4>::type::
- template process<T5>::type::
- template process<T6>::type::
- template process<T7>::type::
- template process<T8>::type::
- template process<T9>::type processed_args;
+ typedef typename bitfield_tuple_base<T0,T1,T2,T3,T4,
+ T5,T6,T7,T8,T9>::type processed_args;
 
     // extracting te Arguments from processed_args relating to
     // the storage policy. Also preforming static assertios
     // where they can be done.
- typedef typename processed_args::storage_policy storage_policy;
+ typedef typename processed_args::storage_policy storage_policy;
+ typedef typename processed_args::field_vector field_vector;
+ typedef typename processed_args::offset offset;
 
     // Precondition:
     // A storage policy must be supplied.
@@ -235,6 +307,32 @@
 
     typedef typename storage_policy::storage_type storage_type;
 
+ // this is only defined if the storage type is a type that is not the
+ // storage_policy_stack which makes this class simple use a stack to
+ // allocate its storage. This leaves an option for the user to select an
+ // allocator.
+ typedef typename mpl::if_<
+ is_same<
+ typename storage_policy::alloc,
+ storage_policy_stack
+ >,
+ typename mpl::void_,
+ storage_policy
+ >::type allocator;
+
+ // get the template to be used as base class so that the bitfield_tuple
+ // class itself can inherit from it.
+ typedef typename mpl::if_<
+ is_same<
+ allocator,
+ mpl::void_
+ >,
+ stack_alloc_base_policy<storage_type>,
+ allocator_wraper_base_policy< storage_type, allocator >
+ >::type allocation_base_policy;
+
+
+
     // precondition: the storage type must be a pod type (for now).
     // NOTE: this may become a documented requirement only.
     BOOST_STATIC_ASSERT(( is_pod<storage_type>::value ));
@@ -247,6 +345,76 @@
         processed_args::offset::value
     ));
 
+ /** Meta-calculations used for enabling and disabling functionality based
+ * on the allocation policy, number of members etc...
+ * The main reason for creating a class such as this is that it makes
+ * the readability of bitfield_tupe higher.
+ * This will also allow me to quickly deduce whether or not two bft types
+ * are equivilant based on a simple set of concepts about the type itself.
+ *
+ */
+ typedef typename is_same<
+ allocator,
+ mpl::void_
+ >::type is_allocator_allocated;
+
+ typedef typename is_same<
+ typename storage_policy::alloc,
+ storage_policy_stack
+ >::type is_stack_allocated;
+
+};
+
+#undef BOOST_BFT_ARG_PROCESSING_CLASS
+
+} // end details
+
+
+template < typename T0,
+ typename T1 = mpl::void_,
+ typename T2 = mpl::void_,
+ typename T3 = mpl::void_,
+ typename T4 = mpl::void_,
+ typename T5 = mpl::void_,
+ typename T6 = mpl::void_,
+ typename T7 = mpl::void_,
+ typename T8 = mpl::void_,
+ typename T9 = mpl::void_
+>
+struct bitfield_tuple
+ : protected details::bitfield_tuple_base<
+ T0,T1,T2,T3,T4,T5,T6,T7,T8,T9
+ >,
+ details::bitfield_tuple_base<
+ T0,T1,T2,T3,T4,T5,T6,T7,T8,T9
+ >::allocation_base_policy
+{
+private:
+ typedef details::bitfield_tuple_base<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9> _base;
+ typedef typename _base::allocation_base_policy _alloc_base;
+
+public:
+ typedef typename _base::is_stack_allocated is_stack_allocated;
+ typedef typename _base::is_allocator_allocated is_allocator_allocated;
+ typedef typename _base::processed_args processed_args;
+ typedef typename _base::field_vector members;
+ typedef typename _base::storage_type storage_type;
+
+
+
+ /** Interface: Stack Allocated.
+ * Retuns a copy of the internally stored type.
+ */
+ //@{
+ storage_type const data( ) const {
+ return this->get_data();
+ }
+
+ storage_type data( ) {
+ return this->get_data();
+ }
+ //@}
+
     
 };
 

Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_tuple_test.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_tuple_test.cpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_tuple_test.cpp 2010-06-10 08:34:55 EDT (Thu, 10 Jun 2010)
@@ -7,6 +7,8 @@
 #include "test_type_list.hpp"
 #include <boost/mpl/front.hpp>
 #include <boost/mpl/find_if.hpp>
+#include <boost/mpl/end.hpp>
+#include <boost/mpl/begin.hpp>
 
 void ignore(...) {}
 
@@ -14,6 +16,11 @@
 struct green { };
 struct blue { };
 
+template <typename T>
+void test_get_data(T const& x, int value) {
+ BOOST_ASSERT(( x.get_data() == value ));
+}
+
 template <typename T, typename U>
 struct match_name
     :is_same<typename T::name_type, U>::type
@@ -82,7 +89,9 @@
     // testing bitfield_element_
     {
         // bitfield_element_
- typedef details::bitfield_element_<int, red, mpl::size_t<5>, mpl::size_t<4> > bft_element_test_1;
+ typedef details::bitfield_element_<
+ int, red, mpl::size_t<5>, mpl::size_t<4>
+ > bft_element_test_1;
         BOOST_ASSERT(( is_same<bft_element_test_1::return_type, int>::value ));
         BOOST_ASSERT(( is_same<bft_element_test_1::name_type, red>::value ));
         BOOST_ASSERT(( bft_element_test_1::offset::value == 5 ));
@@ -90,6 +99,34 @@
 
     }
 
+ // stack allocation policy for bitfield_tuple
+ {
+ // default constructor.
+ details::stack_alloc_base_policy<int> sap_test_1;
+ BOOST_ASSERT(( sap_test_1._data == 0));
+
+ // value constructor
+ details::stack_alloc_base_policy<int> sap_test_2( 2 );
+ BOOST_ASSERT(( sap_test_2._data == 2));
+
+ // copy constructor
+ details::stack_alloc_base_policy<int> sap_test_3( sap_test_2 );
+ BOOST_ASSERT(( sap_test_3._data == 2));
+
+ // assignement.
+ details::stack_alloc_base_policy<int> sap_test_4;
+ sap_test_4 = sap_test_3;
+ BOOST_ASSERT(( sap_test_4._data == 2));
+ sap_test_4 = sap_test_1;
+ BOOST_ASSERT(( sap_test_4._data == 0));
+
+ // const test for get data
+ test_get_data( sap_test_4, 0 );
+
+ // non const test for get data
+ BOOST_ASSERT(( sap_test_4.get_data() == 0));
+
+ }
     // testing for parsing of aruments passed into template parameters.
     {
     
@@ -126,9 +163,19 @@
> temp_vect;
 
     // tesitng so I can learn to use mpl::find_if
+ // for looking up while useing the get<> function in side bitfield_tuple.
     typedef mpl::find_if<temp_vect, match_name<mpl::_1, red> >::type temp_located;
-
-
+ BOOST_MPL_ASSERT_NOT((
+ is_same<
+ temp_located,
+ mpl::end<temp_vect>::type
+ >
+ ));
+
+
+ bft b;
+ b.data();
+ // BOOST_ASSERT(( ));
 
     }
     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