Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81885 - in sandbox-branches/geometry/index: boost/geometry/extensions/index boost/geometry/extensions/index/rtree/node boost/geometry/extensions/index/rtree/visitors test/rtree tests
From: adam.wulkiewicz_at_[hidden]
Date: 2012-12-12 22:34:55


Author: awulkiew
Date: 2012-12-12 22:34:54 EST (Wed, 12 Dec 2012)
New Revision: 81885
URL: http://svn.boost.org/trac/boost/changeset/81885

Log:
static_vector implemented and used in the rtree instead of pushable_array
Added:
   sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp (contents, props changed)
Text files modified:
   sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_d_mem_static.hpp | 10 +-
   sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_s_mem_static.hpp | 6
   sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/visitors/insert.hpp | 2
   sandbox-branches/geometry/index/test/rtree/rtree_exceptions.cpp | 2
   sandbox-branches/geometry/index/tests/static_vector.cpp | 159 +--------------------------------------
   5 files changed, 14 insertions(+), 165 deletions(-)

Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_d_mem_static.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_d_mem_static.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_d_mem_static.hpp 2012-12-12 22:34:54 EST (Wed, 12 Dec 2012)
@@ -12,7 +12,7 @@
 #define BOOST_GEOMETRY_EXTENSIONS_INDEX_RTREE_NODE_NODE_DEFAULT_STATIC_HPP
 
 #include <boost/geometry/extensions/index/rtree/node/dynamic_visitor.hpp>
-#include <boost/geometry/extensions/index/pushable_array.hpp>
+#include <boost/geometry/extensions/index/static_vector.hpp>
 
 namespace boost { namespace geometry { namespace index {
 
@@ -22,7 +22,7 @@
 struct dynamic_internal_node<Value, Parameters, Box, Allocators, node_d_mem_static_tag>
     : public dynamic_node<Value, Parameters, Box, Allocators, node_d_mem_static_tag>
 {
- typedef index::pushable_array<
+ typedef index::static_vector<
         std::pair<
             Box,
             dynamic_node<Value, Parameters, Box, Allocators, node_d_mem_static_tag> *
@@ -43,7 +43,7 @@
 struct dynamic_leaf<Value, Parameters, Box, Allocators, node_d_mem_static_tag>
     : public dynamic_node<Value, Parameters, Box, Allocators, node_d_mem_static_tag>
 {
- typedef index::pushable_array<Value, Parameters::max_elements + 1> elements_type;
+ typedef index::static_vector<Value, Parameters::max_elements + 1> elements_type;
 
     template <typename Dummy>
     inline dynamic_leaf(Dummy) {}
@@ -82,9 +82,9 @@
 
 // elements derived type
 template <typename OldValue, size_t N, typename NewValue>
-struct container_from_elements_type<index::pushable_array<OldValue, N>, NewValue>
+struct container_from_elements_type<index::static_vector<OldValue, N>, NewValue>
 {
- typedef index::pushable_array<NewValue, N> type;
+ typedef index::static_vector<NewValue, N> type;
 };
 
 // allocators

Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_s_mem_static.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_s_mem_static.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_s_mem_static.hpp 2012-12-12 22:34:54 EST (Wed, 12 Dec 2012)
@@ -11,7 +11,7 @@
 #ifndef BOOST_GEOMETRY_EXTENSIONS_INDEX_RTREE_NODE_NODE_DEFAULT_STATIC_VARIANT_HPP
 #define BOOST_GEOMETRY_EXTENSIONS_INDEX_RTREE_NODE_NODE_DEFAULT_STATIC_VARIANT_HPP
 
-#include <boost/geometry/extensions/index/pushable_array.hpp>
+#include <boost/geometry/extensions/index/static_vector.hpp>
 
 #include <boost/geometry/extensions/index/rtree/node/static_visitor.hpp>
 
@@ -24,7 +24,7 @@
 template <typename Value, typename Parameters, typename Box, typename Allocators>
 struct static_internal_node<Value, Parameters, Box, Allocators, node_s_mem_static_tag>
 {
- typedef index::pushable_array<
+ typedef index::static_vector<
         std::pair<
             Box,
             typename node<Value, Parameters, Box, Allocators, node_s_mem_static_tag>::type *
@@ -41,7 +41,7 @@
 template <typename Value, typename Parameters, typename Box, typename Allocators>
 struct static_leaf<Value, Parameters, Box, Allocators, node_s_mem_static_tag>
 {
- typedef index::pushable_array<Value, Parameters::max_elements + 1> elements_type;
+ typedef index::static_vector<Value, Parameters::max_elements + 1> elements_type;
 
     template <typename Dummy>
     inline static_leaf(Dummy) {}

Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/visitors/insert.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/visitors/insert.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/visitors/insert.hpp 2012-12-12 22:34:54 EST (Wed, 12 Dec 2012)
@@ -122,7 +122,7 @@
     typedef rtree::node_auto_ptr<Value, Options, Translator, Box, Allocators> node_auto_ptr;
 
 public:
- typedef index::pushable_array<std::pair<Box, node*>, 1> nodes_container_type;
+ typedef index::static_vector<std::pair<Box, node*>, 1> nodes_container_type;
 
     template <typename Node>
     static inline void apply(nodes_container_type & additional_nodes,

Added: sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp
==============================================================================
--- (empty file)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp 2012-12-12 22:34:54 EST (Wed, 12 Dec 2012)
@@ -0,0 +1,236 @@
+// Boost.Geometry Index
+//
+// Copyright (c) 2011-2012 Adam Wulkiewicz, Lodz, Poland.
+//
+// Use, modification and distribution is subject to 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/aligned_storage.hpp>
+#include <boost/assert.hpp>
+#include <boost/iterator/reverse_iterator.hpp>
+
+#ifndef BOOST_GEOMETRY_EXTENSIONS_INDEX_STATIC_VECTOR_HPP
+#define BOOST_GEOMETRY_EXTENSIONS_INDEX_STATIC_VECTOR_HPP
+
+namespace boost { namespace geometry { namespace index {
+
+template <typename Value, size_t Capacity>
+class static_vector
+{
+public:
+ typedef Value value_type;
+ typedef size_t size_type;
+ typedef Value& reference;
+ typedef Value const& const_reference;
+ typedef Value* iterator;
+ typedef const Value * const_iterator;
+ typedef boost::reverse_iterator<iterator> reverse_iterator;
+ typedef boost::reverse_iterator<const_iterator> const_reverse_iterator;
+
+ // nothrow
+ static_vector()
+ : m_size(0)
+ {}
+
+ // strong
+ static_vector(size_type s)
+ : m_size(0)
+ {
+ resize(s); // may throw
+ }
+
+ // strong
+ static_vector(static_vector const& other)
+ : m_size(0)
+ {
+ //BOOST_ASSERT_MSG(other.m_size <= Capacity, "capacity too small");
+
+ try
+ {
+ for ( ; m_size < other.m_size ; ++m_size )
+ this->construct(m_size, other[m_size]); // may throw
+ }
+ catch(...)
+ {
+ this->destroy(0, m_size);
+ throw; // rethrow
+ }
+ }
+
+ // basic
+ static_vector & operator=(static_vector const& other)
+ {
+ //BOOST_ASSERT_MSG(other.m_size <= Capacity, "capacity too small");
+
+ size_t min_size = m_size < other.m_size ? m_size : other.m_size;
+
+ for ( size_t i = 0 ; i < min_size ; ++i )
+ (*this)[i] = other[i]; // may throw
+
+ for ( ; m_size < other.m_size ; ++m_size )
+ this->construct(m_size, other[m_size]); // may throw
+
+ for ( size_t i = other.m_size ; i < m_size ; ++i )
+ this->destroy(i);
+
+ return *this;
+ }
+
+ // nothrow
+ ~static_vector()
+ {
+ this->destroy(0, m_size);
+ }
+
+ // nothrow if s <= size(), strong otherwise
+ void resize(size_type s)
+ {
+ if ( s < m_size )
+ {
+ this->destroy(s, m_size);
+ m_size = s;
+ }
+ else
+ {
+ size_type i = m_size;
+ try
+ {
+ for ( ; i < s ; ++i )
+ this->construct(i); // may throw
+ m_size = s;
+ }
+ catch(...)
+ {
+ this->destroy(m_size, i);
+ throw; // rethrow
+ }
+ }
+ }
+
+ // nothrow
+ void reserve(size_type s)
+ {
+ BOOST_ASSERT_MSG(s <= Capacity, "max capacity reached");
+ }
+
+ // strong
+ void push_back(Value const& value)
+ {
+ BOOST_ASSERT_MSG(m_size < Capacity, "max capacity reached");
+ this->construct(m_size, value); // may throw
+ ++m_size;
+ }
+
+ // nothrow
+ void pop_back()
+ {
+ BOOST_ASSERT_MSG(0 < m_size, "the container is empty");
+ --m_size;
+ this->destroy(m_size);
+ }
+
+ // nothrow
+ void clear()
+ {
+ this->destroy(0, m_size);
+ m_size = 0;
+ }
+
+ // nothrow
+ Value & operator[](size_t i)
+ {
+ BOOST_ASSERT_MSG(i < Capacity, "index out of bounds");
+ return *(this->ptr(i));
+ }
+
+ // nothrow
+ Value const& operator[](size_t i) const
+ {
+ BOOST_ASSERT_MSG(i < Capacity, "index out of bounds");
+ return *(this->ptr(i));
+ }
+
+ // nothrow
+ Value & front()
+ {
+ BOOST_ASSERT_MSG(0 < m_size, "the container is empty");
+ return *(this->ptr(0));
+ }
+
+ // nothrow
+ Value const& front() const
+ {
+ BOOST_ASSERT_MSG(0 < m_size, "the container is empty");
+ return *(this->ptr(0));
+ }
+
+ // nothrow
+ Value & back()
+ {
+ BOOST_ASSERT_MSG(0 < m_size, "the container is empty");
+ return *(this->ptr(m_size - 1));
+ }
+
+ // nothrow
+ Value const& back() const
+ {
+ BOOST_ASSERT_MSG(0 < m_size, "the container is empty");
+ return *(this->ptr(m_size - 1));
+ }
+
+ // nothrow
+ iterator begin() { return this->ptr(0); }
+ const_iterator begin() const { return this->ptr(0); }
+ iterator end() { return this->ptr(m_size); }
+ const_iterator end() const { return this->ptr(m_size); }
+ // nothrow
+ reverse_iterator rbegin() { return reverse_iterator(this->end()); }
+ const_reverse_iterator rbegin() const { return reverse_iterator(this->end()); }
+ reverse_iterator rend() { return reverse_iterator(this->begin()); }
+ const_reverse_iterator rend() const { return reverse_iterator(this->begin()); }
+
+ // nothrow
+ size_type capacity() const { return Capacity; }
+ size_type size() const { return m_size; }
+ bool empty() const { return 0 == m_size; }
+
+private:
+ void construct(size_type i)
+ {
+ new (this->ptr(i)) value_type(); // may throw
+ }
+
+ void construct(size_type i, Value const& value)
+ {
+ new (this->ptr(i)) value_type(value); // may throw
+ }
+
+ void destroy(size_type i)
+ {
+ this->ptr(i)->~value_type();
+ }
+
+ void destroy(size_type first_i, size_type last_i)
+ {
+ for ( size_type i = first_i ; i < last_i ; ++i )
+ this->destroy(i);
+ }
+
+ Value * ptr(size_type i)
+ {
+ return (reinterpret_cast<Value*>(m_storage.address()) + i);
+ }
+
+ const Value * ptr(size_type i) const
+ {
+ return (reinterpret_cast<const Value*>(m_storage.address()) + i);
+ }
+
+ boost::aligned_storage<sizeof(Value[Capacity])> m_storage;
+ size_type m_size;
+};
+
+}}} // namespace boost::geometry::index
+
+#endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_STATIC_VECTOR_HPP

Modified: sandbox-branches/geometry/index/test/rtree/rtree_exceptions.cpp
==============================================================================
--- sandbox-branches/geometry/index/test/rtree/rtree_exceptions.cpp (original)
+++ sandbox-branches/geometry/index/test/rtree/rtree_exceptions.cpp 2012-12-12 22:34:54 EST (Wed, 12 Dec 2012)
@@ -27,7 +27,7 @@
     B qbox;
     generate_input<2>::apply(input, qbox);
 
- for ( size_t i = 0 ; i < 100 ; i += 5 )
+ for ( size_t i = 0 ; i < 50 ; i += 2 )
     {
         throwing_value::reset_calls_counter();
         throwing_value::set_max_calls(10000);

Modified: sandbox-branches/geometry/index/tests/static_vector.cpp
==============================================================================
--- sandbox-branches/geometry/index/tests/static_vector.cpp (original)
+++ sandbox-branches/geometry/index/tests/static_vector.cpp 2012-12-12 22:34:54 EST (Wed, 12 Dec 2012)
@@ -7,160 +7,7 @@
 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
-#include <boost/aligned_storage.hpp>
-#include <boost/assert.hpp>
-
-template <typename Value, size_t Capacity>
-class static_vector
-{
-public:
- typedef Value value_type;
- typedef size_t size_type;
- typedef Value& reference;
- typedef Value const& const_reference;
- typedef Value* iterator;
- typedef const Value * const_iterator;
-
- static_vector()
- : m_size(0)
- {}
-
- static_vector(size_type s)
- {
- try
- {
- resize(s); // may throw
- }
- catch(...)
- {
- this->destroy(0, m_size);
- }
- }
-
- ~static_vector()
- {
- this->destroy(0, m_size);
- }
-
- void resize(size_type s)
- {
- if ( s < m_size )
- {
- this->destroy(s, m_size);
- m_size = s;
- }
- else
- {
- for ( size_type i = m_size ; i < s ; ++i )
- {
- this->construct(i); // may throw
- ++m_size;
- }
- }
- }
-
- void push_back(Value const& value)
- {
- BOOST_ASSERT_MSG(m_size < Capacity, "max capacity reached");
- this->construct(m_size, value); // may throw
- ++m_size;
- }
-
- void pop_back()
- {
- BOOST_ASSERT_MSG(0 < m_size, "the container is empty");
- --m_size;
- this->destroy(m_size);
- }
-
- Value & operator[](size_t i)
- {
- BOOST_ASSERT_MSG(i < Capacity, "index out of bounds");
- return *(this->ptr(i));
- }
-
- Value const& operator[](size_t i) const
- {
- BOOST_ASSERT_MSG(i < Capacity, "index out of bounds");
- return *(this->ptr(i));
- }
-
- Value & front()
- {
- BOOST_ASSERT_MSG(0 < m_size, "the container is empty");
- return *(this->ptr(0));
- }
-
- Value const& front() const
- {
- BOOST_ASSERT_MSG(0 < m_size, "the container is empty");
- return *(this->ptr(0));
- }
-
- Value & back()
- {
- BOOST_ASSERT_MSG(0 < m_size, "the container is empty");
- return *(this->ptr(m_size - 1));
- }
-
- Value const& back() const
- {
- BOOST_ASSERT_MSG(0 < m_size, "the container is empty");
- return *(this->ptr(m_size - 1));
- }
-
- size_type capacity() const
- {
- return Capacity;
- }
-
- size_type size() const
- {
- return m_size;
- }
-
- bool empty() const
- {
- return 0 == m_size;
- }
-
-private:
- Value * ptr(size_type i)
- {
- return (reinterpret_cast<Value*>(m_storage.address()) + i);
- }
-
- const Value * ptr(size_type i) const
- {
- return (reinterpret_cast<const Value*>(m_storage.address()) + i);
- }
-
- void construct(size_type i)
- {
- new (ptr(i)) value_type(); // may throw
- }
-
- void construct(size_type i, Value const& value)
- {
- new (ptr(i)) value_type(value); // may throw
- }
-
- void destroy(size_type i)
- {
- ptr(i)->~value_type();
- }
-
- void destroy(size_type first_i, size_type last_i)
- {
- for ( size_type i = first_i ; i < last_i ; ++i )
- this->destroy(i);
- }
-
- boost::aligned_storage<sizeof(Value) * Capacity> m_storage;
- size_type m_size;
-};
-
-// ------------------------------- TEST ----------------------------------
+#include <boost/geometry/extensions/index/static_vector.hpp>
 
 #include <iostream>
 
@@ -176,7 +23,9 @@
 
 int main()
 {
- static_vector<A, 4> sv;
+ namespace bgi = boost::geometry::index;
+
+ bgi::static_vector<A, 4> sv;
     std::cout << "resize(2)" << std::endl;
     sv.resize(2); // 0 0
     std::cout << "push_back(A(22))" << std::endl;


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