Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64501 - in sandbox/SOC/2010/bit_masks: boost/integer boost/integer/detail/bitfield_vector lib/integer/test lib/integer/test/bitfield_vector_testing
From: bbartmanboost_at_[hidden]
Date: 2010-07-31 11:13:52


Author: bbartman
Date: 2010-07-31 11:13:51 EDT (Sat, 31 Jul 2010)
New Revision: 64501
URL: http://svn.boost.org/trac/boost/changeset/64501

Log:
attempting to implement things related to the allocator which is proving more difficult then previously expected.

Added:
   sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_base_test.cpp (contents, props changed)
Text files modified:
   sandbox/SOC/2010/bit_masks/boost/integer/bitfield_vector.hpp | 3
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_base.hpp | 113 ++++++++++++++++++++++++++++++++++++++++
   sandbox/SOC/2010/bit_masks/lib/integer/test/Jamfile.v2 | 1
   3 files changed, 115 insertions(+), 2 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-07-31 11:13:51 EDT (Sat, 31 Jul 2010)
@@ -5,8 +5,8 @@
 
 #ifndef BOOST_BITFIELD_VECTOR_HPP
 #define BOOST_BITFIELD_VECTOR_HPP
-#include <cstddef>
 #include <memory>
+#include <boost/integer/detail/bitfield_vector/bitfield_vector_base.hpp>
 
 namespace boost {
 
@@ -24,7 +24,6 @@
 template<typename T, std::size_t Width>
 struct const_bf_vector_iterator { };
 
-
 template<typename T, std::size_t Width>
 struct bf_vector_reverse_iterator { };
 

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-07-31 11:13:51 EDT (Sat, 31 Jul 2010)
@@ -0,0 +1,113 @@
+// 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)
+
+#ifndef BOOST_BITFIELD_VECTOR_BASE_HPP
+#define BOOST_BITFIELD_VECTOR_BASE_HPP
+#include <cstddef>
+
+namespace boost { namespace detail {
+
+template <typename T, typename Allocator>
+struct bitfield_vector_base {
+ typedef T value_type;
+ typedef typename Allocator::template rebind<unsigned char>::other
+ rebound_alloc_type;
+ typedef Allocator allocator;
+
+ /** This is the structure which gains the benifit of EBO and holds
+ * pointers to the start and end of the memory allocated as well
+ * as keeps track of the number of bits in use within that allocated
+ * memory.
+ */
+ struct bitfield_vector_impl
+ : rebound_alloc_type
+ {
+ bitfield_vector_impl()
+ :rebound_alloc_type(),
+ _start(0),
+ _end(0),
+ _bits_in_use(0)
+ { }
+
+ bitfield_vector_impl(const rebound_alloc_type& alloc)
+ :rebound_alloc_type(alloc),
+ _start(0),
+ _end(0),
+ _bits_in_use(0)
+ { }
+
+ typename rebound_alloc_type::pointer _start;
+ typename rebound_alloc_type::pointer _end;
+ typename rebound_alloc_type::size_type _bits_in_use;
+ };
+
+ /** This is an instance of the bitfield_vector_impl type. */
+ bitfield_vector_impl _impl;
+
+ /** Allocator retrieval implementation functions. */
+ //@{
+ rebound_alloc_type& get_allocator_impl() {
+ return *static_cast<rebound_alloc_type*>(&this->_impl);
+ }
+
+ rebound_alloc_type const& get_allocator_impl() const {
+ return *static_cast<rebound_alloc_type const*>(&this->_impl);
+ }
+ //@}
+
+ /** Returns a copy of the allocator.*/
+ allocator get_allocator() const {
+ return allocator(get_allocator_impl());
+ }
+
+ /** Default constructor for vector base. */
+ bitfield_vector_base()
+ :_impl()
+ { }
+
+ /** Constructor over an allocator. */
+ bitfield_vector_base(allocator const& alloc)
+ :_impl(alloc)
+ { }
+
+ /** Array Constructor. */
+ bitfield_vector_base(std::size_t n)
+ :_impl()
+ {
+ this->_impl._start = this->allocate_impl(n);
+ this->_impl._end = this->_impl._start + n;
+ }
+
+ /** Array + Allocator Constructor. */
+ bitfield_vector_base(std::size_t n, allocator const& alloc)
+ :_impl(alloc)
+ {
+ this->_impl._start = this->allocate_impl(n);
+ this->_impl._end = this->_impl._start + n;
+ }
+
+ /** Destructor. */
+ ~bitfield_vector_base() {
+ deallocate_impl(this->_impl._start, this->_impl._end
+ - this->_impl._start);
+ }
+
+
+
+ typename rebound_alloc_type::pointer allocate_impl(std::size_t n) {
+ return n != 0 ? _impl.allocate( n ): 0;
+ }
+
+ void
+ deallocate_impl(typename rebound_alloc_type::pointer ptr, std::size_t n) {
+ if(ptr) {
+ _impl.deallocate(ptr,n);
+ }
+ }
+};
+
+}} // end boost::detail
+
+#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-07-31 11:13:51 EDT (Sat, 31 Jul 2010)
@@ -72,5 +72,6 @@
         [ run bft_testing/element_n_test.cpp ]
         [ run bft_testing/get_free_function_test.cpp ]
         [ run bitfield_vector_testing/bitfield_vector_test.cpp ]
+ [ run bitfield_vector_testing/bitfield_vector_base_test.cpp ]
     ;
 

Added: sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_base_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_base_test.cpp 2010-07-31 11:13:51 EDT (Sat, 31 Jul 2010)
@@ -0,0 +1,107 @@
+// 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>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/type_traits/is_convertible.hpp>
+
+using namespace boost;
+
+typedef bits<short,2> T;
+typedef std::allocator<int> alloc;
+typedef std::allocator<unsigned char> rebound_alloc;
+typedef detail::bitfield_vector_base<
+ T,
+ alloc
+> vector_base_type;
+int main() {
+ // Checking typedefs
+ {
+ // checking the rebound_alloc_type.
+ BOOST_TEST((
+ is_same<
+ vector_base_type::rebound_alloc_type,
+ rebound_alloc
+ >::type::value
+ ));
+
+ // checking allocator typedef
+ BOOST_TEST((
+ is_same<
+ vector_base_type::allocator,
+ alloc
+ >::type::value
+ ));
+
+ // checking the value_type type def.
+ BOOST_TEST((
+ is_same<
+ vector_base_type::value_type,
+ T
+ >::type::value
+ ));
+ }
+
+ // testing impl type
+ {
+ typedef vector_base_type::bitfield_vector_impl vect_impl;
+ // making sure the impl type is convertible to the allocator type
+ // this is specific to one of my implementation details.
+ BOOST_TEST((
+ is_convertible<
+ vect_impl,
+ rebound_alloc
+ >::type::value
+ ));
+
+ // testing the default constructor for bitfield_vector_impl.
+ vect_impl temp_default_constructed;
+ BOOST_TEST(temp_default_constructed._start == 0 );
+ BOOST_TEST(temp_default_constructed._end == 0 );
+ BOOST_TEST(temp_default_constructed._bits_in_use == 0 );
+
+ alloc temp_alloc;
+ vect_impl temp_allocator_constructed(temp_alloc);
+
+ BOOST_TEST(temp_allocator_constructed._start == 0 );
+ BOOST_TEST(temp_allocator_constructed._end == 0 );
+ BOOST_TEST(temp_allocator_constructed._bits_in_use == 0 );
+ }
+
+ // testing constructors for bitfield_vector_base
+ {
+ // Default Constructor.
+ vector_base_type default_constructed;
+ BOOST_TEST(default_constructed._impl._start == 0 );
+ BOOST_TEST(default_constructed._impl._end == 0 );
+ BOOST_TEST(default_constructed._impl._bits_in_use == 0 );
+
+ // Allocator Constructor
+ alloc temp_alloc;
+ vector_base_type allocator_constructed(temp_alloc);
+ BOOST_TEST(default_constructed._impl._start == 0 );
+ BOOST_TEST(default_constructed._impl._end == 0 );
+ BOOST_TEST(default_constructed._impl._bits_in_use == 0 );
+
+ // N Constructor
+ vector_base_type n_array_constructed(3);
+ BOOST_TEST(n_array_constructed._impl._start != 0 );
+ BOOST_TEST(n_array_constructed._impl._end != 0 );
+ BOOST_TEST(n_array_constructed._impl._bits_in_use == 0 );
+
+ // N + Allocator Constructor
+ vector_base_type n_plus_allocator_array_constructed(3, temp_alloc);
+ BOOST_TEST(n_plus_allocator_array_constructed._impl._start != 0 );
+ BOOST_TEST(n_plus_allocator_array_constructed._impl._end != 0 );
+ BOOST_TEST(n_plus_allocator_array_constructed._impl._bits_in_use == 0 );
+ }
+ {
+ }
+ 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