|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r66918 - in trunk/boost/spirit/home/support/utree: . detail
From: hartmut.kaiser_at_[hidden]
Date: 2010-11-30 15:35:36
Author: hkaiser
Date: 2010-11-30 15:35:36 EST (Tue, 30 Nov 2010)
New Revision: 66918
URL: http://svn.boost.org/trac/boost/changeset/66918
Log:
Spirit: changing utree asserts into exceptions
Text files modified:
trunk/boost/spirit/home/support/utree/detail/utree_detail2.hpp | 57 ++++++++++++++++++++++++++++-----------
trunk/boost/spirit/home/support/utree/operators.hpp | 5 +--
trunk/boost/spirit/home/support/utree/utree.hpp | 16 +++++++++++
3 files changed, 59 insertions(+), 19 deletions(-)
Modified: trunk/boost/spirit/home/support/utree/detail/utree_detail2.hpp
==============================================================================
--- trunk/boost/spirit/home/support/utree/detail/utree_detail2.hpp (original)
+++ trunk/boost/spirit/home/support/utree/detail/utree_detail2.hpp 2010-11-30 15:35:36 EST (Tue, 30 Nov 2010)
@@ -16,6 +16,7 @@
#include <boost/type_traits/remove_pointer.hpp>
#include <boost/type_traits/is_pointer.hpp>
#include <boost/utility/enable_if.hpp>
+#include <boost/throw_exception.hpp>
namespace boost { namespace spirit { namespace detail
{
@@ -887,7 +888,9 @@
return detail::index_impl::apply(r.first, i);
// otherwise...
- BOOST_ASSERT(get_type() == type::list_type && size() > i);
+ if (get_type() != type::list_type || size() <= i)
+ boost::throw_exception(bad_type_exception());
+
return detail::index_impl::apply(l.first, i);
}
@@ -899,7 +902,9 @@
return detail::index_impl::apply(r.first, i);
// otherwise...
- BOOST_ASSERT(get_type() == type::list_type && size() > i);
+ if (get_type() != type::list_type || size() <= i)
+ boost::throw_exception(bad_type_exception());
+
return detail::index_impl::apply(l.first, i);
}
@@ -985,7 +990,8 @@
{
if (get_type() == type::reference_type)
return p->pop_front();
- BOOST_ASSERT(get_type() == type::list_type);
+ if (get_type() != type::list_type)
+ boost::throw_exception(bad_type_exception());
l.pop_front();
}
@@ -993,7 +999,8 @@
{
if (get_type() == type::reference_type)
return p->pop_back();
- BOOST_ASSERT(get_type() == type::list_type);
+ if (get_type() != type::list_type)
+ boost::throw_exception(bad_type_exception());
l.pop_back();
}
@@ -1001,7 +1008,8 @@
{
if (get_type() == type::reference_type)
return p->erase(pos);
- BOOST_ASSERT(get_type() == type::list_type);
+ if (get_type() != type::list_type)
+ boost::throw_exception(bad_type_exception());
detail::list::node* np = l.erase(pos.node);
return iterator(np, np?np->prev:l.last);
}
@@ -1071,7 +1079,9 @@
return const_iterator(r.first, 0);
// otherwise...
- BOOST_ASSERT(get_type() == type::list_type);
+ if (get_type() != type::list_type)
+ boost::throw_exception(bad_type_exception());
+
return const_iterator(l.first, 0);
}
@@ -1083,7 +1093,9 @@
return const_iterator(0, r.first);
// otherwise...
- BOOST_ASSERT(get_type() == type::list_type);
+ if (get_type() != type::list_type)
+ boost::throw_exception(bad_type_exception());
+
return const_iterator(0, l.last);
}
@@ -1119,7 +1131,10 @@
{
return l.size;
}
- BOOST_ASSERT(get_type() == type::nil_type);
+
+ if (get_type() != type::nil_type)
+ boost::throw_exception(bad_type_exception());
+
return 0;
}
@@ -1141,7 +1156,9 @@
}
// otherwise...
- BOOST_ASSERT(get_type() == type::list_type && l.first != 0);
+ if (get_type() != type::list_type || l.first == 0)
+ boost::throw_exception(bad_type_exception());
+
return l.first->val;
}
@@ -1158,7 +1175,9 @@
}
// otherwise...
- BOOST_ASSERT(get_type() == type::list_type && l.last != 0);
+ if (get_type() != type::list_type || l.last == 0)
+ boost::throw_exception(bad_type_exception());
+
return l.last->val;
}
@@ -1175,7 +1194,9 @@
}
// otherwise...
- BOOST_ASSERT(get_type() == type::list_type && l.first != 0);
+ if (get_type() != type::list_type || l.first == 0)
+ boost::throw_exception(bad_type_exception());
+
return l.first->val;
}
@@ -1192,7 +1213,9 @@
}
// otherwise...
- BOOST_ASSERT(get_type() == type::list_type && l.last != 0);
+ if (get_type() != type::list_type || l.last == 0)
+ boost::throw_exception(bad_type_exception());
+
return l.last->val;
}
@@ -1220,9 +1243,9 @@
set_type(type::list_type);
l.default_construct();
}
- else
+ else if (get_type() != type::list_type)
{
- BOOST_ASSERT(get_type() == type::list_type);
+ boost::throw_exception(bad_type_exception());
}
}
@@ -1368,7 +1391,8 @@
inline short utree::tag() const
{
- BOOST_ASSERT(get_type() == type::list_type);
+ if (get_type() != type::list_type)
+ boost::throw_exception(bad_type_exception());
return s.tag();
}
@@ -1380,7 +1404,8 @@
inline utree utree::eval(scope const& env) const
{
- BOOST_ASSERT(get_type() == type::function_type);
+ if (get_type() != type::function_type)
+ boost::throw_exception(bad_type_exception());
return (*pf)(env);
}
}}
Modified: trunk/boost/spirit/home/support/utree/operators.hpp
==============================================================================
--- trunk/boost/spirit/home/support/utree/operators.hpp (original)
+++ trunk/boost/spirit/home/support/utree/operators.hpp 2010-11-30 15:35:36 EST (Tue, 30 Nov 2010)
@@ -17,13 +17,12 @@
#include <exception>
#include <boost/spirit/home/support/utree/utree.hpp>
#include <boost/preprocessor/cat.hpp>
+#include <boost/throw_exception.hpp>
#include <boost/type_traits/is_arithmetic.hpp>
#include <boost/type_traits/is_integral.hpp>
namespace boost { namespace spirit
{
- struct utree_exception : std::exception {};
-
struct illegal_arithmetic_operation : utree_exception
{
virtual const char* what() const throw()
@@ -367,7 +366,7 @@
template <typename A, typename B>
utree dispatch(A const&, B const&, boost::mpl::false_) const
{
- throw illegal_integral_operation();
+ boost::throw_exception(illegal_integral_operation());
return utree(); // cannot apply to non-integral types
}
Modified: trunk/boost/spirit/home/support/utree/utree.hpp
==============================================================================
--- trunk/boost/spirit/home/support/utree/utree.hpp (original)
+++ trunk/boost/spirit/home/support/utree/utree.hpp 2010-11-30 15:35:36 EST (Tue, 30 Nov 2010)
@@ -35,6 +35,22 @@
namespace boost { namespace spirit
{
///////////////////////////////////////////////////////////////////////////
+ // all exceptions throw by utree are derived from utree_exception
+ struct utree_exception : std::exception {};
+
+ ///////////////////////////////////////////////////////////////////////////
+ // bad_type_exception is thrown whenever somebody calls a member function
+ // which applies to certain stored utree_type's only, but this precondition
+ // is violated as the utree instance holds some other type.
+ struct bad_type_exception : utree_exception
+ {
+ virtual const char* what() const throw()
+ {
+ return "utree: Illegal operation for currently stored data.";
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
// Our utree can store these types. This enum tells us what type
// of data is stored in utree's discriminated union.
///////////////////////////////////////////////////////////////////////////
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