|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r85267 - in trunk/tools/quickbook: src test/include
From: dnljms_at_[hidden]
Date: 2013-08-10 05:06:59
Author: danieljames
Date: 2013-08-10 05:06:59 EDT (Sat, 10 Aug 2013)
New Revision: 85267
URL: http://svn.boost.org/trac/boost/changeset/85267
Log:
Improve the handling of file ids.
Instead of messing around with the section's id, leave it alone and
check for a file id whenever looking up the current id.
Text files modified:
trunk/tools/quickbook/src/id_manager.cpp | 108 +++++++++++++--------------------------
trunk/tools/quickbook/test/include/in_section-1_5.gold | 28 ++++++++++
trunk/tools/quickbook/test/include/in_section-1_6.gold | 24 ++++++++
trunk/tools/quickbook/test/include/in_section-inc1.quickbook | 4 +
trunk/tools/quickbook/test/include/in_section-inc2.quickbook | 4 +
5 files changed, 95 insertions(+), 73 deletions(-)
Modified: trunk/tools/quickbook/src/id_manager.cpp
==============================================================================
--- trunk/tools/quickbook/src/id_manager.cpp Sat Aug 10 05:06:36 2013 (r85266)
+++ trunk/tools/quickbook/src/id_manager.cpp 2013-08-10 05:06:59 EDT (Sat, 10 Aug 2013) (r85267)
@@ -104,6 +104,9 @@
id_placeholder* get_placeholder(boost::string_ref);
+ id_placeholder* get_id_placeholder(
+ boost::shared_ptr<section_info> const& section) const;
+
// Events
id_placeholder* start_file(
@@ -134,11 +137,6 @@
id_placeholder* create_new_section(
boost::string_ref id,
id_category category);
-
- void switch_section(id_placeholder*);
- void reswitch_sections(boost::shared_ptr<section_info> const&,
- boost::shared_ptr<section_info> const&);
- void restore_section();
};
struct file_info
@@ -148,8 +146,9 @@
bool document_root; // !parent || document != parent->document
unsigned compatibility_version;
- boost::shared_ptr<section_info> switched_section;
- id_placeholder* original_placeholder;
+ unsigned depth;
+ unsigned override_depth;
+ id_placeholder* override_id;
// The 1.1-1.5 document id would actually change per file due to
// explicit ids in includes and a bug which would sometimes use the
@@ -160,7 +159,9 @@
unsigned compatibility_version) :
parent(parent), document(parent->document), document_root(false),
compatibility_version(compatibility_version),
- switched_section(), original_placeholder()
+ depth(parent->depth + 1),
+ override_depth(parent->override_depth),
+ override_id(parent->override_id)
{}
file_info(boost::shared_ptr<file_info> const& parent,
@@ -168,7 +169,7 @@
unsigned compatibility_version) :
parent(parent), document(document), document_root(true),
compatibility_version(compatibility_version),
- switched_section(), original_placeholder()
+ depth(0), override_depth(0), override_id(0)
{}
};
@@ -187,13 +188,16 @@
{
boost::shared_ptr<section_info> parent;
unsigned compatibility_version;
+ unsigned file_depth;
unsigned level;
std::string id_1_1;
id_placeholder* placeholder_1_6;
section_info(boost::shared_ptr<section_info> const& parent,
- unsigned compatibility_version, boost::string_ref id) :
- parent(parent), compatibility_version(compatibility_version),
+ file_info const* current_file, boost::string_ref id) :
+ parent(parent),
+ compatibility_version(current_file->compatibility_version),
+ file_depth(current_file->depth),
level(parent ? parent->level + 1 : 1),
id_1_1(), placeholder_1_6(0)
{
@@ -366,46 +370,12 @@
return &placeholders.at(index);
}
- void id_state::switch_section(id_placeholder* p)
+ id_placeholder* id_state::get_id_placeholder(
+ boost::shared_ptr<section_info> const& section) const
{
- assert(!current_file->original_placeholder);
- current_file->switched_section = current_file->document->current_section;
- current_file->original_placeholder = current_file->switched_section->placeholder_1_6;
- current_file->switched_section->placeholder_1_6 = p;
- }
-
- void id_state::reswitch_sections(
- boost::shared_ptr<section_info> const& popped_section,
- boost::shared_ptr<section_info> const& parent_section)
- {
- boost::shared_ptr<file_info> file = current_file;
- boost::shared_ptr<file_info> first_switched_file;
-
- for (;;) {
- if (file->switched_section == popped_section)
- {
- first_switched_file = file;
- file->switched_section = parent_section;
- }
-
- if (file->document_root) break;
- file = file->parent;
- }
-
- if (first_switched_file) {
- first_switched_file->original_placeholder =
- parent_section->placeholder_1_6;
- parent_section->placeholder_1_6 =
- popped_section->placeholder_1_6;
- }
- }
-
- void id_state::restore_section()
- {
- if (current_file->original_placeholder) {
- current_file->switched_section->placeholder_1_6 =
- current_file->original_placeholder;
- }
+ return !section ? 0 :
+ section->file_depth < current_file->override_depth ?
+ current_file->override_id : section->placeholder_1_6;
}
id_placeholder* id_state::start_file(
@@ -437,7 +407,8 @@
if (document_root ||
compatibility_version >= 106u ||
- (parent && parent->compatibility_version >= 106u)) {
+ (parent && parent->compatibility_version >= 106u))
+ {
initial_doc_id = !include_doc_id.empty() ? include_doc_id : id;
}
else {
@@ -479,15 +450,15 @@
}
}
else {
- // If an id was set for the file, then switch the current section
- // with a new section with this id. This will be maintained in
- // 'end_section' if the current section ends, and then the original
- // section restored in 'end_file'
+ // If an id was set for the file, then the file overrides the
+ // current section's id with this id.
if (compatibility_version >= 106u && !initial_doc_id.empty()) {
- switch_section(add_id_to_section(initial_doc_id,
- id_category::explicit_section_id,
- boost::shared_ptr<section_info>()));
+ boost::shared_ptr<section_info> null_section;
+
+ current_file->override_depth = current_file->depth;
+ current_file->override_id = add_id_to_section(initial_doc_id,
+ id_category::explicit_section_id, null_section);
}
return 0;
@@ -496,7 +467,6 @@
void id_state::end_file()
{
- restore_section();
current_file = current_file->parent;
}
@@ -523,23 +493,23 @@
id_part = normalize_id(id);
}
+ id_placeholder* placeholder_1_6 = get_id_placeholder(section);
+
if(!section || section->compatibility_version >= 106u) {
- return add_placeholder(id_part, category,
- section ? section->placeholder_1_6 : 0);
+ return add_placeholder(id_part, category, placeholder_1_6);
}
else {
std::string const& qualified_id = section->id_1_1;
std::string new_id;
- if (!section->placeholder_1_6)
+ if (!placeholder_1_6)
new_id = current_file->doc_id_1_1;
if (!new_id.empty() && !qualified_id.empty()) new_id += '.';
new_id += qualified_id;
if (!new_id.empty() && !id_part.empty()) new_id += '.';
new_id += id_part;
- return add_placeholder(new_id, category,
- section->placeholder_1_6);
+ return add_placeholder(new_id, category, placeholder_1_6);
}
}
@@ -570,7 +540,7 @@
boost::shared_ptr<section_info> new_section =
boost::make_shared<section_info>(parent,
- current_file->compatibility_version, id);
+ current_file.get(), id);
id_placeholder* p;
@@ -579,8 +549,7 @@
new_section->placeholder_1_6 = p;
}
else if (new_section->compatibility_version >= 103u) {
- if (parent)
- new_section->placeholder_1_6 = parent->placeholder_1_6;
+ new_section->placeholder_1_6 = get_id_placeholder(parent);
std::string new_id;
if (!new_section->placeholder_1_6) {
@@ -593,8 +562,7 @@
new_section->placeholder_1_6);
}
else {
- if (parent)
- new_section->placeholder_1_6 = parent->placeholder_1_6;
+ new_section->placeholder_1_6 = get_id_placeholder(parent);
std::string new_id;
if (parent && !new_section->placeholder_1_6)
@@ -616,8 +584,6 @@
boost::shared_ptr<section_info> popped_section =
current_file->document->current_section;
current_file->document->current_section = popped_section->parent;
-
- reswitch_sections(popped_section, popped_section->parent);
}
//
Modified: trunk/tools/quickbook/test/include/in_section-1_5.gold
==============================================================================
--- trunk/tools/quickbook/test/include/in_section-1_5.gold Sat Aug 10 05:06:36 2013 (r85266)
+++ trunk/tools/quickbook/test/include/in_section-1_5.gold 2013-08-10 05:06:59 EDT (Sat, 10 Aug 2013) (r85267)
@@ -13,6 +13,11 @@
<bridgehead renderas="sect1" id="include_in_section_include_1.container.inner.h0">
<phrase id="include_in_section_include_1.container.inner.test2"/><link linkend="include_in_section_include_1.container.inner.test2">Test2</link>
</bridgehead>
+ <bridgehead renderas="sect4" id="include_in_section_include_1.container.inner.h1">
+ <phrase id="include_in_section_include_1.container.inner.simple_include"/><link
+ linkend="include_in_section_include_1.container.inner.simple_include">Simple
+ include</link>
+ </bridgehead>
</section>
<bridgehead renderas="sect1" id="section_include.container.h0">
<phrase id="section_include.container.test1"/><link linkend="section_include.container.test1">Test1</link>
@@ -22,6 +27,11 @@
<bridgehead renderas="sect1" id="section_include.container.inner.h0">
<phrase id="section_include.container.inner.test2"/><link linkend="section_include.container.inner.test2">Test2</link>
</bridgehead>
+ <bridgehead renderas="sect4" id="include_in_section_include_2.container.inner.h0">
+ <phrase id="include_in_section_include_2.container.inner.simple_include"/><link
+ linkend="include_in_section_include_2.container.inner.simple_include">Simple
+ include</link>
+ </bridgehead>
</section>
</section>
<bridgehead renderas="sect1" id="include_in_section_include_1.h0">
@@ -32,6 +42,10 @@
<bridgehead renderas="sect1" id="include_in_section_include_1.inner.h0">
<phrase id="include_in_section_include_1.inner.test2"/><link linkend="include_in_section_include_1.inner.test2">Test2</link>
</bridgehead>
+ <bridgehead renderas="sect3" id="include_in_section_include_1.inner.h1">
+ <phrase id="include_in_section_include_1.inner.simple_include"/><link linkend="include_in_section_include_1.inner.simple_include">Simple
+ include</link>
+ </bridgehead>
</section>
<bridgehead renderas="sect1" id="section_include.h0">
<phrase id="section_include.test1"/><link linkend="section_include.test1">Test1</link>
@@ -41,6 +55,10 @@
<bridgehead renderas="sect1" id="section_include.inner.h0">
<phrase id="section_include.inner.test2"/><link linkend="section_include.inner.test2">Test2</link>
</bridgehead>
+ <bridgehead renderas="sect3" id="include_in_section_include_2.inner.h0">
+ <phrase id="include_in_section_include_2.inner.simple_include"/><link linkend="include_in_section_include_2.inner.simple_include">Simple
+ include</link>
+ </bridgehead>
</section>
<section id="include_in_section_1_5.container2">
<title><link linkend="include_in_section_1_5.container2">Container2</link></title>
@@ -52,6 +70,11 @@
<bridgehead renderas="sect1" id="include_in_section_include_1.container2.inner.h0">
<phrase id="include_in_section_include_1.container2.inner.test2"/><link linkend="include_in_section_include_1.container2.inner.test2">Test2</link>
</bridgehead>
+ <bridgehead renderas="sect4" id="include_in_section_include_1.container2.inner.h1">
+ <phrase id="include_in_section_include_1.container2.inner.simple_include"/><link
+ linkend="include_in_section_include_1.container2.inner.simple_include">Simple
+ include</link>
+ </bridgehead>
</section>
<bridgehead renderas="sect1" id="section_include.container2.h0">
<phrase id="section_include.container2.test1"/><link linkend="section_include.container2.test1">Test1</link>
@@ -61,6 +84,11 @@
<bridgehead renderas="sect1" id="section_include.container2.inner.h0">
<phrase id="section_include.container2.inner.test2"/><link linkend="section_include.container2.inner.test2">Test2</link>
</bridgehead>
+ <bridgehead renderas="sect4" id="include_in_section_include_2.container2.inner.h0">
+ <phrase id="include_in_section_include_2.container2.inner.simple_include"/><link
+ linkend="include_in_section_include_2.container2.inner.simple_include">Simple
+ include</link>
+ </bridgehead>
</section>
</section>
</article>
Modified: trunk/tools/quickbook/test/include/in_section-1_6.gold
==============================================================================
--- trunk/tools/quickbook/test/include/in_section-1_6.gold Sat Aug 10 05:06:36 2013 (r85266)
+++ trunk/tools/quickbook/test/include/in_section-1_6.gold 2013-08-10 05:06:59 EDT (Sat, 10 Aug 2013) (r85267)
@@ -16,6 +16,10 @@
<bridgehead renderas="sect1" id="include_in_section_include_1.inner.h0">
<phrase id="include_in_section_include_1.inner.test2"/><link linkend="include_in_section_include_1.inner.test2">Test2</link>
</bridgehead>
+ <bridgehead renderas="sect3" id="include_in_section_include_1.inner.h1">
+ <phrase id="include_in_section_include_1.inner.simple_include"/><link linkend="include_in_section_include_1.inner.simple_include">Simple
+ include</link>
+ </bridgehead>
</section>
</article>
<article id="section_include" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
@@ -29,6 +33,10 @@
<bridgehead renderas="sect1" id="section_include.inner.h0">
<phrase id="section_include.inner.test2"/><link linkend="section_include.inner.test2">Test2</link>
</bridgehead>
+ <bridgehead renderas="sect3" id="section_include.inner.h1">
+ <phrase id="section_include.inner.simple_include"/><link linkend="section_include.inner.simple_include">Simple
+ include</link>
+ </bridgehead>
</section>
</article>
</section>
@@ -43,6 +51,10 @@
<bridgehead renderas="sect1" id="include_in_section_include_1_0.inner.h0">
<phrase id="include_in_section_include_1_0.inner.test2"/><link linkend="include_in_section_include_1_0.inner.test2">Test2</link>
</bridgehead>
+ <bridgehead renderas="sect3" id="include_in_section_include_1_0.inner.h1">
+ <phrase id="include_in_section_include_1_0.inner.simple_include"/><link linkend="include_in_section_include_1_0.inner.simple_include">Simple
+ include</link>
+ </bridgehead>
</section>
</article>
<article id="section_include0" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
@@ -56,6 +68,10 @@
<bridgehead renderas="sect1" id="section_include0.inner.h0">
<phrase id="section_include0.inner.test2"/><link linkend="section_include0.inner.test2">Test2</link>
</bridgehead>
+ <bridgehead renderas="sect3" id="section_include0.inner.h1">
+ <phrase id="section_include0.inner.simple_include"/><link linkend="section_include0.inner.simple_include">Simple
+ include</link>
+ </bridgehead>
</section>
</article>
<section id="include_in_section_1_6.container2">
@@ -71,6 +87,10 @@
<bridgehead renderas="sect1" id="include_in_section_include_1_1.inner.h0">
<phrase id="include_in_section_include_1_1.inner.test2"/><link linkend="include_in_section_include_1_1.inner.test2">Test2</link>
</bridgehead>
+ <bridgehead renderas="sect3" id="include_in_section_include_1_1.inner.h1">
+ <phrase id="include_in_section_include_1_1.inner.simple_include"/><link
+ linkend="include_in_section_include_1_1.inner.simple_include">Simple include</link>
+ </bridgehead>
</section>
</article>
<article id="section_include1" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
@@ -84,6 +104,10 @@
<bridgehead renderas="sect1" id="section_include1.inner.h0">
<phrase id="section_include1.inner.test2"/><link linkend="section_include1.inner.test2">Test2</link>
</bridgehead>
+ <bridgehead renderas="sect3" id="section_include1.inner.h1">
+ <phrase id="section_include1.inner.simple_include"/><link linkend="section_include1.inner.simple_include">Simple
+ include</link>
+ </bridgehead>
</section>
</article>
</section>
Modified: trunk/tools/quickbook/test/include/in_section-inc1.quickbook
==============================================================================
--- trunk/tools/quickbook/test/include/in_section-inc1.quickbook Sat Aug 10 05:06:36 2013 (r85266)
+++ trunk/tools/quickbook/test/include/in_section-inc1.quickbook 2013-08-10 05:06:59 EDT (Sat, 10 Aug 2013) (r85267)
@@ -8,4 +8,6 @@
[h1 Test2]
-[endsect]
\ No newline at end of file
+[include include-id-inc1.quickbook]
+
+[endsect]
Modified: trunk/tools/quickbook/test/include/in_section-inc2.quickbook
==============================================================================
--- trunk/tools/quickbook/test/include/in_section-inc2.quickbook Sat Aug 10 05:06:36 2013 (r85266)
+++ trunk/tools/quickbook/test/include/in_section-inc2.quickbook 2013-08-10 05:06:59 EDT (Sat, 10 Aug 2013) (r85267)
@@ -9,4 +9,6 @@
[h1 Test2]
-[endsect]
\ No newline at end of file
+[include include-id-inc1.quickbook]
+
+[endsect]
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