Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64522 - in sandbox/SOC/2010/bit_masks: boost/integer boost/integer/detail/bitfield_vector lib/integer/test/bitfield_vector_testing
From: bbartmanboost_at_[hidden]
Date: 2010-08-01 12:22:15


Author: bbartman
Date: 2010-08-01 12:22:15 EDT (Sun, 01 Aug 2010)
New Revision: 64522
URL: http://svn.boost.org/trac/boost/changeset/64522

Log:
working on creating a test suite for the implementation functions relating to the of the reallocation functon within the bitfield_vector
Text files modified:
   sandbox/SOC/2010/bit_masks/boost/integer/bitfield_vector.hpp | 88 +++++++++++++++++++++--------------
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_base.hpp | 5 +
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_member_impl.hpp | 97 +++++++++++++++++++++++----------------
   sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/member_impl_test.cpp | 36 ++++++++++++++
   sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/reference_type_test.cpp | 12 ++++
   5 files changed, 159 insertions(+), 79 deletions(-)

Modified: sandbox/SOC/2010/bit_masks/boost/integer/bitfield_vector.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/bitfield_vector.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/bitfield_vector.hpp 2010-08-01 12:22:15 EDT (Sun, 01 Aug 2010)
@@ -7,11 +7,13 @@
 #define BOOST_BITFIELD_VECTOR_HPP
 #include <memory>
 #include <boost/integer/detail/bitfield_vector/bitfield_vector_member_impl.hpp>
+#include <boost/integer/detail/bitfield_vector/bitfield_vector_base.hpp>
+#include <cstring>
 
 namespace boost {
 
-template <typename,typename>
-class vector;
+// template <typename,typename>
+// class vector;
 
 template <typename T,std::size_t>
 struct bits;
@@ -32,55 +34,64 @@
 //@}
 
 
-template <typename T, std::size_t Width, typename Allocator >
-class vector< bits<T,Width>, Allocator > {
- typedef vector< bits<T,Width>, Allocator > _self;
+template < typename T,
+ std::size_t Width,
+ typename Allocator = std::allocator<unsigned char>
+>
+class bitfield_vector
+ :protected detail::bitfield_vector_base<T,Allocator>
+{
+ typedef bitfield_vector< T,Width, Allocator > _self;
+ typedef detail::bitfield_vector_base<T,Allocator> _base;
+
 public:
- typedef bf_vector_iterator<T,Width> iterator;
- typedef const_bf_vector_iterator<T,Width> const_iterator;
- typedef bf_vector_reverse_iterator<T,Width> reverse_iterator;
- typedef const_bf_vector_reverse_iterator<T,Width> const_reverse_iterator;
- typedef T value_type;
-
- typedef Allocator allocator_type;
- typedef typename Allocator::size_type size_type;
- typedef typename Allocator::difference_type difference_type;
- typedef typename Allocator::pointer pointer;
- typedef typename Allocator::const_pointer const_pointer;
+ typedef bf_vector_iterator<T,Width> iterator;
+ typedef const_bf_vector_iterator<T,Width> const_iterator;
+ typedef bf_vector_reverse_iterator<T,Width> reverse_iterator;
+ typedef const_bf_vector_reverse_iterator<T,Width> const_reverse_iterator;
+ typedef T value_type;
+ typedef Allocator allocator_type;
+ typedef std::size_t size_type;
+ typedef std::ptrdiff_t difference_type;
+ typedef typename _base::storage_type* pointer;
+ typedef typename _base::storage_type const* const_pointer;
     
     class reference {
- friend class vector;
+ friend class bitfield_vector;
         reference();
     public:
         ~reference();
- operator value_type () const;
- reference& operator= (const value_type x);
- reference& operator= (const reference& x);
+ operator value_type() const;
+ reference& operator= (value_type const& x);
+ reference& operator= (reference const & x);
         void flip();
     };
 
     class const_reference {
- friend class vector;
+ friend class bitfield_vector;
         const_reference();
     public:
         ~const_reference();
- // operator value_type () const;
- const_reference& operator= (const value_type x);
- const_reference& operator= (const const_reference& x);
+ operator value_type () const;
+ // const_reference& operator=(const value_type x);
+ const_reference& operator=(const_reference const& x);
         void flip();
     };
 
 
- explicit vector(const Allocator& = Allocator() );
- explicit vector(size_type n, const T& value= T(),
- const Allocator& = Allocator() );
+ explicit bitfield_vector(Allocator const& alloc = Allocator() )
+ :_base(alloc)
+ { }
+
+ explicit bitfield_vector(size_type n, T const& value= T(),
+ Allocator const& = Allocator() );
     template <class InputIterator>
- vector(InputIterator first, InputIterator last,
- const Allocator& = Allocator());
- vector( const vector<T,Allocator>& x );
- ~vector();
+ bitfield_vector(InputIterator first, InputIterator last,
+ Allocator const& = Allocator());
+ bitfield_vector(_self const& x );
+ ~bitfield_vector();
 
- _self& operator=(const _self& x);
+ _self& operator=(_self const& x);
 
     iterator begin();
     iterator end();
@@ -112,11 +123,11 @@
     template <class InputIterator>
     void assign(InputIterator first, InputIterator last);
 
- void assign(size_type n, const value_type& u);
- void push_back(const value_type& x);
+ void assign(size_type n, value_type const& u);
+ void push_back(value_type const& x);
     void pop_back();
- iterator insert(iterator position, const value_type& x);
- void insert(iterator position, size_type n, const value_type& x);
+ iterator insert(iterator position, value_type const& x);
+ void insert(iterator position, size_type n, value_type const& x);
 
     template <class InputIterator>
     void insert(iterator position, InputIterator first, InputIterator last);
@@ -126,6 +137,11 @@
     void swap(_self& vec);
     void clear();
     allocator_type get_allocator() const;
+
+protected:
+ void check_for_resizing() {
+ // next_allocation_size<Width>
+ }
 };
 
 } // end boost

Modified: sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_base.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_base.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_base.hpp 2010-08-01 12:22:15 EDT (Sun, 01 Aug 2010)
@@ -23,8 +23,9 @@
  */
 template <typename T, typename Allocator>
 struct bitfield_vector_base {
+ typedef unsigned char storage_type;
     typedef T value_type;
- typedef typename Allocator::template rebind<unsigned char>::other
+ typedef typename Allocator::template rebind<storage_type>::other
         rebound_alloc_type;
     typedef Allocator allocator;
 
@@ -109,7 +110,7 @@
 
     /** Calles allocate unless n = 0. */
     typename rebound_alloc_type::pointer allocate_impl(std::size_t n) {
- return n != 0 ? _impl.allocate( n ): 0;
+ return n != 0 ? _impl.allocate(n): 0;
     }
 
     /** Calles deallocate unless ptr = 0. */

Modified: sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_member_impl.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_member_impl.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_member_impl.hpp 2010-08-01 12:22:15 EDT (Sun, 01 Aug 2010)
@@ -6,51 +6,66 @@
 #ifndef BOOST_BITFIELD_MEMBER_IMPL_HPP
 #define BOOST_BITFIELD_MEMBER_IMPL_HPP
 #include "bitfield_vector_base.hpp"
-
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/arithmetic.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/equal.hpp>
 
 namespace boost { namespace detail {
 
-/** bitfield_vector_member_impl
- * This implements the members basic member functions so that they can be
- * tested outside of the bitfield_vector it self and the used to implement
- * the rest of the functionalility of the bitfield_vector with out as much
- * trouble.
- *
- *
- * This level of the data structures deals with constructing the object
- * correctly and the implementing a lot of details related to the
- * bitfeild_vector which would other wise be private.
- *
- */
-template <typename T, typename Alloc>
-struct bitfield_vector_member_impl
- :bitfield_vector_base<T,Alloc>
-{
-
- /** Base class of the bitfield_vector_impl. */
- typedef bitfield_vector_base<T,Alloc> _base;
-
- /** Default Constructor. */
- bitfield_vector_member_impl()
- :_base()
- { }
-
- /** Constructor over an allocator. */
- bitfield_vector_member_impl(typename _base::allocator const& alloc)
- :_base(alloc)
- { }
-
- /** Array Constructor. */
- bitfield_vector_member_impl(std::size_t n)
- :_base(n)
- { }
-
- /** Array + Allocator Constructor. */
- bitfield_vector_member_impl(std::size_t n,
- typename _base::allocator const& alloc)
- :_base(n,alloc)
- { }
+template <std::size_t Width, bool = bool((Width%8) > 0)>
+struct next_allocation_size;
+
+
+// NOT divible by 8
+template <std::size_t Width>
+struct next_allocation_size<Width, true> {
+ std::size_t compute_8_bit_boundry(std::size_t bits) {
+ if((bits%8) == 0) {
+ return bits;
+ }else{
+ return bits + std::size_t(8-(bits%8));
+ }
+ }
+
+ typedef typename mpl::divides<
+ typename mpl::plus<
+ mpl::size_t<Width>,
+ typename mpl::minus<
+ mpl::size_t<8>,
+ typename mpl::modulus<
+ mpl::size_t<Width>,
+ mpl::size_t<8>
+ >::type
+ >::type
+ >::type,
+ mpl::size_t<8>
+ >::type first_alloc_size;
+
+
+ std::size_t operator()(std::ptrdiff_t current_size, std::size_t bits_used) {
+ if(current_size == 0) {
+ return std::size_t(first_alloc_size::value);
+ }
+ return compute_8_bit_boundry(bits_used*2)/8;
+ }
+};
 
+// IS divible by 8
+template <std::size_t Width>
+struct next_allocation_size<Width,false> {
+ typedef typename mpl::divides<
+ mpl::size_t<Width>,
+ mpl::size_t<8>
+ >::type first_return_value;
+
+ std::size_t operator()(std::ptrdiff_t current_size, std::size_t) {
+ if(current_size == 0) {
+ return first_return_value::value;
+ }else{
+ return current_size * 2;
+ }
+ }
 };
 
 }} // end boost::detail

Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/member_impl_test.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/member_impl_test.cpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/member_impl_test.cpp 2010-08-01 12:22:15 EDT (Sun, 01 Aug 2010)
@@ -0,0 +1,36 @@
+// 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_vector.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+using namespace boost::detail;
+
+int main() {
+ // Covering trivail case for next_allocation size
+ // width = to width of a char.
+ {
+ BOOST_TEST(next_allocation_size<8>()(0,0) == 1);
+ BOOST_TEST(next_allocation_size<8>()(2,0) == 4);
+
+ BOOST_TEST(next_allocation_size<16>()(0,0) == 2);
+ BOOST_TEST(next_allocation_size<16>()(4,0) == 8);
+ }
+ // more complex case where the width is NOT divisible by number of bits in
+ // char.
+ {
+ // less then 8.
+ BOOST_TEST(next_allocation_size<3>()(0,0) == 1);
+ BOOST_TEST(next_allocation_size<3>()(1,3) == 1);
+ BOOST_TEST(next_allocation_size<3>()(2,6) == 2);
+
+ // greater then 8
+ BOOST_TEST(next_allocation_size<9>()(0,0) == 2);
+ BOOST_TEST(next_allocation_size<9>()(1,9) == 3);
+ BOOST_TEST(next_allocation_size<9>()(2,18) == 5);
+ }
+ return boost::report_errors();
+}

Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/reference_type_test.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/reference_type_test.cpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/reference_type_test.cpp 2010-08-01 12:22:15 EDT (Sun, 01 Aug 2010)
@@ -0,0 +1,12 @@
+// 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_vector.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+int main() {
+ 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