Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63623 - branches/quickbook-1.5-spirit2
From: daniel_james_at_[hidden]
Date: 2010-07-04 14:58:21


Author: danieljames
Date: 2010-07-04 14:58:20 EDT (Sun, 04 Jul 2010)
New Revision: 63623
URL: http://svn.boost.org/trac/boost/changeset/63623

Log:
Remove my silly way of calling the encoder.
Text files modified:
   branches/quickbook-1.5-spirit2/block_actions.cpp | 58 ++++++++++++++++-----------------------
   branches/quickbook-1.5-spirit2/block_actions.hpp | 29 +++++++++----------
   branches/quickbook-1.5-spirit2/block_list.cpp | 9 ++++--
   branches/quickbook-1.5-spirit2/doc_info_actions.cpp | 6 ++--
   branches/quickbook-1.5-spirit2/doc_info_actions.hpp | 2
   branches/quickbook-1.5-spirit2/encoder.hpp | 2 -
   branches/quickbook-1.5-spirit2/fwd.hpp | 2 -
   branches/quickbook-1.5-spirit2/phrase_actions.cpp | 38 ++++++++++++-------------
   branches/quickbook-1.5-spirit2/phrase_actions.hpp | 20 ++++++-------
   branches/quickbook-1.5-spirit2/phrase_image.cpp | 6 ++-
   branches/quickbook-1.5-spirit2/process.cpp | 22 ++-------------
   branches/quickbook-1.5-spirit2/state.hpp | 8 ++++
   branches/quickbook-1.5-spirit2/template.cpp | 16 +++++-----
   13 files changed, 97 insertions(+), 121 deletions(-)

Modified: branches/quickbook-1.5-spirit2/block_actions.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block_actions.cpp (original)
+++ branches/quickbook-1.5-spirit2/block_actions.cpp 2010-07-04 14:58:20 EDT (Sun, 04 Jul 2010)
@@ -18,6 +18,7 @@
 #include "code_snippet_grammar.hpp"
 #include "code_snippet_types.hpp"
 #include "utils.hpp"
+#include "encoder.hpp"
 
 namespace quickbook
 {
@@ -36,28 +37,27 @@
         }
     }
 
- block_formatted process(quickbook::state& state, block_formatted const& x)
+ void process(quickbook::state& state, block_formatted const& x)
     {
         state.paragraph_output();
- return x;
+ state.encode(x);
     }
 
- block_formatted process(quickbook::state& state, paragraph const& x)
+ void process(quickbook::state& state, paragraph const& x)
     {
         state.paragraph_output();
         block_formatted r;
         r.type="paragraph";
         r.content = x.content;
- return r;
+ state.encode(r);
     }
 
- nothing process(quickbook::state& state, block_separator const&)
+ void process(quickbook::state& state, block_separator const&)
     {
         state.paragraph_output();
- return nothing();
     }
 
- begin_section2 process(quickbook::state& state, begin_section const& x)
+ void process(quickbook::state& state, begin_section const& x)
     {
         state.paragraph_output();
 
@@ -89,11 +89,10 @@
         }
         
         r.content = x.content.content;
-
- return r;
+ state.encode(r);
     }
 
- end_section2 process(quickbook::state& state, end_section const& x)
+ void process(quickbook::state& state, end_section const& x)
     {
         state.paragraph_output();
 
@@ -103,8 +102,7 @@
                 << "Mismatched [endsect] near column " << x.position.column << ".\n";
             ++state.error_count;
             
- // TODO: Return something else?
- return end_section2();
+ return;
         }
 
         --state.section_level;
@@ -119,11 +117,11 @@
                 state.qualified_section_id.value.find_last_of('.');
             state.qualified_section_id.value.erase(n, std::string::npos);
         }
-
- return end_section2();
+
+ state.encode(end_section2());
     }
 
- heading2 process(quickbook::state& state, heading const& x)
+ void process(quickbook::state& state, heading const& x)
     {
         state.paragraph_output();
 
@@ -160,10 +158,10 @@
 
         r.content = x.content.content;
         
- return r;
+ state.encode(r);
     }
 
- nothing process(quickbook::state& state, def_macro const& x)
+ void process(quickbook::state& state, def_macro const& x)
     {
         state.paragraph_output();
 
@@ -171,10 +169,9 @@
             x.macro_identifier.begin()
           , x.macro_identifier.end()
           , quickbook::macro(x.content));
- return nothing();
     }
 
- nothing process(quickbook::state& state, define_template const& x)
+ void process(quickbook::state& state, define_template const& x)
     {
         state.paragraph_output();
 
@@ -183,11 +180,9 @@
                 << "Template Redefinition: " << x.id << std::endl;
             ++state.error_count;
         }
-
- return nothing();
     }
 
- table2 process(quickbook::state& state, table const& x)
+ void process(quickbook::state& state, table const& x)
     {
         state.paragraph_output();
 
@@ -224,14 +219,13 @@
 
         r.rows.assign(row, x.rows.end());
 
- return r;
+ state.encode(r);
     }
 
- variablelist process(quickbook::state& state, variablelist const& x)
+ void process(quickbook::state& state, variablelist const& x)
     {
         state.paragraph_output();
-
- return x;
+ state.encode(x);
     }
 
     namespace
@@ -330,16 +324,16 @@
         }
     }
 
- xinclude2 process(quickbook::state& state, xinclude const& x)
+ void process(quickbook::state& state, xinclude const& x)
     {
         state.paragraph_output();
 
         xinclude2 r;
         r.path = calculate_relative_path(detail::escape_uri(x.path), state).string();
- return r;
+ state.encode(r);
     }
 
- nothing process(quickbook::state& state, include const& x)
+ void process(quickbook::state& state, include const& x)
     {
         state.paragraph_output();
 
@@ -394,11 +388,9 @@
         state.macro = macro;
         // restore the templates
         //~ state.templates = templates; $$$ fixme $$$
-
- return nothing();
     }
 
- nothing process(quickbook::state& state, import const& x)
+ void process(quickbook::state& state, import const& x)
     {
         state.paragraph_output();
 
@@ -417,7 +409,5 @@
                 ++state.error_count;
             }
         }
-
- return nothing();
     }
 }
\ No newline at end of file

Modified: branches/quickbook-1.5-spirit2/block_actions.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block_actions.hpp (original)
+++ branches/quickbook-1.5-spirit2/block_actions.hpp 2010-07-04 14:58:20 EDT (Sun, 04 Jul 2010)
@@ -11,24 +11,23 @@
 #define BOOST_SPIRIT_QUICKBOOK_BLOCK_ACTIONS_HPP
 
 #include "block.hpp"
-#include "gen_types.hpp"
 
 namespace quickbook
 {
- block_formatted process(quickbook::state&, block_formatted const&);
- block_formatted process(quickbook::state&, paragraph const&);
- nothing process(quickbook::state&, block_separator const&);
- begin_section2 process(quickbook::state&, begin_section const&);
- end_section2 process(quickbook::state&, end_section const&);
- heading2 process(quickbook::state&, heading const&);
- nothing process(quickbook::state&, def_macro const&);
- nothing process(quickbook::state&, define_template const&);
- table2 process(quickbook::state&, table const&);
- variablelist process(quickbook::state&, variablelist const&);
- xinclude2 process(quickbook::state&, xinclude const&);
- nothing process(quickbook::state&, import const&);
- nothing process(quickbook::state&, include const&);
- list2 process(quickbook::state&, list const&);
+ void process(quickbook::state&, block_formatted const&);
+ void process(quickbook::state&, paragraph const&);
+ void process(quickbook::state&, block_separator const&);
+ void process(quickbook::state&, begin_section const&);
+ void process(quickbook::state&, end_section const&);
+ void process(quickbook::state&, heading const&);
+ void process(quickbook::state&, def_macro const&);
+ void process(quickbook::state&, define_template const&);
+ void process(quickbook::state&, table const&);
+ void process(quickbook::state&, variablelist const&);
+ void process(quickbook::state&, xinclude const&);
+ void process(quickbook::state&, import const&);
+ void process(quickbook::state&, include const&);
+ void process(quickbook::state&, list const&);
 }
 
 #endif
\ No newline at end of file

Modified: branches/quickbook-1.5-spirit2/block_list.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block_list.cpp (original)
+++ branches/quickbook-1.5-spirit2/block_list.cpp 2010-07-04 14:58:20 EDT (Sun, 04 Jul 2010)
@@ -10,9 +10,13 @@
 
 #include <stack>
 #include <boost/assert.hpp>
+#include "block_actions.hpp"
 #include "state.hpp"
 #include "gen_types.hpp"
 #include "utils.hpp"
+#include "encoder.hpp"
+
+#include <iostream>
 
 namespace quickbook
 {
@@ -42,10 +46,9 @@
         int indent;
     };
 
- list2 process(quickbook::state& state, quickbook::list const& list)
+ void process(quickbook::state& state, quickbook::list const& list)
     {
         state.paragraph_output();
-
         list::const_iterator it = list.begin(), end = list.end();
         BOOST_ASSERT(it != end);
         
@@ -88,6 +91,6 @@
             }
         }
 
- return r;
+ state.encode(r);
     }
 }
\ No newline at end of file

Modified: branches/quickbook-1.5-spirit2/doc_info_actions.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/doc_info_actions.cpp (original)
+++ branches/quickbook-1.5-spirit2/doc_info_actions.cpp 2010-07-04 14:58:20 EDT (Sun, 04 Jul 2010)
@@ -19,7 +19,7 @@
 #include "doc_info_actions.hpp"
 #include "state.hpp"
 #include "utils.hpp"
-#include <iostream>
+#include "encoder.hpp"
 
 namespace quickbook
 {
@@ -44,7 +44,7 @@
         };
     }
 
- doc_info process(quickbook::state& state, doc_info const& x)
+ void process(quickbook::state& state, doc_info const& x)
     {
         doc_info info = x;
     
@@ -106,6 +106,6 @@
                 ;
         }
 
- return info;
+ state.encode(info);
     }
 }

Modified: branches/quickbook-1.5-spirit2/doc_info_actions.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/doc_info_actions.hpp (original)
+++ branches/quickbook-1.5-spirit2/doc_info_actions.hpp 2010-07-04 14:58:20 EDT (Sun, 04 Jul 2010)
@@ -17,7 +17,7 @@
 
 namespace quickbook
 {
- doc_info process(quickbook::state&, doc_info const&);
+ void process(quickbook::state&, doc_info const&);
 }
 
 #endif

Modified: branches/quickbook-1.5-spirit2/encoder.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/encoder.hpp (original)
+++ branches/quickbook-1.5-spirit2/encoder.hpp 2010-07-04 14:58:20 EDT (Sun, 04 Jul 2010)
@@ -33,8 +33,6 @@
     // push and pop methods.
     
     struct encoder {
- void operator()(quickbook::state&, nothing) {}
-
         virtual void operator()(quickbook::state&, doc_info const&) = 0;
         virtual void operator()(quickbook::state&, doc_info_post const&) = 0;
     

Modified: branches/quickbook-1.5-spirit2/fwd.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/fwd.hpp (original)
+++ branches/quickbook-1.5-spirit2/fwd.hpp 2010-07-04 14:58:20 EDT (Sun, 04 Jul 2010)
@@ -16,8 +16,6 @@
 
 namespace quickbook
 {
- struct nothing {};
-
     struct template_stack;
     struct macro;
     struct doc_info;

Modified: branches/quickbook-1.5-spirit2/phrase_actions.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/phrase_actions.cpp (original)
+++ branches/quickbook-1.5-spirit2/phrase_actions.cpp 2010-07-04 14:58:20 EDT (Sun, 04 Jul 2010)
@@ -9,6 +9,7 @@
 =============================================================================*/
 
 #include <boost/assert.hpp>
+#include "phrase_actions.hpp"
 #include "phrase.hpp"
 #include "actions.hpp"
 #include "state.hpp"
@@ -19,41 +20,40 @@
 
 namespace quickbook
 {
- nothing process(quickbook::state& state, source_mode const& s) {
+ void process(quickbook::state& state, source_mode const& s) {
         state.source_mode = s.mode;
- return nothing();
     }
 
     // TODO: If I used a different types for quickbook and the generated
     // output, I could possibly do something smarter here.
- std::string process(quickbook::state& state, macro const& x) {
+ void process(quickbook::state& state, macro const& x) {
         if (x.raw_markup == quickbook_get_date)
         {
             char strdate[64];
             strftime(strdate, sizeof(strdate), "%Y-%b-%d", current_time);
- return state.encoder->encode(strdate);
+ state.encode(state.encoder->encode(strdate));
         }
         else if (x.raw_markup == quickbook_get_time)
         {
             char strdate[64];
             strftime(strdate, sizeof(strdate), "%I:%M:%S %p", current_time);
- return state.encoder->encode(strdate);
+ state.encode(state.encoder->encode(strdate));
         }
         else
         {
- return x.raw_markup;
+ state.encode(x.raw_markup);
         }
     }
 
- link process(quickbook::state& state, link const& x) {
+ void process(quickbook::state& state, link const& x) {
         link r = x;
         if(r.content.empty()) {
             r.content = state.encoder->encode(x.destination);
         }
- return r;
+ state.encode(r);
     }
 
- formatted process(quickbook::state& state, simple_markup const& x) {
+ void process(quickbook::state& state, simple_markup const& x) {
         formatted r;
         switch(x.symbol) {
             case '*': r.type = "bold"; break;
@@ -65,23 +65,23 @@
 
         r.content = state.encoder->encode(x.raw_content);
 
- return r;
+ state.encode(r);
     }
 
- std::string process(quickbook::state& state, cond_phrase const& x) {
+ void process(quickbook::state& state, cond_phrase const& x) {
         bool symbol_found = state.macro.find(x.macro_id.c_str());
 
- return (!x.content.empty() && symbol_found) ? x.content : "";
+ if(!x.content.empty() && symbol_found) state.encode(x.content);
     }
 
- break_ process(quickbook::state& state, break_ const& x) {
+ void process(quickbook::state& state, break_ const& x) {
         detail::outwarn(x.position.file,x.position.line)
             << "in column:" << x.position.column << ", "
             << "[br] and \\n are deprecated" << ".\n";
- return x;
+ state.encode(x);
     }
 
- boost::variant<formatted, block_formatted> process(quickbook::state& state, code const& x) {
+ void process(quickbook::state& state, code const& x) {
         if(x.flow == x.block) state.paragraph_output();
     
          std::string program = x.content;
@@ -89,10 +89,8 @@
         if(x.flow == x.block || x.flow == x.inline_block) {
             // preprocess the code section to remove the initial indentation
             detail::unindent(program);
- formatted r;
- r.type = "";
             if (program.size() == 0)
- return r; // Nothing left to do here. The program is empty.
+ return; // Nothing left to do here. The program is empty.
         }
 
         iterator first_(program.begin(), program.end());
@@ -114,13 +112,13 @@
             block_formatted r;
             r.type = "programlisting";
             r.content = str;
- return r;
+ state.encode(r);
         }
         else {
             formatted r;
             r.type = x.flow == x.inline_block ? "programlisting" : "code";
             r.content = str;
- return r;
+ state.encode(r);
         }
     }
 }

Modified: branches/quickbook-1.5-spirit2/phrase_actions.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/phrase_actions.hpp (original)
+++ branches/quickbook-1.5-spirit2/phrase_actions.hpp 2010-07-04 14:58:20 EDT (Sun, 04 Jul 2010)
@@ -10,22 +10,20 @@
 #if !defined(BOOST_SPIRIT_QUICKBOOK_PHRASE_ACTIONS_HPP)
 #define BOOST_SPIRIT_QUICKBOOK_PHRASE_ACTIONS_HPP
 
-#include <boost/variant/variant.hpp>
 #include "phrase.hpp"
 #include "code.hpp"
-#include "gen_types.hpp"
 
 namespace quickbook
 {
- nothing process(quickbook::state&, source_mode const&);
- std::string process(quickbook::state&, macro const&);
- link process(quickbook::state&, link const&);
- formatted process(quickbook::state&, simple_markup const&);
- std::string process(quickbook::state&, cond_phrase const&);
- break_ process(quickbook::state&, break_ const&);
- boost::variant<formatted, block_formatted> process(quickbook::state&, code const&);
- image2 process(quickbook::state&, image const&);
- nothing process(quickbook::state&, call_template const&);
+ void process(quickbook::state&, source_mode const&);
+ void process(quickbook::state&, macro const&);
+ void process(quickbook::state&, link const&);
+ void process(quickbook::state&, simple_markup const&);
+ void process(quickbook::state&, cond_phrase const&);
+ void process(quickbook::state&, break_ const&);
+ void process(quickbook::state&, code const&);
+ void process(quickbook::state&, image const&);
+ void process(quickbook::state&, call_template const&);
 }
 
 #endif

Modified: branches/quickbook-1.5-spirit2/phrase_image.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/phrase_image.cpp (original)
+++ branches/quickbook-1.5-spirit2/phrase_image.cpp 2010-07-04 14:58:20 EDT (Sun, 04 Jul 2010)
@@ -10,16 +10,18 @@
 
 #include <boost/filesystem/convenience.hpp>
 #include <boost/filesystem/fstream.hpp>
+#include "phrase_actions.hpp"
 #include "phrase.hpp"
 #include "gen_types.hpp"
 #include "state.hpp"
 #include "utils.hpp"
+#include "encoder.hpp"
 
 namespace quickbook
 {
     namespace fs = boost::filesystem;
 
- image2 process(quickbook::state& state, image const& x)
+ void process(quickbook::state& state, image const& x)
     {
         typedef image2::attribute_map attribute_map;
         typedef attribute_map::value_type attribute;
@@ -113,6 +115,6 @@
            }
         }
         
- return image2(attributes);
+ state.encode(image2(attributes));
     }
 }
\ No newline at end of file

Modified: branches/quickbook-1.5-spirit2/process.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/process.cpp (original)
+++ branches/quickbook-1.5-spirit2/process.cpp 2010-07-04 14:58:20 EDT (Sun, 04 Jul 2010)
@@ -20,35 +20,19 @@
 #include "template.hpp"
 #include "doc_info_actions.hpp"
 #include "encoder.hpp"
-#include <boost/variant/apply_visitor.hpp>
 
 namespace quickbook
 {
- namespace {
- template <typename T>
- inline void encode_impl(state& state_, T const& x)
- {
- (*state_.encoder)(state_, x);
- }
-
- template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
- inline void encode_impl(state& state_, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& x)
- {
- encode_action visitor(state_, *state_.encoder);
- boost::apply_visitor(visitor, x);
- }
- }
-
     template <typename T>
     void process_action::operator()(T const& x) const
     {
- encode_impl(actions.state_, process(actions.state_, x));
+ process(actions.state_, x);
     }
 
     template <typename T>
- T const& process(quickbook::state&, T const& x)
+ void process(quickbook::state& state, T const& x)
     {
- return x;
+ state.encode(x);
     }
 
     template void process_action::operator()<std::string>(std::string const&) const;

Modified: branches/quickbook-1.5-spirit2/state.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/state.hpp (original)
+++ branches/quickbook-1.5-spirit2/state.hpp 2010-07-04 14:58:20 EDT (Sun, 04 Jul 2010)
@@ -78,7 +78,13 @@
 
     //
         void paragraph_output();
- };
+
+ template <typename T>
+ void encode(T const& x) {
+ const std::type_info &info = typeid(x);
+ (*encoder)(*this, x);
+ }
+ };
 }
 
 #endif // BOOST_SPIRIT_ACTIONS_CLASS_HPP

Modified: branches/quickbook-1.5-spirit2/template.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/template.cpp (original)
+++ branches/quickbook-1.5-spirit2/template.cpp 2010-07-04 14:58:20 EDT (Sun, 04 Jul 2010)
@@ -360,7 +360,7 @@
         }
     }
 
- nothing process(quickbook::state& state, call_template const& x)
+ void process(quickbook::state& state, call_template const& x)
     {
         ++state.template_depth;
         if (state.template_depth > state.max_template_depth)
@@ -369,7 +369,7 @@
                 << "Infinite loop detected" << std::endl;
             --state.template_depth;
             ++state.error_count;
- return nothing();
+ return;
         }
 
         // The template arguments should have the scope that the template was
@@ -402,7 +402,7 @@
                 state.pop(); // restore the state
                 --state.template_depth;
                 ++state.error_count;
- return nothing();
+ return;
             }
 
             ///////////////////////////////////
@@ -417,7 +417,7 @@
             {
                 state.pop(); // restore the state
                 --state.template_depth;
- return nothing();
+ return;
             }
 
             ///////////////////////////////////
@@ -435,7 +435,7 @@
                 state.pop(); // restore the state
                 --state.template_depth;
                 ++state.error_count;
- return nothing();
+ return;
             }
 
             if (state.section_level != state.min_section_level)
@@ -445,7 +445,7 @@
                 state.pop(); // restore the actions' states
                 --state.template_depth;
                 ++state.error_count;
- return nothing();
+ return;
             }
         }
 
@@ -469,7 +469,7 @@
                         << "Error expanding callout."
                         << std::endl;
                     ++state.error_count;
- return nothing();
+ return;
                 }
 
                 list.push_back(item);
@@ -492,6 +492,6 @@
             state.phrase << result;
         }
         
- return nothing();
+ return;
     }
 }


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