Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69288 - in branches/quickbook-filenames/tools/quickbook: src test/unit
From: dnljms_at_[hidden]
Date: 2011-02-25 18:06:17


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

Log:
Clean up the value consumer interface.
Text files modified:
   branches/quickbook-filenames/tools/quickbook/src/actions.cpp | 48 +++++++++++++++++-----------------
   branches/quickbook-filenames/tools/quickbook/src/doc_info_actions.cpp | 55 +++++++++++++++++++--------------------
   branches/quickbook-filenames/tools/quickbook/src/values.cpp | 40 +++++++++++++---------------
   branches/quickbook-filenames/tools/quickbook/src/values.hpp | 21 +++++++++-----
   branches/quickbook-filenames/tools/quickbook/test/unit/values_test.cpp | 30 ++++++++++----------
   5 files changed, 98 insertions(+), 96 deletions(-)

Modified: branches/quickbook-filenames/tools/quickbook/src/actions.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions.cpp 2011-02-25 18:06:16 EST (Fri, 25 Feb 2011)
@@ -71,9 +71,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())
         {
@@ -203,7 +203,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)
@@ -213,7 +213,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
@@ -260,7 +260,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;
 
@@ -289,7 +289,7 @@
         else
         {
             std::string id =
- !element_id.is_empty() ?
+ !element_id.empty() ?
                     element_id.get_quickbook() :
                     detail::make_identifier(
                         qbk_version_n >= 106 ?
@@ -377,7 +377,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 == '#');
@@ -468,7 +468,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
@@ -630,7 +630,7 @@
             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)
@@ -786,7 +786,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(
@@ -807,9 +807,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(
@@ -1035,7 +1035,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();
@@ -1244,13 +1244,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();
@@ -1274,13 +1274,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_;
@@ -1299,7 +1299,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();
@@ -1388,9 +1388,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());
 
@@ -1527,7 +1527,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());
@@ -1571,7 +1571,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;
@@ -1599,7 +1599,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;
 
@@ -1630,7 +1630,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: branches/quickbook-filenames/tools/quickbook/src/doc_info_actions.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/doc_info_actions.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/doc_info_actions.cpp 2011-02-25 18:06:16 EST (Fri, 25 Feb 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: 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:06:16 EST (Fri, 25 Feb 2011)
@@ -30,7 +30,7 @@
         std::string value_node::get_boostbook() const { assert(false); }
         value_node* value_node::get_list() const { assert(false); }
 
- 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; }
     }
@@ -55,7 +55,7 @@
             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);
@@ -192,7 +192,7 @@
             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_;
         };
@@ -211,7 +211,7 @@
             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_;
@@ -228,7 +228,7 @@
             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_;
@@ -251,7 +251,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 +289,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 +328,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 +363,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 +427,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 +469,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 +514,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 +529,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 +545,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;
@@ -576,7 +574,7 @@
             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 +632,7 @@
         }
 
 
- bool value_list_impl::is_empty() const
+ bool value_list_impl::empty() const
         {
             return head_ == &value_nil_impl::instance;
         }

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:06:16 EST (Fri, 25 Feb 2011)
@@ -48,7 +48,7 @@
             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;
 
@@ -91,7 +91,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(); }
 
@@ -281,19 +281,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 +303,7 @@
 
         value optional_consume(value::tag_type t)
         {
- if(is(t)) {
+ if(check(t)) {
                 return *pos_++;
             }
             else {
@@ -311,15 +311,20 @@
             }
         }
 
- 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_; }

Modified: branches/quickbook-filenames/tools/quickbook/test/unit/values_test.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/test/unit/values_test.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/test/unit/values_test.cpp 2011-02-25 18:06:16 EST (Fri, 25 Feb 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