Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r70192 - in trunk/tools/quickbook: . src test/unit
From: dnljms_at_[hidden]
Date: 2011-03-19 11:42:10


Author: danieljames
Date: 2011-03-19 11:42:08 EDT (Sat, 19 Mar 2011)
New Revision: 70192
URL: http://svn.boost.org/trac/boost/changeset/70192

Log:
Quickbook: clean up the value stuff.
Properties modified:
   trunk/tools/quickbook/ (props changed)
Text files modified:
   trunk/tools/quickbook/src/actions.cpp | 60 ++++++++++++++++++-------------
   trunk/tools/quickbook/src/doc_info_actions.cpp | 55 ++++++++++++++--------------
   trunk/tools/quickbook/src/values.cpp | 75 ++++++++++++++++++++++++++-------------
   trunk/tools/quickbook/src/values.hpp | 67 ++++++++++++++++++++++++++++-------
   trunk/tools/quickbook/test/unit/values_test.cpp | 30 ++++++++--------
   5 files changed, 180 insertions(+), 107 deletions(-)

Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp (original)
+++ trunk/tools/quickbook/src/actions.cpp 2011-03-19 11:42:08 EDT (Sat, 19 Mar 2011)
@@ -74,9 +74,9 @@
     void element_action::operator()(iterator first, iterator) const
     {
         value_consumer values = actions.values.get();
- if(!values.is()) return;
+ if(!values.check()) return;
         value v = values.consume();
- if(values.is()) return;
+ if(values.check()) return;
         
         switch(v.get_tag())
         {
@@ -206,7 +206,7 @@
 
         value_consumer values = block;
         actions.out << markup.pre << values.consume().get_boostbook() << markup.post;
- assert(!values.is());
+ values.finish();
     }
 
     void phrase_action_(quickbook::actions& actions, value phrase)
@@ -216,7 +216,7 @@
 
         value_consumer values = phrase;
         actions.phrase << markup.pre << values.consume().get_boostbook() << markup.post;
- assert(!values.is());
+ values.finish();
     }
 
     void paragraph_action::operator()() const
@@ -263,7 +263,7 @@
         bool generic = heading_list.get_tag() == block_tags::generic_heading;
         value element_id = values.optional_consume(general_tags::element_id);
         value content = values.consume();
- assert(!values.is());
+ values.finish();
 
         int level;
 
@@ -292,7 +292,7 @@
         else
         {
             std::string id =
- !element_id.is_empty() ?
+ !element_id.empty() ?
                     element_id.get_quickbook() :
                     detail::make_identifier(
                         qbk_version_n >= 106 ?
@@ -380,7 +380,7 @@
                     values.consume(general_tags::list_indent).get_quickbook());
             value mark_value = values.consume(general_tags::list_mark);
             std::string content = values.consume().get_boostbook();
- assert(!values.is());
+ values.finish();
 
             char mark = mark_value.get_quickbook()[0];
             assert(mark == '*' || mark == '#');
@@ -471,7 +471,7 @@
         
         value_consumer values = anchor;
         actions.anchors.push_back(values.consume().get_quickbook());
- assert(!values.is());
+ values.finish();
     }
 
     void do_macro_action::operator()(std::string const& str) const
@@ -633,13 +633,15 @@
             value_consumer pair = pair_;
             value name = pair.consume();
             value value = pair.consume();
- assert(!pair.is());
+ pair.finish();
             if(!attributes.insert(std::make_pair(name.get_quickbook(), value)).second)
             {
                 detail::outwarn(actions.filename, name.get_position().line)
                     << "Duplicate image attribute: " << name.get_quickbook() << std::endl;
             }
         }
+
+ values.finish();
 
         // Find the file basename and extension.
         //
@@ -798,7 +800,7 @@
         value_consumer values = macro_definition;
         std::string macro_id = values.consume().get_quickbook();
         std::string phrase = values.consume().get_boostbook();
- assert(!values.is());
+ values.finish();
 
         actions.copy_macros_for_write();
         actions.macro.add(
@@ -819,9 +821,9 @@
             template_values.push_back(p.get_quickbook());
         }
 
- BOOST_ASSERT(values.is(template_tags::block) || values.is(template_tags::phrase));
+ BOOST_ASSERT(values.check(template_tags::block) || values.check(template_tags::phrase));
         value body = values.consume();
- BOOST_ASSERT(!values.is());
+ BOOST_ASSERT(!values.check());
     
         if (!actions.templates.add(
             template_symbol(
@@ -1047,7 +1049,7 @@
         // Get the arguments
         value_consumer values = actions.values.get();
 
- bool template_escape = values.is(template_tags::escape);
+ bool template_escape = values.check(template_tags::escape);
         if(template_escape) values.consume();
 
         std::string identifier = values.consume(template_tags::identifier).get_quickbook();
@@ -1068,6 +1070,8 @@
                     arg.get_tag() == template_tags::block
                 ));
         }
+
+ values.finish();
 
         ++actions.template_depth;
         if (actions.template_depth > actions.max_template_depth)
@@ -1256,13 +1260,13 @@
         value_consumer values = link;
         value dst = values.consume();
         value content = values.consume();
- assert(!values.is());
+ values.finish();
         
         actions.phrase << markup.pre;
         detail::print_string(dst.get_quickbook(), actions.phrase.get());
         actions.phrase << "\">";
 
- if (content.is_empty())
+ if (content.empty())
             detail::print_string(dst.get_quickbook(), actions.phrase.get());
         else
             actions.phrase << content.get_boostbook();
@@ -1286,13 +1290,13 @@
         BOOST_FOREACH(value_consumer entry, values) {
             actions.out << start_varlistentry_;
             
- if(entry.is()) {
+ if(entry.check()) {
                 actions.out << start_varlistterm_;
                 actions.out << entry.consume().get_boostbook();
                 actions.out << end_varlistterm_;
             }
             
- if(entry.is()) {
+ if(entry.check()) {
                 actions.out << start_varlistitem_;
                 BOOST_FOREACH(value phrase, entry) actions.out << phrase.get_boostbook();
                 actions.out << end_varlistitem_;
@@ -1302,6 +1306,8 @@
         }
 
         actions.out << "</variablelist>\n";
+
+ values.finish();
     }
 
     void table_action(quickbook::actions& actions, value table)
@@ -1311,7 +1317,7 @@
         value_consumer values = table;
 
         std::string element_id;
- if(values.is(general_tags::element_id))
+ if(values.check(general_tags::element_id))
             element_id = values.consume().get_quickbook();
 
         std::string title = values.consume(table_tags::title).get_quickbook();
@@ -1335,10 +1341,12 @@
         int row_count = 0;
         int span_count = 0;
 
- BOOST_FOREACH(value row, values) {
+ value_consumer lookahead = values;
+ BOOST_FOREACH(value row, lookahead) {
             ++row_count;
             span_count = boost::distance(row);
         }
+ lookahead.finish();
 
         if (has_title)
         {
@@ -1378,6 +1386,8 @@
             }
             actions.out << end_row_;
         }
+
+ values.finish();
 
         actions.out << "</tbody>\n"
                      << "</tgroup>\n";
@@ -1400,9 +1410,9 @@
 
         value element_id = values.optional_consume(general_tags::element_id);
         value content = values.consume();
- assert(!values.is());
+ values.finish();
 
- actions.section_id = !element_id.is_empty() ?
+ actions.section_id = !element_id.empty() ?
             element_id.get_quickbook() :
             detail::make_identifier(content.get_quickbook());
 
@@ -1543,7 +1553,7 @@
         value_consumer values = xinclude;
         fs::path path = calculate_relative_path(
             check_path(values.consume(), actions), actions);
- assert(!values.is());
+ values.finish();
 
         actions.out << "\n<xi:include href=\"";
         detail::print_string(detail::escape_uri(path.generic_string()), actions.out.get());
@@ -1587,7 +1597,7 @@
         value_consumer values = import;
         fs::path path = include_search(actions.filename.parent_path(),
             check_path(values.consume(), actions));
- assert(!values.is());
+ values.finish();
 
         std::string ext = path.extension().generic_string();
         std::vector<template_symbol> storage;
@@ -1615,7 +1625,7 @@
         value include_doc_id = values.optional_consume(general_tags::include_id);
         fs::path filein = include_search(actions.filename.parent_path(),
             check_path(values.consume(), actions));
- assert(!values.is());
+ values.finish();
 
         std::string doc_type, doc_id;
 
@@ -1646,7 +1656,7 @@
 
         // if an id is specified in this include (as in [include:id foo.qbk])
         // then use it as the doc_id.
- if (!include_doc_id.is_empty())
+ if (!include_doc_id.empty())
             actions.doc_id = include_doc_id.get_quickbook();
 
         // update the __FILENAME__ macro

Modified: trunk/tools/quickbook/src/doc_info_actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/doc_info_actions.cpp (original)
+++ trunk/tools/quickbook/src/doc_info_actions.cpp 2011-03-19 11:42:08 EDT (Sat, 19 Mar 2011)
@@ -33,7 +33,7 @@
         value p;
 
         int count = 0;
- while(c.is(tag)) {
+ while(c.check(tag)) {
             p = c.consume();
             ++count;
         }
@@ -47,12 +47,12 @@
             std::vector<std::string>* duplicates)
     {
         value l = consume_last(c, tag, duplicates);
- if(l.is_empty()) return l;
+ if(l.empty()) return l;
 
         assert(l.is_list());
         value_consumer c2 = l;
         value p = c2.consume();
- assert(!c2.is());
+ c2.finish();
 
         return p;
     }
@@ -61,7 +61,7 @@
     {
         std::vector<value> values;
         
- while(c.is(tag)) {
+ while(c.check(tag)) {
             values.push_back(c.consume());
         }
         
@@ -77,12 +77,12 @@
 
         // Skip over invalid attributes
 
- while (values.is(value::default_tag)) values.consume();
+ while (values.check(value::default_tag)) values.consume();
         
         std::vector<std::string> duplicates;
 
         value doc_title;
- if (values.is())
+ if (values.check())
         {
             actions.doc_type = values.consume(doc_info_tags::type).get_quickbook();
             doc_title = values.consume(doc_info_tags::title);
@@ -103,10 +103,9 @@
         
         // Skip over source-mode tags (already dealt with)
 
- while (values.is(doc_info_attributes::source_mode)) values.consume();
+ while (values.check(doc_info_attributes::source_mode)) values.consume();
 
-
- BOOST_ASSERT(!values.is());
+ values.finish();
 
         if(!duplicates.empty())
         {
@@ -118,14 +117,14 @@
                 ;
         }
 
- if (!id.is_empty())
+ if (!id.empty())
             actions.doc_id = id.get_quickbook();
 
         if (actions.doc_id.empty())
             actions.doc_id = detail::make_identifier(actions.doc_title_qbk);
         
- if (dirname.is_empty() && actions.doc_type == "library") {
- if (!id.is_empty()) {
+ if (dirname.empty() && actions.doc_type == "library") {
+ if (!id.empty()) {
                 dirname = id;
             }
             else {
@@ -133,7 +132,7 @@
             }
         }
 
- if (last_revision.is_empty())
+ if (last_revision.empty())
         {
             // default value for last-revision is now
 
@@ -195,13 +194,13 @@
         {
             std::vector<std::string> invalid_attributes;
 
- if (!purpose.is_empty())
+ if (!purpose.empty())
                 invalid_attributes.push_back("purpose");
 
             if (!categories.empty())
                 invalid_attributes.push_back("category");
 
- if (!dirname.is_empty())
+ if (!dirname.empty())
                 invalid_attributes.push_back("dirname");
 
             if(!invalid_attributes.empty())
@@ -228,7 +227,7 @@
             << actions.doc_id
             << "\"\n";
         
- if(!lang.is_empty())
+ if(!lang.empty())
         {
             out << " lang=\""
                 << doc_info_output(lang, 106)
@@ -240,7 +239,7 @@
             out << " name=\"" << doc_info_output(doc_title, 106) << "\"\n";
         }
 
- if(!dirname.is_empty())
+ if(!dirname.empty())
         {
             out << " dirname=\""
                 << doc_info_output(dirname, 106)
@@ -259,7 +258,7 @@
             tmp << " <authorgroup>\n";
             BOOST_FOREACH(value_consumer author_values, authors)
             {
- while (author_values.is()) {
+ while (author_values.check()) {
                     value surname = author_values.consume(doc_info_tags::author_surname);
                     value first = author_values.consume(doc_info_tags::author_first);
     
@@ -278,16 +277,16 @@
 
         BOOST_FOREACH(value_consumer copyright, copyrights)
         {
- while(copyright.is())
+ while(copyright.check())
             {
                 tmp << "\n" << " <copyright>\n";
     
- while(copyright.is(doc_info_tags::copyright_year))
+ while(copyright.check(doc_info_tags::copyright_year))
                 {
                     int year_start =
                         boost::lexical_cast<int>(copyright.consume().get_quickbook());
                     int year_end =
- copyright.is(doc_info_tags::copyright_year_end) ?
+ copyright.check(doc_info_tags::copyright_year_end) ?
                         boost::lexical_cast<int>(copyright.consume().get_quickbook()) :
                         year_start;
     
@@ -317,7 +316,7 @@
             }
         }
 
- if (!license.is_empty())
+ if (!license.empty())
         {
             tmp << " <legalnotice>\n"
                 << " <para>\n"
@@ -328,7 +327,7 @@
             ;
         }
 
- if (!purpose.is_empty())
+ if (!purpose.empty())
         {
             tmp << " <" << actions.doc_type << "purpose>\n"
                 << " " << doc_info_output(purpose, 103)
@@ -339,14 +338,14 @@
 
         BOOST_FOREACH(value_consumer values, categories) {
             value category = values.optional_consume();
- if(!category.is_empty()) {
+ if(!category.empty()) {
                 tmp << " <" << actions.doc_type << "category name=\"category:"
                     << doc_info_output(category, 106)
                     << "\"></" << actions.doc_type << "category>\n"
                     << "\n"
                 ;
             }
- assert(!values.is());
+ values.finish();
         }
 
         BOOST_FOREACH(value_consumer biblioid, biblioids)
@@ -361,7 +360,7 @@
                 << "</biblioid>"
                 << "\n"
                 ;
- assert(!biblioid.is());
+ biblioid.finish();
         }
 
         if(actions.doc_type != "library") {
@@ -398,11 +397,11 @@
 
     static void write_document_title(collector& out, value const& title, value const& version)
     {
- if (!title.is_empty())
+ if (!title.empty())
         {
             out << " <title>"
                 << doc_info_output(title, 106);
- if (!version.is_empty()) {
+ if (!version.empty()) {
                 out << ' ' << doc_info_output(version, 106);
             }
             out<< "</title>\n\n\n";

Modified: trunk/tools/quickbook/src/values.cpp
==============================================================================
--- trunk/tools/quickbook/src/values.cpp (original)
+++ trunk/tools/quickbook/src/values.cpp 2011-03-19 11:42:08 EDT (Sat, 19 Mar 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,12 +40,12 @@
         
         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::is_empty() const { return false; }
+ bool value_node::empty() const { return false; }
         bool value_node::is_list() const { return false; }
         bool value_node::is_string() const { return false; }
     }
@@ -52,10 +67,12 @@
                 : value_node(t) {}
 
         private:
+ char const* type_name() const { return "empty"; }
+
             virtual value_node* clone() const
                 { return new value_empty_impl(tag_); }
 
- virtual bool is_empty() const
+ virtual bool empty() const
                 { return true; }
             
             friend value quickbook::empty_value(value::tag_type);
@@ -188,11 +205,13 @@
         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;
             virtual bool is_string() const;
- virtual bool is_empty() const;
+ virtual bool empty() const;
     
             std::string value_;
         };
@@ -206,12 +225,14 @@
                     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;
             virtual std::string get_quickbook() const;
             virtual bool is_string() const;
- virtual bool is_empty() const;
+ virtual bool empty() const;
     
             std::string value_;
             file_position position_;
@@ -222,13 +243,15 @@
         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();
             virtual file_position get_position() const;
             virtual std::string get_quickbook() const;
             virtual bool is_string() const;
- virtual bool is_empty() const;
+ virtual bool empty() const;
     
             quickbook::iterator begin_;
             quickbook::iterator end_;
@@ -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);
@@ -251,7 +276,7 @@
             virtual std::string get_quickbook() const;
             virtual std::string get_boostbook() const;
             virtual bool is_string() const;
- virtual bool is_empty() const;
+ virtual bool empty() const;
 
             std::string qbk_value_;
             std::string bbk_value_;
@@ -289,7 +314,7 @@
         bool value_string_impl::is_string() const
             { return true; }
 
- bool value_string_impl::is_empty() const
+ bool value_string_impl::empty() const
             { return value_.empty(); }
 
         // value_qbk_string_impl
@@ -328,7 +353,7 @@
         bool value_qbk_string_impl::is_string() const
             { return true; }
 
- bool value_qbk_string_impl::is_empty() const
+ bool value_qbk_string_impl::empty() const
             { return value_.empty(); }
     
         // value_qbk_ref_impl
@@ -363,7 +388,7 @@
         bool value_qbk_ref_impl::is_string() const
             { return true; }
 
- bool value_qbk_ref_impl::is_empty() const
+ bool value_qbk_ref_impl::empty() const
             { return begin_ == end_; }
     
         // value_qbk_bbk_impl
@@ -427,7 +452,7 @@
             { return true; }
 
         // Should this test the quickbook, the boostbook or both?
- bool value_qbk_bbk_impl::is_empty() const
+ bool value_qbk_bbk_impl::empty() const
             { return bbk_value_.empty(); }
     }
 
@@ -469,9 +494,8 @@
         void list_unref(value_node*);
         value_node** merge_sort(value_node**);
         value_node** merge_sort(value_node**, int);
- value_node** merge_adjacent_ranges(
- value_node**, value_node**, value_node**);
- void swap_adjacent_ranges(value_node**, value_node**, value_node**);
+ value_node** merge(value_node**, value_node**, value_node**);
+ void rotate(value_node**, value_node**, value_node**);
 
         value_node** list_ref_back(value_node** back)
         {
@@ -515,12 +539,12 @@
                 count < recurse_limit && *p != &value_nil_impl::instance;
                 ++count)
             {
- p = merge_adjacent_ranges(l, p, merge_sort(p, count));
+ p = merge(l, p, merge_sort(p, count));
             }
             return p;
         }
         
- value_node** merge_adjacent_ranges(
+ value_node** merge(
                 value_node** first, value_node** second, value_node** third)
         {
             for(;;) {
@@ -530,7 +554,7 @@
                     first = &(*first)->next_;
                 }
     
- swap_adjacent_ranges(first, second, third);
+ rotate(first, second, third);
                 first = &(*first)->next_;
                 
                 // Since the two ranges were just swapped, the order is now:
@@ -546,13 +570,12 @@
                     first = &(*first)->next_;
                 }
     
- swap_adjacent_ranges(first, third, second);
+ rotate(first, third, second);
                 first = &(*first)->next_;
             }
         }
 
- void swap_adjacent_ranges(
- value_node** first, value_node** second, value_node** third)
+ void rotate(value_node** first, value_node** second, value_node** third)
         {
             value_node* tmp = *first;
             *first = *second;
@@ -573,10 +596,12 @@
             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();
- virtual bool is_empty() const;
+ virtual bool empty() const;
             virtual bool is_list() const;
     
             virtual value_node* get_list() const;
@@ -634,7 +659,7 @@
         }
 
 
- bool value_list_impl::is_empty() const
+ bool value_list_impl::empty() const
         {
             return head_ == &value_nil_impl::instance;
         }

Modified: trunk/tools/quickbook/src/values.hpp
==============================================================================
--- trunk/tools/quickbook/src/values.hpp (original)
+++ trunk/tools/quickbook/src/values.hpp 2011-03-19 11:42:08 EDT (Sat, 19 Mar 2011)
@@ -15,12 +15,15 @@
 #include <string>
 #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
     {
@@ -41,6 +44,7 @@
             virtual ~value_node();
 
         public:
+ virtual char const* type_name() const = 0;
             virtual value_node* clone() const = 0;
             virtual value_node* store();
 
@@ -48,12 +52,12 @@
             virtual std::string get_quickbook() const;
             virtual std::string get_boostbook() const;
 
- virtual bool is_empty() const;
+ virtual bool empty() const;
             virtual bool is_list() const;
             virtual bool is_string() const;
 
             virtual value_node* get_list() const;
-
+
             int ref_count_;
             const tag_type tag_;
             value_node* next_;
@@ -91,7 +95,7 @@
         public:
             void swap(value_base& x) { std::swap(value_, x.value_); }
 
- bool is_empty() const { return value_->is_empty(); }
+ bool empty() const { return value_->empty(); }
             bool is_list() const { return value_->is_list(); }
             bool is_string() const { return value_->is_string(); }
 
@@ -129,6 +133,7 @@
         public:
             explicit value_proxy(value_node* base) : value_base(base) {}
             value_proxy* operator->() { return this; }
+ value_ref operator*() const { return value_ref(value_); }
         };
     
         ////////////////////////////////////////////////////////////////////////
@@ -257,14 +262,43 @@
     };
 
     ////////////////////////////////////////////////////////////////////////////
+ // Value Error
+ //
+
+ class value_error : std::logic_error
+ {
+ public:
+ value_error(std::string const&);
+ };
+
+ ////////////////////////////////////////////////////////////////////////////
     // Value Consumer
     //
     // Convenience class for unpacking value values.
 
     class value_consumer {
     public:
- typedef value::iterator iterator;
- typedef value::iterator const_iterator;
+ class iterator
+ : public boost::input_iterator_helper<iterator,
+ boost::iterator_value<value::iterator>::type,
+ boost::iterator_difference<value::iterator>::type,
+ boost::iterator_pointer<value::iterator>::type,
+ boost::iterator_reference<value::iterator>::type>
+ {
+ public:
+ iterator();
+ explicit iterator(value::iterator* p) : ptr_(p) {}
+ friend bool operator==(iterator x, iterator y)
+ { return *x.ptr_ == *y.ptr_; }
+ iterator& operator++() { ++*ptr_; return *this; }
+ reference operator*() const { return **ptr_; }
+ pointer operator->() const { return ptr_->operator->(); }
+ private:
+ value::iterator* ptr_;
+ };
+
+
+ typedef iterator const_iterator;
         typedef iterator::reference reference;
     
         value_consumer(value const& x)
@@ -281,19 +315,19 @@
 
         reference consume()
         {
- assert(is());
+ assert(check());
             return *pos_++;
         }
 
         reference consume(value::tag_type t)
         {
- assert(is(t));
+ assert(check(t));
             return *pos_++;
         }
 
         value optional_consume()
         {
- if(is()) {
+ if(check()) {
                 return *pos_++;
             }
             else {
@@ -303,7 +337,7 @@
 
         value optional_consume(value::tag_type t)
         {
- if(is(t)) {
+ if(check(t)) {
                 return *pos_++;
             }
             else {
@@ -311,21 +345,26 @@
             }
         }
 
- bool is()
+ bool check() const
         {
             return pos_ != end_;
         }
 
- bool is(value::tag_type t)
+ bool check(value::tag_type t) const
         {
             return pos_ != end_ && t == pos_->get_tag();
         }
+
+ void finish() const
+ {
+ assert(pos_ == end_);
+ }
 
- iterator begin() const { return pos_; }
- iterator end() const { return end_; }
+ iterator begin() { return iterator(&pos_); }
+ iterator end() { return iterator(&end_); }
     private:
         value list_;
- iterator pos_, end_;
+ value::iterator pos_, end_;
     };
 }
 

Modified: trunk/tools/quickbook/test/unit/values_test.cpp
==============================================================================
--- trunk/tools/quickbook/test/unit/values_test.cpp (original)
+++ trunk/tools/quickbook/test/unit/values_test.cpp 2011-03-19 11:42:08 EDT (Sat, 19 Mar 2011)
@@ -16,7 +16,7 @@
 void empty_tests()
 {
     quickbook::value q;
- BOOST_TEST(q.is_empty());
+ BOOST_TEST(q.empty());
     BOOST_TEST(!q.is_list());
     BOOST_TEST(!q.is_string());
 }
@@ -40,11 +40,11 @@
     b.sort_list();
     
     quickbook::value_consumer c = b.get();
- BOOST_TEST(c.is(2)); BOOST_TEST_EQ(c.consume(2).get_boostbook(), "b");
- BOOST_TEST(c.is(5)); c.consume(5);
- BOOST_TEST(c.is(8)); c.consume(8);
- BOOST_TEST(c.is(10)); c.consume(10);
- BOOST_TEST(!c.is());
+ BOOST_TEST(c.check(2)); BOOST_TEST_EQ(c.consume(2).get_boostbook(), "b");
+ BOOST_TEST(c.check(5)); c.consume(5);
+ BOOST_TEST(c.check(8)); c.consume(8);
+ BOOST_TEST(c.check(10)); c.consume(10);
+ BOOST_TEST(!c.check());
 }
 
 void multiple_list_test()
@@ -65,17 +65,17 @@
     quickbook::value_consumer l1 = list1.get(); list1.reset();
     quickbook::value_consumer l2 = list2.get(); list2.reset();
 
- BOOST_TEST(l1.is(10));
+ BOOST_TEST(l1.check(10));
     BOOST_TEST_EQ(l1.consume(10).get_boostbook(), "b");
- BOOST_TEST(l1.is(5));
+ BOOST_TEST(l1.check(5));
     BOOST_TEST_EQ(l1.consume(5).get_boostbook(), "a");
- BOOST_TEST(!l1.is());
+ BOOST_TEST(!l1.check());
 
- BOOST_TEST(l2.is(5));
+ BOOST_TEST(l2.check(5));
     BOOST_TEST_EQ(l2.consume(5).get_boostbook(), "a");
- BOOST_TEST(l2.is(3));
+ BOOST_TEST(l2.check(3));
     BOOST_TEST_EQ(l2.consume(3).get_boostbook(), "c");
- BOOST_TEST(!l2.is());
+ BOOST_TEST(!l2.check());
 }
 
 void store_test1()
@@ -100,11 +100,11 @@
 void store_test2_check(quickbook::value const& q)
 {
     quickbook::value_consumer l1 = q;
- BOOST_TEST(l1.is(5));
+ BOOST_TEST(l1.check(5));
     BOOST_TEST_EQ(l1.consume(5).get_quickbook(), "Hello");
- BOOST_TEST(l1.is(10));
+ BOOST_TEST(l1.check(10));
     BOOST_TEST_EQ(l1.consume(10).get_boostbook(), "World");
- BOOST_TEST(!l1.is());
+ BOOST_TEST(!l1.check());
 }
 
 void store_test2()


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