Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69167 - branches/quickbook-filenames/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-02-22 15:29:29


Author: danieljames
Date: 2011-02-22 15:29:23 EST (Tue, 22 Feb 2011)
New Revision: 69167
URL: http://svn.boost.org/trac/boost/changeset/69167

Log:
Try out more dynamic action dispatch.

Rather than a switch case, the final version will probably use something
like `std::map<value_tag, boost::function<...> >` to dispatch the
actions.
Text files modified:
   branches/quickbook-filenames/tools/quickbook/src/actions.cpp | 46 +++++++++++++++++++++++++++++----------
   branches/quickbook-filenames/tools/quickbook/src/actions.hpp | 42 ++++++++---------------------------
   branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp | 2
   branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp | 3 +
   branches/quickbook-filenames/tools/quickbook/src/block_element_grammar.cpp | 2
   branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp | 5 ++-
   6 files changed, 51 insertions(+), 49 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-22 15:29:23 EST (Tue, 22 Feb 2011)
@@ -49,6 +49,30 @@
         }
     }
 
+ void header_action(quickbook::actions&, value);
+
+ void element_action::operator()(iterator, iterator) const
+ {
+ value_consumer values = actions.values.get();
+ if(!values.is()) return;
+ value v = values.consume();
+ if(values.is()) return;
+
+ switch(v.get_tag())
+ {
+ case block_tags::generic_heading:
+ case block_tags::heading1:
+ case block_tags::heading2:
+ case block_tags::heading3:
+ case block_tags::heading4:
+ case block_tags::heading5:
+ case block_tags::heading6:
+ return header_action(actions, v);
+ default:
+ break;
+ }
+ }
+
     // Handles line-breaks (DEPRECATED!!!)
     void break_action::operator()(iterator first, iterator) const
     {
@@ -156,15 +180,11 @@
         }
     }
 
- void header_action::operator()(iterator first, iterator last) const
+ void header_action(quickbook::actions& actions, value heading_list)
     {
         if(actions.suppress) return;
 
- value_consumer values = actions.values.get();
- value heading_list = values.consume();
- assert(!values.is());
-
- values = heading_list;
+ value_consumer values = heading_list;
 
         bool generic = heading_list.get_tag() == block_tags::generic_heading;
         value element_id = values.optional_consume(general_tags::element_id);
@@ -175,7 +195,8 @@
 
         if (generic)
         {
- level = section_level + 2; // section_level is zero-based. We need to use a
+ level = actions.section_level + 2;
+ // section_level is zero-based. We need to use a
                                             // one-based heading which is one greater
                                             // than the current. Thus: section_level + 2.
             if (level > 6 ) // The max is h6, clip it if it goes
@@ -191,7 +212,7 @@
 
         if (!generic && qbk_version_n < 103) // version 1.2 and below
         {
- anchor = section_id + '.' +
+ anchor = actions.section_id + '.' +
                 detail::make_identifier(content.get_boostbook());
         }
         else
@@ -206,15 +227,16 @@
                     );
 
             linkend = anchor =
- fully_qualified_id(library_id, qualified_section_id, id);
+ fully_qualified_id(actions.doc_id, actions.qualified_section_id, id);
         }
 
- actions.output_pre(out);
+ actions.output_pre(actions.out);
         actions.anchors.swap(actions.saved_anchors);
         actions.anchors.push_back(anchor);
- actions.output_pre(out);
+ actions.output_pre(actions.out);
         
- write_bridgehead(out, level, content.get_boostbook(), anchor + "-heading", linkend);
+ write_bridgehead(actions.out, level,
+ content.get_boostbook(), anchor + "-heading", linkend);
     }
 
     void simple_phrase_action::operator()(iterator first, iterator last) const

Modified: branches/quickbook-filenames/tools/quickbook/src/actions.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions.hpp 2011-02-22 15:29:23 EST (Tue, 22 Feb 2011)
@@ -112,6 +112,16 @@
         quickbook::actions& actions;
     };
 
+ struct element_action
+ {
+ element_action(quickbook::actions& actions)
+ : actions(actions) {}
+
+ void operator()(iterator, iterator) const;
+
+ quickbook::actions& actions;
+ };
+
     struct tagged_action
     {
         tagged_action(
@@ -188,37 +198,6 @@
         quickbook::actions& actions;
     };
 
- struct header_action
- {
- // Handles h
-
- header_action(
- collector& out,
- collector& phrase,
- std::string const& library_id,
- std::string const& section_id,
- std::string const& qualified_section_id,
- int const& section_level,
- quickbook::actions& actions)
- : out(out)
- , phrase(phrase)
- , library_id(library_id)
- , section_id(section_id)
- , qualified_section_id(qualified_section_id)
- , section_level(section_level)
- , actions(actions) {}
-
- void operator()(iterator first, iterator last) const;
-
- collector& out;
- collector& phrase;
- std::string const& library_id;
- std::string const& section_id;
- std::string const& qualified_section_id;
- int const& section_level;
- quickbook::actions& actions;
- };
-
     struct simple_phrase_action
     {
         // Handles simple text formats
@@ -832,4 +811,3 @@
 #endif
 
 #endif // BOOST_SPIRIT_QUICKBOOK_ACTIONS_HPP
-

Modified: branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp 2011-02-22 15:29:23 EST (Tue, 22 Feb 2011)
@@ -65,6 +65,7 @@
         , warned_about_breaks(false)
 
     // actions
+ , element(*this)
         , error(*this)
         , scoped_block(*this)
         , scoped_phrase(*this)
@@ -72,7 +73,6 @@
         , code_block(phrase, phrase, *this)
         , inline_code(phrase, *this)
         , inside_paragraph(out, phrase, paragraph_pre, paragraph_post, *this)
- , heading(out, phrase, doc_id, section_id, qualified_section_id, section_level, *this)
         , hr(out, hr_, *this)
         , blurb(out, blurb_pre, blurb_post, *this)
         , blockquote(out, blockquote_pre, blockquote_post, *this)

Modified: branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp 2011-02-22 15:29:23 EST (Tue, 22 Feb 2011)
@@ -103,6 +103,8 @@
     ///////////////////////////////////////////////////////////////////////////
     // actions
     ///////////////////////////////////////////////////////////////////////////
+
+ element_action element;
         error_action error;
 
         scoped_parser<scoped_block_push>
@@ -114,7 +116,6 @@
         code_action code_block;
         inline_code_action inline_code;
         implicit_paragraph_action inside_paragraph;
- header_action heading;
         markup_action hr;
         tagged_action blurb, blockquote;
         scoped_parser<set_no_eols_scoped>

Modified: branches/quickbook-filenames/tools/quickbook/src/block_element_grammar.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/block_element_grammar.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/block_element_grammar.cpp 2011-02-22 15:29:23 EST (Tue, 22 Feb 2011)
@@ -99,7 +99,7 @@
>> local.element_id_1_6
>> space
>> local.inner_phrase
- ] [actions.heading]
+ ]
             ;
 
         // This looks verbose now, but it'll eventually be replaced with a

Modified: branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp 2011-02-22 15:29:23 EST (Tue, 22 Feb 2011)
@@ -174,7 +174,7 @@
                                                 [actions.inside_paragraph]
                                                 [actions.values.reset]
>> ( local.element_rule
- >> ( (space >> ']')
+ >> ( (space >> ']') [actions.element]
                     | cl::eps_p [actions.error]
                     )
                 | cl::eps_p [actions.error]
@@ -384,6 +384,7 @@
>> cl::eps_p(local.check_element(element_info::in_phrase))
                                                 [actions.values.reset]
>> local.element_rule
+ >> cl::eps_p(space >> ']') [actions.element]
                 | local.template_
                 | cl::str_p("br") [actions.break_]
                 )
@@ -397,7 +398,7 @@
                                                 [actions.inside_paragraph]
                                                 [actions.values.reset]
>> ( local.element_rule
- >> ( (space >> ']')
+ >> ( (space >> ']') [actions.element]
                     | cl::eps_p [actions.error]
                     )
                 | cl::eps_p [actions.error]


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