Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75244 - branches/quickbook-dev/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-11-02 03:42:38


Author: danieljames
Date: 2011-11-02 03:42:37 EDT (Wed, 02 Nov 2011)
New Revision: 75244
URL: http://svn.boost.org/trac/boost/changeset/75244

Log:
Quickbook: Put all the section tracking stuff in a struct.
Text files modified:
   branches/quickbook-dev/tools/quickbook/src/actions.cpp | 44 ++++++++++++++++++++--------------------
   branches/quickbook-dev/tools/quickbook/src/actions_class.cpp | 28 ++++++++++++++----------
   branches/quickbook-dev/tools/quickbook/src/actions_class.hpp | 24 ++++++++++++++-------
   branches/quickbook-dev/tools/quickbook/src/doc_info_actions.cpp | 10 ++++----
   branches/quickbook-dev/tools/quickbook/src/id_generator.hpp | 2
   5 files changed, 60 insertions(+), 48 deletions(-)

Modified: branches/quickbook-dev/tools/quickbook/src/actions.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions.cpp 2011-11-02 03:42:37 EDT (Wed, 02 Nov 2011)
@@ -44,8 +44,8 @@
             std::string const& section_id)
         {
             std::string id = actions.doc_id;
- if(!id.empty() && !actions.qualified_section_id.empty()) id += '.';
- id += actions.qualified_section_id;
+ if(!id.empty() && !actions.section.qualified_id.empty()) id += '.';
+ id += actions.section.qualified_id;
             if(!id.empty() && !section_id.empty()) id += '.';
             id += section_id;
             return id;
@@ -348,10 +348,10 @@
 
         if (generic)
         {
- level = actions.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.
+ // than the current. Thus: section.level + 2.
             if (level > 6 ) // The max is h6, clip it if it goes
                 level = 6; // further than that
         }
@@ -365,7 +365,7 @@
         if (!generic && qbk_version_n < 103) // version 1.2 and below
         {
             std::string anchor = actions.ids.add(
- actions.section_id + '.' +
+ actions.section.id + '.' +
                     detail::make_identifier(content.get_boostbook()),
                 id_generator::generated_heading);
 
@@ -1196,7 +1196,7 @@
 
             // Store the current section level so that we can ensure that
             // [section] and [endsect] tags in the template are balanced.
- actions.min_section_level = actions.section_level;
+ actions.section.min_level = actions.section.level;
 
             // Quickbook 1.4-: When expanding the tempalte continue to use the
             // current scope (the dynamic scope).
@@ -1234,7 +1234,7 @@
                 return;
             }
 
- if (actions.section_level != actions.min_section_level)
+ if (actions.section.level != actions.section.min_level)
             {
                 detail::outerr(actions.filename, pos.line)
                     << "Mismatched sections in template "
@@ -1562,24 +1562,24 @@
         value content = values.consume();
         values.finish();
 
- actions.section_id = !element_id.empty() ?
+ actions.section.id = !element_id.empty() ?
             element_id.get_quickbook() :
             detail::make_identifier(content.get_quickbook());
 
- if (actions.section_level != 0)
- actions.qualified_section_id += '.';
+ if (actions.section.level != 0)
+ actions.section.qualified_id += '.';
         else
- BOOST_ASSERT(actions.qualified_section_id.empty());
+ BOOST_ASSERT(actions.section.qualified_id.empty());
 
- actions.qualified_section_id += actions.section_id;
- ++actions.section_level;
+ actions.section.qualified_id += actions.section.id;
+ ++actions.section.level;
 
         // TODO: This could be awkward if there's a clash, possibly
         // needs another category, between explicit and generated.
         std::string full_id = actions.ids.add(
             qbk_version_n < 103 ?
- actions.doc_id + "." + actions.section_id :
- actions.doc_id + "." + actions.qualified_section_id,
+ actions.doc_id + "." + actions.section.id :
+ actions.doc_id + "." + actions.section.qualified_id,
             !element_id.empty() ?
                 id_generator::explicit_id :
                 id_generator::generated_section);
@@ -1608,7 +1608,7 @@
     {
         write_anchors(actions, actions.out);
 
- if (actions.section_level <= actions.min_section_level)
+ if (actions.section.level <= actions.section.min_level)
         {
             detail::outerr(actions.filename, pos.line)
                 << "Mismatched [endsect] near column " << pos.column << ".\n";
@@ -1617,18 +1617,18 @@
             return;
         }
 
- --actions.section_level;
+ --actions.section.level;
         actions.out << "</section>";
 
- if (actions.section_level == 0)
+ if (actions.section.level == 0)
         {
- actions.qualified_section_id.clear();
+ actions.section.qualified_id.clear();
         }
         else
         {
             std::string::size_type const n =
- actions.qualified_section_id.find_last_of('.');
- actions.qualified_section_id.erase(n, std::string::npos);
+ actions.section.qualified_id.find_last_of('.');
+ actions.section.qualified_id.erase(n, std::string::npos);
         }
     }
     

Modified: branches/quickbook-dev/tools/quickbook/src/actions_class.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions_class.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions_class.cpp 2011-11-02 03:42:37 EDT (Wed, 02 Nov 2011)
@@ -44,10 +44,7 @@
         , filename_relative(filein_.filename())
 
         , template_depth(0)
- , section_level(0)
- , min_section_level(0)
- , section_id()
- , qualified_section_id()
+ , section()
 
         , out(out_)
         , phrase()
@@ -106,7 +103,7 @@
         , filename_relative(a.filename_relative)
         , source_mode(a.source_mode)
         , macro()
- , min_section_level(a.min_section_level)
+ , min_level(a.section.min_level)
     {
         if (scope & scope_macros) macro = a.macro;
         if (scope & scope_templates) a.templates.push();
@@ -133,23 +130,30 @@
         }
         if (scope & scope_templates) a.templates.pop();
         if (scope & scope_macros) a.macro = macro;
- boost::swap(a.min_section_level, min_section_level);
+ boost::swap(a.section.min_level, min_level);
     }
     
     template_state::template_state(actions& a)
         : file_state(a, file_state::scope_all)
         , template_depth(a.template_depth)
- , section_level(a.section_level)
- , section_id(a.section_id)
- , qualified_section_id(a.qualified_section_id)
+ , section(a.section)
     {
     }
 
     template_state::~template_state()
     {
         boost::swap(a.template_depth, template_depth);
- boost::swap(a.section_level, section_level);
- boost::swap(a.section_id, section_id);
- boost::swap(a.qualified_section_id, qualified_section_id);
+ boost::swap(a.section, section);
+ }
+
+ section_info::section_info()
+ : level(0), min_level(0), id(), qualified_id() {}
+
+ void swap(section_info& a, section_info& b)
+ {
+ boost::swap(a.level, b.level);
+ boost::swap(a.min_level, b.min_level);
+ boost::swap(a.id, b.id);
+ boost::swap(a.qualified_id, b.qualified_id);
     }
 }

Modified: branches/quickbook-dev/tools/quickbook/src/actions_class.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions_class.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions_class.hpp 2011-11-02 03:42:37 EDT (Wed, 02 Nov 2011)
@@ -21,6 +21,17 @@
     namespace cl = boost::spirit::classic;
     namespace fs = boost::filesystem;
 
+ struct section_info
+ {
+ section_info();
+
+ int level;
+ int min_level;
+ std::string id;
+ std::string qualified_id;
+ };
+ void swap(section_info&, section_info&);
+
     struct actions
     {
         actions(fs::path const& filein_, fs::path const& xinclude_base, string_stream& out_,
@@ -63,10 +74,7 @@
 
     // state saved for templates.
         int template_depth;
- int section_level;
- int min_section_level;
- std::string section_id;
- std::string qualified_section_id;
+ section_info section;
 
     // output state - scoped by templates and grammar
         collector out; // main output stream
@@ -136,7 +144,9 @@
         fs::path filename_relative;
         std::string source_mode;
         string_symbols macro;
- int min_section_level;
+ // Currently saving this twice for templates...
+ // Will fix that soon.
+ int min_level;
     private:
         file_state(file_state const&);
         file_state& operator=(file_state const&);
@@ -148,9 +158,7 @@
         ~template_state();
 
         int template_depth;
- int section_level;
- std::string section_id;
- std::string qualified_section_id;
+ section_info section;
     };
 }
 

Modified: branches/quickbook-dev/tools/quickbook/src/doc_info_actions.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/doc_info_actions.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/doc_info_actions.cpp 2011-11-02 03:42:37 EDT (Wed, 02 Nov 2011)
@@ -170,7 +170,7 @@
         // Save the section level so it can be checked at the end of the
         // document.
 
- actions.min_section_level = actions.section_level;
+ actions.section.min_level = actions.section.level;
 
         // Quickbook version
 
@@ -465,17 +465,17 @@
         assert(!actions.doc_type.empty());
 
         // Close any open sections.
- if (actions.section_level > actions.min_section_level) {
+ if (actions.section.level > actions.section.min_level) {
             detail::outwarn(actions.filename)
                 << "Missing [endsect] detected at end of file."
                 << std::endl;
 
- while(actions.section_level > actions.min_section_level) {
+ while(actions.section.level > actions.section.min_level) {
                 out << "</section>";
- --actions.section_level;
+ --actions.section.level;
             }
 
- actions.qualified_section_id.clear();
+ actions.section.qualified_id.clear();
         }
 
         // We've finished generating our output. Here's what we'll do

Modified: branches/quickbook-dev/tools/quickbook/src/id_generator.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/id_generator.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/id_generator.hpp 2011-11-02 03:42:37 EDT (Wed, 02 Nov 2011)
@@ -110,4 +110,4 @@
     };
 }
 
-#endif
\ No newline at end of file
+#endif


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