Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69290 - branches/quickbook-filenames/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-02-25 18:07:08


Author: danieljames
Date: 2011-02-25 18:07:07 EST (Fri, 25 Feb 2011)
New Revision: 69290
URL: http://svn.boost.org/trac/boost/changeset/69290

Log:
Throw errors for incorrect method calls rather than assert.
Text files modified:
   branches/quickbook-filenames/tools/quickbook/src/values.cpp | 35 +++++++++++++++++++++++++++++++----
   branches/quickbook-filenames/tools/quickbook/src/values.hpp | 15 ++++++++++++++-
   2 files changed, 45 insertions(+), 5 deletions(-)

Modified: branches/quickbook-filenames/tools/quickbook/src/values.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/values.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/values.cpp 2011-02-25 18:07:07 EST (Fri, 25 Feb 2011)
@@ -8,10 +8,25 @@
 
 #include "values.hpp"
 #include <boost/intrusive_ptr.hpp>
+#include <boost/current_function.hpp>
+
+#define UNDEFINED_ERROR() \
+ throw value_error( \
+ std::string(BOOST_CURRENT_FUNCTION) +\
+ " not defined for " + \
+ this->type_name() + \
+ " values." \
+ );
 
 namespace quickbook
 {
     ////////////////////////////////////////////////////////////////////////////
+ // Value Error
+
+ value_error::value_error(std::string const& x)
+ : std::logic_error(x) {}
+
+ ////////////////////////////////////////////////////////////////////////////
     // Node
 
     namespace detail
@@ -25,10 +40,10 @@
         
         value_node* value_node::store() { return this; }
 
- file_position value_node::get_position() const { assert(false); }
- std::string value_node::get_quickbook() const { assert(false); }
- std::string value_node::get_boostbook() const { assert(false); }
- value_node* value_node::get_list() const { assert(false); }
+ file_position value_node::get_position() const { UNDEFINED_ERROR(); }
+ std::string value_node::get_quickbook() const { UNDEFINED_ERROR(); }
+ std::string value_node::get_boostbook() const { UNDEFINED_ERROR(); }
+ value_node* value_node::get_list() const { UNDEFINED_ERROR(); }
 
         bool value_node::empty() const { return false; }
         bool value_node::is_list() const { return false; }
@@ -52,6 +67,8 @@
                 : value_node(t) {}
 
         private:
+ char const* type_name() const { return "empty"; }
+
             virtual value_node* clone() const
                 { return new value_empty_impl(tag_); }
 
@@ -188,6 +205,8 @@
         public:
             explicit value_string_impl(std::string const&, value::tag_type);
         private:
+ char const* type_name() const { return "boostbook"; }
+
             virtual ~value_string_impl();
             virtual value_node* clone() const;
             virtual std::string get_boostbook() const;
@@ -206,6 +225,8 @@
                     quickbook::iterator begin, quickbook::iterator end,
                     value::tag_type);
         private:
+ char const* type_name() const { return "quickbook"; }
+
             virtual ~value_qbk_string_impl();
             virtual value_node* clone() const;
             virtual file_position get_position() const;
@@ -222,6 +243,8 @@
         public:
             explicit value_qbk_ref_impl(quickbook::iterator begin, quickbook::iterator end, value::tag_type);
         private:
+ char const* type_name() const { return "quickbook"; }
+
             virtual ~value_qbk_ref_impl();
             virtual value_node* clone() const;
             virtual value_node* store();
@@ -237,6 +260,8 @@
         struct value_qbk_bbk_impl : public value_node
         {
         private:
+ char const* type_name() const { return "quickbook/boostbook"; }
+
             value_qbk_bbk_impl(
                 std::string const& qbk, std::string const& bbk,
                 file_position const&, value::tag_type);
@@ -571,6 +596,8 @@
             value_list_impl(value::tag_type);
             value_list_impl(value_node*, value::tag_type);
         private:
+ char const* type_name() const { return "list"; }
+
             virtual ~value_list_impl();
             virtual value_node* clone() const;
             virtual value_node* store();

Modified: branches/quickbook-filenames/tools/quickbook/src/values.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/values.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/values.hpp 2011-02-25 18:07:07 EST (Fri, 25 Feb 2011)
@@ -16,12 +16,14 @@
 #include <cassert>
 #include <boost/scoped_ptr.hpp>
 #include <boost/iterator/iterator_traits.hpp>
+#include <stdexcept>
 #include "fwd.hpp"
 
 namespace quickbook
 {
     class value;
     class value_builder;
+ class value_error;
 
     namespace detail
     {
@@ -42,6 +44,7 @@
             virtual ~value_node();
 
         public:
+ virtual char const* type_name() const = 0;
             virtual value_node* clone() const = 0;
             virtual value_node* store();
 
@@ -54,7 +57,7 @@
             virtual bool is_string() const;
 
             virtual value_node* get_list() const;
-
+
             int ref_count_;
             const tag_type tag_;
             value_node* next_;
@@ -259,6 +262,16 @@
     };
 
     ////////////////////////////////////////////////////////////////////////////
+ // Value Error
+ //
+
+ class value_error : std::logic_error
+ {
+ public:
+ value_error(std::string const&);
+ };
+
+ ////////////////////////////////////////////////////////////////////////////
     // Value Consumer
     //
     // Convenience class for unpacking value values.


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