Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84092 - in trunk/boost/geometry/index: . detail
From: adam.wulkiewicz_at_[hidden]
Date: 2013-04-30 10:00:51


Author: awulkiew
Date: 2013-04-30 10:00:50 EDT (Tue, 30 Apr 2013)
New Revision: 84092
URL: http://svn.boost.org/trac/boost/changeset/84092

Log:
geometry.index: added rtree's max and min parameters checks.
Text files modified:
   trunk/boost/geometry/index/detail/exception.hpp | 35 ++++++++++++++++++++++++++++++++
   trunk/boost/geometry/index/parameters.hpp | 43 ++++++++++++++++++++++++++-------------
   2 files changed, 63 insertions(+), 15 deletions(-)

Modified: trunk/boost/geometry/index/detail/exception.hpp
==============================================================================
--- trunk/boost/geometry/index/detail/exception.hpp (original)
+++ trunk/boost/geometry/index/detail/exception.hpp 2013-04-30 10:00:50 EDT (Tue, 30 Apr 2013)
@@ -24,6 +24,21 @@
     throw std::runtime_error(str);
 }
 
+inline void throw_logic_error(const char * str)
+{
+ throw std::logic_error(str);
+}
+
+inline void throw_invalid_argument(const char * str)
+{
+ throw std::invalid_argument(str);
+}
+
+inline void throw_length_error(const char * str)
+{
+ throw std::length_error(str);
+}
+
 #else
 
 inline void throw_runtime_error(const char * str)
@@ -32,6 +47,26 @@
     std::abort();
 }
 
+inline void throw_logic_error(const char * str)
+{
+ BOOST_ASSERT_MSG(!"logic_error thrown", str);
+ std::abort();
+}
+
+inline void throw_invalid_argument(const char * str)
+{
+ throw std::invalid_argument(str);
+ BOOST_ASSERT_MSG(!"invalid_argument thrown", str);
+ std::abort();
+}
+
+inline void throw_length_error(const char * str)
+{
+ throw std::length_error(str);
+ BOOST_ASSERT_MSG(!"length_error thrown", str);
+ std::abort();
+}
+
 #endif
 
 }}}} // namespace boost::geometry::index::detail

Modified: trunk/boost/geometry/index/parameters.hpp
==============================================================================
--- trunk/boost/geometry/index/parameters.hpp (original)
+++ trunk/boost/geometry/index/parameters.hpp 2013-04-30 10:00:50 EDT (Tue, 30 Apr 2013)
@@ -15,13 +15,8 @@
 
 namespace boost { namespace geometry { namespace index {
 
-// TODO: awulkiew - add asserts or exceptions?
-// 0 < MIN
-// 2 * MIN <= MAX
-// or rather MIN <= (MAX + 1) / 2 for classic variants
-// assuming that MAX is the number of elements without overflowing ones
-// and something like MIN <= (MAX + OVERFLOWING_NODES) / K for cR-tree
-// this implies 2 <= MAX for classic variants
+//TODO:
+// add default value of Min = 0.3 * Max?
 
 /*!
 \brief Linear r-tree creation algorithm parameters.
@@ -32,6 +27,9 @@
 template <size_t MaxElements, size_t MinElements>
 struct linear
 {
+ BOOST_MPL_ASSERT_MSG((0 < MinElements && 2*MinElements <= MaxElements+1),
+ INVALID_STATIC_MIN_MAX_PARAMETERS, (linear));
+
     static const size_t max_elements = MaxElements;
     static const size_t min_elements = MinElements;
 
@@ -48,6 +46,9 @@
 template <size_t MaxElements, size_t MinElements>
 struct quadratic
 {
+ BOOST_MPL_ASSERT_MSG((0 < MinElements && 2*MinElements <= MaxElements+1),
+ INVALID_STATIC_MIN_MAX_PARAMETERS, (quadratic));
+
     static const size_t max_elements = MaxElements;
     static const size_t min_elements = MinElements;
 
@@ -71,13 +72,13 @@
 \tparam MaxElements Maximum number of elements in nodes.
 \tparam MinElements Minimum number of elements in nodes.
 \tparam ReinsertedElements The number of elements reinserted by forced reinsertions algorithm.
- If 0 forced reinsertions are disabled. Maximum value is Max-Min+1.
- Greater values are truncated.
+ If 0 forced reinsertions are disabled. Maximum value is Max+1-Min.
+ Greater values are truncated. Default: 0.3*Max.
 \tparam OverlapCostThreshold The number of most suitable leafs taken into account while choosing
                                 the leaf node to which currently inserted value will be added. If
                                 value is in range (0, MaxElements) - the algorithm calculates
                                 nearly minimum overlap cost, otherwise all leafs are analyzed
- and true minimum overlap cost is calculated.
+ and true minimum overlap cost is calculated. Default: 32.
 */
 template <size_t MaxElements,
           size_t MinElements,
@@ -85,6 +86,9 @@
           size_t OverlapCostThreshold = 32>
 struct rstar
 {
+ BOOST_MPL_ASSERT_MSG((0 < MinElements && 2*MinElements <= MaxElements+1),
+ INVALID_STATIC_MIN_MAX_PARAMETERS, (rstar));
+
     static const size_t max_elements = MaxElements;
     static const size_t min_elements = MinElements;
     static const size_t reinserted_elements = ReinsertedElements;
@@ -118,7 +122,10 @@
     dynamic_linear(size_t max_elements, size_t min_elements)
         : m_max_elements(max_elements)
         , m_min_elements(min_elements)
- {}
+ {
+ if (!(0 < m_min_elements && 2*m_min_elements <= m_max_elements+1))
+ detail::throw_invalid_argument("invalid min or/and max parameters of dynamic_linear");
+ }
 
     size_t get_max_elements() const { return m_max_elements; }
     size_t get_min_elements() const { return m_min_elements; }
@@ -143,7 +150,10 @@
     dynamic_quadratic(size_t max_elements, size_t min_elements)
         : m_max_elements(max_elements)
         , m_min_elements(min_elements)
- {}
+ {
+ if (!(0 < m_min_elements && 2*m_min_elements <= m_max_elements+1))
+ detail::throw_invalid_argument("invalid min or/and max parameters of dynamic_quadratic");
+ }
 
     size_t get_max_elements() const { return m_max_elements; }
     size_t get_min_elements() const { return m_min_elements; }
@@ -175,12 +185,12 @@
     \param min_elements Minimum number of elements in nodes.
     \param reinserted_elements The number of elements reinserted by forced reinsertions algorithm.
                                     If 0 forced reinsertions are disabled. Maximum value is Max-Min+1.
- Greater values are truncated.
+ Greater values are truncated. Default: 0.3*Max.
     \param overlap_cost_threshold The number of most suitable leafs taken into account while choosing
                                     the leaf node to which currently inserted value will be added. If
                                     value is in range (0, MaxElements) - the algorithm calculates
                                     nearly minimum overlap cost, otherwise all leafs are analyzed
- and true minimum overlap cost is calculated.
+ and true minimum overlap cost is calculated. Default: 32.
     */
     dynamic_rstar(size_t max_elements,
                   size_t min_elements,
@@ -193,7 +203,10 @@
             (max_elements * 3) / 10 :
             reinserted_elements )
         , m_overlap_cost_threshold(overlap_cost_threshold)
- {}
+ {
+ if (!(0 < m_min_elements && 2*m_min_elements <= m_max_elements+1))
+ detail::throw_invalid_argument("invalid min or/and max parameters of dynamic_rstar");
+ }
 
     size_t get_max_elements() const { return m_max_elements; }
     size_t get_min_elements() const { return m_min_elements; }


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