Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85109 - trunk/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2013-07-22 15:31:48


Author: danieljames
Date: 2013-07-22 15:31:48 EDT (Mon, 22 Jul 2013)
New Revision: 85109
URL: http://svn.boost.org/trac/boost/changeset/85109

Log:
Generic 'scoped_no_eols' implementation.

So that it can be reused for other state variables.

Text files modified:
   trunk/tools/quickbook/src/main_grammar.cpp | 54 +++++++++++++++++++++++++--------------
   1 files changed, 35 insertions(+), 19 deletions(-)

Modified: trunk/tools/quickbook/src/main_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/main_grammar.cpp Mon Jul 22 13:03:01 2013 (r85108)
+++ trunk/tools/quickbook/src/main_grammar.cpp 2013-07-22 15:31:48 EDT (Mon, 22 Jul 2013) (r85109)
@@ -226,35 +226,48 @@
         std::string saved_source_mode_;
     };
 
- struct set_no_eols_scoped : scoped_action_base
+ struct in_list_impl {
+ main_grammar_local& l;
+
+ in_list_impl(main_grammar_local& l) :
+ l(l) {}
+
+ bool operator()() const {
+ return !l.list_stack.top().root;
+ }
+ };
+
+ template <typename T, typename M>
+ struct set_scoped_value_impl : scoped_action_base
     {
- set_no_eols_scoped(main_grammar_local& l)
- : l(l) {}
+ typedef M T::*member_ptr;
+
+ set_scoped_value_impl(T& l, member_ptr ptr)
+ : l(l), ptr(ptr), saved_value() {}
 
- bool start() {
- saved_no_eols = l.no_eols;
- l.no_eols = false;
+ bool start(M const& value) {
+ saved_value = l.*ptr;
+ l.*ptr = value;
 
             return true;
         }
 
         void cleanup() {
- l.no_eols = saved_no_eols;
+ l.*ptr = saved_value;
         }
 
- main_grammar_local& l;
- bool saved_no_eols;
+ T& l;
+ member_ptr ptr;
+ M saved_value;
     };
 
- struct in_list_impl {
- main_grammar_local& l;
-
- in_list_impl(main_grammar_local& l) :
- l(l) {}
+ template <typename T, typename M>
+ struct set_scoped_value : scoped_parser<set_scoped_value_impl<T, M> >
+ {
+ typedef set_scoped_value_impl<T, M> impl;
 
- bool operator()() const {
- return !l.list_stack.top().root;
- }
+ set_scoped_value(T& l, typename impl::member_ptr ptr) :
+ scoped_parser<impl>(impl(l, ptr)) {}
     };
 
     ////////////////////////////////////////////////////////////////////////////
@@ -287,8 +300,11 @@
 
         // Local Actions
         scoped_parser<process_element_impl> process_element(local);
- scoped_parser<set_no_eols_scoped> scoped_no_eols(local);
         in_list_impl in_list(local);
+
+ set_scoped_value<main_grammar_local, bool> scoped_no_eols(
+ local, &main_grammar_local::no_eols);
+
         member_action<main_grammar_local> check_indentation(local,
             &main_grammar_local::check_indentation_impl);
         member_action<main_grammar_local> check_code_block(local,
@@ -354,7 +370,7 @@
             ;
 
         inside_preformatted =
- scoped_no_eols()
+ scoped_no_eols(false)
             [ paragraph_phrase
             ]
             ;


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