Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75250 - branches/quickbook-dev/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-11-02 03:45:04


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

Log:
Quickbook: Sort a placeholder for doc_id.
Text files modified:
   branches/quickbook-dev/tools/quickbook/src/doc_info_actions.cpp | 47 ++++++++++++------------
   branches/quickbook-dev/tools/quickbook/src/id_generator.cpp | 76 +++++++++++++++++++++++++++++++++++++--
   branches/quickbook-dev/tools/quickbook/src/id_generator.hpp | 24 ++++++++++--
   branches/quickbook-dev/tools/quickbook/src/quickbook.cpp | 13 +-----
   4 files changed, 118 insertions(+), 42 deletions(-)

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:45:03 EDT (Wed, 02 Nov 2011)
@@ -128,33 +128,36 @@
                 ;
         }
 
- bool generated_id = false;
+ std::string id_placeholder;
 
         // Note: this is the version number of the parent document.
         if (qbk_version_n >= 106)
         {
             if (!include_doc_id.empty())
- actions.section->doc_id = include_doc_id.get_quickbook();
+ id_placeholder = actions.section->set_doc_id(actions.ids,
+ include_doc_id.get_quickbook(), id_generator::explicit_id);
             else if (!id.empty())
- actions.section->doc_id = id.get_quickbook();
- else if (docinfo_type) {
- actions.section->doc_id = detail::make_identifier(actions.doc_title_qbk);
- generated_id = true;
- }
- else {
+ id_placeholder = actions.section->set_doc_id(actions.ids,
+ id.get_quickbook(), id_generator::explicit_id);
+ else if (docinfo_type)
+ id_placeholder = actions.section->set_doc_id(actions.ids,
+ detail::make_identifier(actions.doc_title_qbk),
+ id_generator::generated_doc);
+ else
                 assert(!actions.section->doc_id.empty());
- }
         }
         else
         {
             if (!id.empty())
- actions.section->doc_id = id.get_quickbook();
+ id_placeholder = actions.section->set_doc_id(actions.ids,
+ id.get_quickbook(), id_generator::explicit_id);
             else if (!include_doc_id.empty())
- actions.section->doc_id = include_doc_id.get_quickbook();
- else {
- actions.section->doc_id = detail::make_identifier(actions.doc_title_qbk);
- generated_id = true;
- }
+ id_placeholder = actions.section->set_doc_id(actions.ids,
+ include_doc_id.get_quickbook(), id_generator::explicit_id);
+ else
+ id_placeholder = actions.section->set_doc_id(actions.ids,
+ detail::make_identifier(actions.doc_title_qbk),
+ id_generator::generated_doc);
         }
 
         // if we're ignoring the document info, we're done.
@@ -165,8 +168,9 @@
         }
         
         // Make sure we really did have a document info block.
-
- assert(doc_title.check() && !actions.doc_type.empty());
+
+ assert(doc_title.check() && !actions.doc_type.empty() &&
+ !id_placeholder.empty());
 
         // Save the section level so it can be checked at the end of the
         // document.
@@ -294,12 +298,9 @@
 
         out << '<' << actions.doc_type << "\n"
             << " id=\""
- << actions.section->fully_qualified_id(actions.ids,
- std::string(), generated_id ?
- id_generator::generated_doc : id_generator::explicit_id)
- << "\"\n"
- ;
-
+ << id_placeholder
+ << "\"\n";
+
         if(!lang.empty())
         {
             out << " lang=\""

Modified: branches/quickbook-dev/tools/quickbook/src/id_generator.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/id_generator.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/id_generator.cpp 2011-11-02 03:45:03 EDT (Wed, 02 Nov 2011)
@@ -118,6 +118,33 @@
     {
     }
 
+ id_generator::placeholder id_generator::add_placeholder(
+ std::string const& value,
+ id_generator::categories category)
+ {
+ std::string result;
+
+ id_data& data = ids.emplace(boost::unordered::piecewise_construct,
+ boost::make_tuple(value),
+ boost::make_tuple(value, category)).first->second;
+
+ // Doesn't check if explicit ids collide, could probably be a warning.
+ if (category == explicit_id)
+ {
+ data.category = category;
+ data.used = true;
+ }
+ else
+ {
+ if (category < data.category) data.category = category;
+ }
+
+ placeholder p(placeholders.size());
+ placeholders.push_back(placeholder_id(category, &data));
+
+ return p;
+ }
+
     std::string id_generator::add(
             std::string const& value,
             id_generator::categories category)
@@ -138,11 +165,8 @@
         else
         {
             if (category < data.category) data.category = category;
-
- // '$' can't appear in quickbook ids, so use it indicate a
- // placeholder id.
- result = "$" +
- boost::lexical_cast<std::string>(placeholders.size());
+ placeholder p(placeholders.size());
+ result = p.to_string();
             placeholders.push_back(placeholder_id(category, &data));
         }
 
@@ -270,12 +294,28 @@
         return insert.second;
     }
 
+ id_generator::placeholder_id::placeholder_id(
+ id_generator::categories category, id_data* data)
+ : category(category),
+ data(data),
+ final_id()
+ {
+ if (category == explicit_id)
+ final_id = data->name;
+ }
+
     void id_generator::id_generation_data::new_base_value() {
         count = 0;
         needs_underscore = !base.empty() &&
             std::isdigit(base[base.length() - 1]);
     }
 
+ std::string id_generator::placeholder::to_string() const {
+ // '$' can't appear in quickbook ids, so use it indicate a
+ // placeholder id.
+ return "$" + boost::lexical_cast<std::string>(index);
+ }
+
     // Very simple xml subset parser which replaces id values.
     //
     // I originally tried to integrate this into the post processor
@@ -458,6 +498,16 @@
     section_info::section_info()
         : level(0), min_level(0), doc_id(), id(), qualified_id() {}
 
+ std::string section_info::set_doc_id(
+ id_generator& ids,
+ std::string const& new_doc_id,
+ id_generator::categories category)
+ {
+ doc_id = new_doc_id;
+ parent_placeholder = ids.add_placeholder(new_doc_id, category);
+ return parent_placeholder.to_string();
+ }
+
     std::string section_info::old_style_id(
             id_generator& ids,
             std::string const& id_part,
@@ -522,6 +572,22 @@
         }
     }
 
+ void section_info::clear_section()
+ {
+ level = 0;
+ min_level = 0;
+ id.clear();
+ qualified_id.clear();
+ }
+
+ void section_info::copy_section(section_info const& x)
+ {
+ level = x.level;
+ min_level = x.min_level;
+ id = x.id;
+ qualified_id = x.qualified_id;
+ }
+
     void swap(section_info& a, section_info& b)
     {
         boost::swap(a.level, b.level);

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:45:03 EDT (Wed, 02 Nov 2011)
@@ -42,10 +42,7 @@
 
         struct placeholder_id
         {
- placeholder_id(id_generator::categories category, id_data* data)
- : category(category),
- data(data),
- final_id() {}
+ placeholder_id(id_generator::categories, id_data*);
 
             id_generator::categories category;
             id_data* data;
@@ -92,9 +89,20 @@
         std::deque<placeholder_id> placeholders;
 
     public:
+ struct placeholder
+ {
+ private:
+ int index;
+ public:
+ placeholder(int index = -1) : index(index) {}
+ std::string to_string() const;
+ bool check() const { return index != -1; }
+ };
+
         id_generator();
         ~id_generator();
 
+ placeholder add_placeholder(std::string const& id, categories priority);
         std::string add(std::string const& id, categories priority);
 
         std::string replace_placeholders(std::string const&);
@@ -113,6 +121,10 @@
     {
         section_info();
 
+ std::string set_doc_id(
+ id_generator&,
+ std::string const&,
+ id_generator::categories);
         std::string old_style_id(
                 id_generator&,
                 std::string const&,
@@ -127,12 +139,16 @@
                 std::string const&,
                 id_generator::categories);
         void end_section();
+ void clear_section();
+ void copy_section(section_info const&);
 
         int level;
         int min_level;
         std::string doc_id;
         std::string id;
         std::string qualified_id;
+ id_generator::placeholder
+ parent_placeholder;
     };
 
     void swap(section_info&, section_info&);

Modified: branches/quickbook-dev/tools/quickbook/src/quickbook.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/quickbook.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/quickbook.cpp 2011-11-02 03:45:03 EDT (Wed, 02 Nov 2011)
@@ -99,11 +99,8 @@
         section_info* saved_section = &section;
         boost::swap(saved_section, actor.section);
 
- if (saved_section) {
- if (!docinfo_type) section = *saved_section;
- else section.doc_id = saved_section->doc_id;
- }
-
+ if (saved_section) section = *saved_section;
+ if (docinfo_type) section.clear_section();
 
         if (info.hit || !docinfo_type)
         {
@@ -118,11 +115,7 @@
 
         // If this is not a nested document then we want to keep
         // the current section state.
- if (saved_section && !docinfo_type) {
- saved_section->level = section.level;
- saved_section->id = section.id;
- saved_section->qualified_id = section.qualified_id;
- }
+ if (!docinfo_type) saved_section->copy_section(section);
         boost::swap(saved_section, actor.section);
 
         if (!info.full)


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