$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r67491 - in sandbox/SOC/2010/bit_masks: boost/integer lib/integer/test/bitfield_vector_testing
From: bbartmanboost_at_[hidden]
Date: 2010-12-29 11:24:09
Author: bbartman
Date: 2010-12-29 11:24:08 EST (Wed, 29 Dec 2010)
New Revision: 67491
URL: http://svn.boost.org/trac/boost/changeset/67491
Log:
working on implementing additional functionality for the bitfield_vector
Text files modified: 
   sandbox/SOC/2010/bit_masks/boost/integer/bitfield_vector.hpp                                 |    46 ++++++++++----                          
   sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_test.cpp |   126 +++++++++++++++++++++++++++++++++++++++ 
   2 files changed, 156 insertions(+), 16 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-12-29 11:24:08 EST (Wed, 29 Dec 2010)
@@ -721,34 +721,54 @@
 
 
     /** Resize to a size given in elements. */
-    void resize(size_type sz, value_type c = value_type() ) {
+    void resize(size_type sz, value_type val = value_type() ) {
+        if(sz == size()) return;
         size_type next_size_in_bits = Width * sz;
         
         // fewer elements than needed.
-        if(next_size_in_bits <= this->m_impl.m_bits_in_use ) {
+        if(next_size_in_bits < this->m_impl.m_bits_in_use ) {
             this->m_impl.m_bits_in_use = next_size_in_bits;
             return;
         }
 
-        // not enough space
-        if(next_size_in_bits > ((this->m_impl.m_end - this->m_impl.m_start) * Width)) {
-            // while(
+        // adding elements to the end of the bitfield_vector.
+        while(this->m_impl.m_bits_in_use < next_size_in_bits ) {
+            push_back(val);
         }
-        
     }
-    reference operator[](size_type n);    
-    const_reference operator[](size_type n) const;
-    reference at(size_type n);
-    const_reference at(size_type n) const;
+
+    /** Operator []. */ 
+    reference operator[](size_type n) {
+        return reference( *(begin() + n));
+    }
+
+    /** const operator[] */
+    const_reference operator[](size_type n) const {
+        return const_reference( *(begin() + n));
+    }
+
+    /** at throwing indexing. */
+    reference at(size_type n) {
+        if(n > size() ) {
+            throw std::out_of_range("Out of Range: invalid value for n.");
+        }
+        return (*this)[n];
+    }
+
+    /**  const at throwing indexing. */
+    const_reference at(size_type n) const {
+        if(n > size() ) {
+            throw std::out_of_range();
+        }
+        return (*this)[n];
+    }
 
 
     template <class InputIterator>
     void assign(InputIterator first, InputIterator last);
     void assign(size_type n, value_type const& u);
 
-    /**
-     *
-     */
+    /** Add an element to the end of the vector. */
     void push_back(value_type const& x) {
         check_for_resizing();
         iterator iter = end();
Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_test.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_test.cpp	(original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_test.cpp	2010-12-29 11:24:08 EST (Wed, 29 Dec 2010)
@@ -22,6 +22,7 @@
 struct test_for_bfv
     :Bfv
 {
+    typedef test_for_bfv<T,Width,Alloc,Bfv> self;
     typedef Bfv _base;
 
     /** Tests to make sure that I got all of the typedefs from within
@@ -281,16 +282,113 @@
         BOOST_TEST( this->m_impl.m_bits_in_use == 0);
     }
     
+
+
     // resize
     void test_resize() {
-        // BOOST_TEST( )
-        // test case size > the the resizing value.
+        typedef typename _base::iterator iterator;
+        this->clear();
+        for(std::size_t i=0; i < 3u; ++i) this->push_back(5);
+
+        // test case size < the the resizing value.
+        BOOST_TEST( this->size() == 3u);
+
+        this->resize(2);
+        BOOST_TEST( this->size() == 2u);
+        for(iterator i = this->begin() ;i != this->end(); ++i) {
+            BOOST_TEST( *i == 5);
+        }
+
+        // resize with the same value in the vector.
+        this->resize(2);
+        BOOST_TEST( this->size() == 2u);
+        for(iterator i = this->begin() ;i != this->end(); ++i) {
+            BOOST_TEST( *i == 5);
+        }
+
+        // resize to > than size
+        this->clear();
+        for(std::size_t i=0; i < 3u; ++i) this->push_back(4);
+        this->resize(10,6);
+        BOOST_TEST( this->size() == 10u);
+        iterator iter = this->begin();
+        iterator ending = iter + 3;
+        for(;iter != ending;++iter) {
+            BOOST_TEST(*iter == 4u);
+        }
+        
+        ending = this->end();
+        for(;iter != ending;++iter) {
+            BOOST_TEST(*iter == 6);
+        }
     }
     
     // push_back
     void test_push_back(T val) {
         BOOST_TEST(this->back() == val);
     }
+    
+    // operator[]
+    void test_square_bracket_operator() {
+        this->clear();
+        for(std::size_t i=0; i < 3u; ++i) this->push_back(4u);
+        // this->operator[](0);
+        for(std::size_t i = 0; i<3u; ++i){
+            BOOST_TEST( ((*this)[i]) == 4u);
+        }
+        for(std::size_t i = 0; i<3u; ++i){
+            ((*this)[i]) = 5u;
+        }
+        for(std::size_t i = 0; i<3u; ++i){
+            BOOST_TEST( ((*this)[i]) == 5u);
+        }
+    }
+
+    // const operator[]
+    void test_const_square_bracket_operator() {
+        this->clear();
+        for(std::size_t i=0; i < 3u; ++i) this->push_back(4u);
+        // this->operator[](0);
+        for(std::size_t i = 0; i<3u; ++i){
+            BOOST_TEST( (const_cast<self const&>(*this)[i]) == 4u);
+        }
+    }
+
+    // at test
+    void test_at() {
+        this->clear();
+        for(std::size_t i=0; i < 3u; ++i) this->push_back(i);
+        for(std::size_t i=0; i < 3u; ++i) {
+            BOOST_TEST( this->at(i) == i);
+        }
+
+        try{
+            this->at(100);
+        }catch(std::out_of_range const&) {
+            return;
+        }catch(...) {
+            BOOST_TEST(!"Didn't catch correct exception from at.");
+        }
+        BOOST_TEST(!"Didn't catch Exception from at.");
+    }
+    
+    // const at
+    void test_const_at() {
+        this->clear();
+        for(std::size_t i=0; i < 3u; ++i) this->push_back(i);
+        for(std::size_t i=0; i < 3u; ++i) {
+            BOOST_TEST( const_cast<self const&>(*this)->at(i) == i);
+        }
+
+        try{
+            const_cast<self const&>(*this)->at(100);
+        }catch(std::out_of_range const&) {
+            return;
+        }catch(...) {
+            BOOST_TEST(!"Didn't catch correct exception from at.");
+        }
+        BOOST_TEST(!"Didn't catch Exception from at.");
+    }
 };
 
 
@@ -423,7 +521,7 @@
     
     // resize test
     {
-        Tester t1(8,2);
+        Tester t1;
         t1.test_resize();
     }
 
@@ -433,6 +531,28 @@
         t1.push_back(3);
         t1.test_push_back(3);
     }
+
+    // operator[]
+    {
+        Tester t1;
+        t1.test_square_bracket_operator();
+    }
+
+    // const operator[]
+    {
+        Tester t1;
+        t1.test_const_square_bracket_operator();
+    }
+
+    // at test
+    {
+        Tester t1;
+        t1.test_at();
+    }
+
+    // const at test
+    {
+    }
 }
 
 int main() {