Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81897 - sandbox-branches/geometry/index/test/rtree
From: adam.wulkiewicz_at_[hidden]
Date: 2012-12-13 08:48:51


Author: awulkiew
Date: 2012-12-13 08:48:51 EST (Thu, 13 Dec 2012)
New Revision: 81897
URL: http://svn.boost.org/trac/boost/changeset/81897

Log:
added throwing static vector to exceptions test
Text files modified:
   sandbox-branches/geometry/index/test/rtree/test_rtree_exceptions.hpp | 6 ++--
   sandbox-branches/geometry/index/test/rtree/test_throwing.hpp | 54 ++++++++++++++++++++++++++++++++++++++++
   2 files changed, 57 insertions(+), 3 deletions(-)

Modified: sandbox-branches/geometry/index/test/rtree/test_rtree_exceptions.hpp
==============================================================================
--- sandbox-branches/geometry/index/test/rtree/test_rtree_exceptions.hpp (original)
+++ sandbox-branches/geometry/index/test/rtree/test_rtree_exceptions.hpp 2012-12-13 08:48:51 EST (Thu, 13 Dec 2012)
@@ -75,7 +75,7 @@
 struct dynamic_internal_node<Value, Parameters, Box, Allocators, node_throwing_d_mem_static_tag>
     : public dynamic_node<Value, Parameters, Box, Allocators, node_throwing_d_mem_static_tag>
 {
- typedef throwing_pushable_array<
+ typedef throwing_static_vector<
         std::pair<
             Box,
             dynamic_node<Value, Parameters, Box, Allocators, node_throwing_d_mem_static_tag> *
@@ -96,7 +96,7 @@
 struct dynamic_leaf<Value, Parameters, Box, Allocators, node_throwing_d_mem_static_tag>
     : public dynamic_node<Value, Parameters, Box, Allocators, node_throwing_d_mem_static_tag>
 {
- typedef throwing_pushable_array<Value, Parameters::max_elements + 1> elements_type;
+ typedef throwing_static_vector<Value, Parameters::max_elements + 1> elements_type;
 
     template <typename Dummy>
     inline dynamic_leaf(Dummy) {}
@@ -111,7 +111,7 @@
 template <typename OldValue, size_t N, typename NewValue>
 struct container_from_elements_type<throwing_pushable_array<OldValue, N>, NewValue>
 {
- typedef throwing_pushable_array<NewValue, N> type;
+ typedef throwing_static_vector<NewValue, N> type;
 };
 
 // nodes traits

Modified: sandbox-branches/geometry/index/test/rtree/test_throwing.hpp
==============================================================================
--- sandbox-branches/geometry/index/test/rtree/test_throwing.hpp (original)
+++ sandbox-branches/geometry/index/test/rtree/test_throwing.hpp 2012-12-13 08:48:51 EST (Thu, 13 Dec 2012)
@@ -319,4 +319,58 @@
     size_type m_size;
 };
 
+#include <boost/geometry/extensions/index/static_vector.hpp>
+
+struct throwing_static_vector_exception : public std::exception
+{
+ const char * what() const throw() { return "static vector exception."; }
+};
+
+struct throwing_static_vector_settings
+{
+ static void throw_if_required()
+ {
+ // throw if counter meets max count
+ if ( get_max_calls_ref() <= get_calls_counter_ref() )
+ throw throwing_pushable_array_exception();
+ else
+ ++get_calls_counter_ref();
+ }
+
+ static void reset_calls_counter() { get_calls_counter_ref() = 0; }
+ static void set_max_calls(size_t mc) { get_max_calls_ref() = mc; }
+
+ static size_t & get_calls_counter_ref() { static size_t cc = 0; return cc; }
+ static size_t & get_max_calls_ref() { static size_t mc = (std::numeric_limits<size_t>::max)(); return mc; }
+};
+
+template <typename Element, size_t Capacity>
+class throwing_static_vector
+ : public boost::geometry::index::static_vector<Element, Capacity>
+{
+ typedef boost::geometry::index::static_vector<Element, Capacity> container;
+
+public:
+ typedef typename container::value_type value_type;
+ typedef typename container::size_type size_type;
+ typedef typename container::iterator iterator;
+ typedef typename container::const_iterator const_iterator;
+ typedef typename container::reverse_iterator reverse_iterator;
+ typedef typename container::const_reverse_iterator const_reverse_iterator;
+ typedef typename container::reference reference;
+ typedef typename container::const_reference const_reference;
+
+ inline void resize(size_type s)
+ {
+ throwing_pushable_array_settings::throw_if_required();
+ container::resize(s);
+ }
+
+ void push_back(Element const& v)
+ {
+ throwing_pushable_array_settings::throw_if_required();
+ container::push_back(v);
+ }
+};
+
 #endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_TEST_THROWING_HPP


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