|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r59670 - branches/quickbook-1.5-spirit2
From: daniel_james_at_[hidden]
Date: 2010-02-13 10:04:23
Author: danieljames
Date: 2010-02-13 10:04:22 EST (Sat, 13 Feb 2010)
New Revision: 59670
URL: http://svn.boost.org/trac/boost/changeset/59670
Log:
Allow the encoders to store state.
Text files modified:
branches/quickbook-1.5-spirit2/boostbook.cpp | 58 +++++++++++++--------
branches/quickbook-1.5-spirit2/encoder.hpp | 50 +++++++++---------
branches/quickbook-1.5-spirit2/encoder_impl.hpp | 104 ++++++++++++++++++++--------------------
branches/quickbook-1.5-spirit2/html.cpp | 58 +++++++++++++--------
4 files changed, 147 insertions(+), 123 deletions(-)
Modified: branches/quickbook-1.5-spirit2/boostbook.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/boostbook.cpp (original)
+++ branches/quickbook-1.5-spirit2/boostbook.cpp 2010-02-13 10:04:22 EST (Sat, 13 Feb 2010)
@@ -23,17 +23,20 @@
return r;
}
- std::string boostbook_encoder::encode(std::string const& x) const {
+ std::string boostbook_encoder::encode(std::string const& x)
+ {
return encode_impl(x.begin(), x.end());
}
- std::string boostbook_encoder::encode(char const* x) const {
+ std::string boostbook_encoder::encode(char const* x)
+ {
char const* end = x;
while(*end) ++end;
return encode_impl(x, end);
}
- std::string boostbook_encoder::encode(char c) const {
+ std::string boostbook_encoder::encode(char c)
+ {
return encode_impl(&c, &c + 1);
}
@@ -105,23 +108,25 @@
} initialize_instance;
}
- void boostbook_encoder::operator()(quickbook::state& state, std::string const& x) const
+ void boostbook_encoder::operator()(quickbook::state& state, std::string const& x)
{
state.phrase << x;
}
- void boostbook_encoder::operator()(quickbook::state& state, char x) const
+ void boostbook_encoder::operator()(quickbook::state& state, char x)
{
state.phrase << encode(x);
}
- void boostbook_encoder::operator()(quickbook::state& state, anchor const& x) const {
+ void boostbook_encoder::operator()(quickbook::state& state, anchor const& x)
+ {
state.phrase << "<anchor id=\"";
state.phrase << encode(x.id);
state.phrase << "\"/>\n";
}
- void boostbook_encoder::operator()(quickbook::state& state, link const& x) const {
+ void boostbook_encoder::operator()(quickbook::state& state, link const& x)
+ {
boostbook_markup m = markup_map.at(x.type);
state.phrase << m.pre;
state.phrase << encode(x.destination);
@@ -130,17 +135,20 @@
state.phrase << m.post;
}
- void boostbook_encoder::operator()(quickbook::state& state, formatted const& x) const {
+ void boostbook_encoder::operator()(quickbook::state& state, formatted const& x)
+ {
boostbook_markup m = markup_map.at(x.type);
state.phrase << m.pre << x.content << m.post;
}
- void boostbook_encoder::operator()(quickbook::state& state, break_ const& x) const {
+ void boostbook_encoder::operator()(quickbook::state& state, break_ const& x)
+ {
boostbook_markup m = markup_map.at("break");
state.phrase << m.pre;
}
- void boostbook_encoder::operator()(quickbook::state& state, image2 const& x) const {
+ void boostbook_encoder::operator()(quickbook::state& state, image2 const& x)
+ {
state.phrase << "<inlinemediaobject>";
state.phrase << "<imageobject><imagedata";
@@ -173,11 +181,13 @@
state.phrase << "</inlinemediaobject>";
}
- void boostbook_encoder::operator()(quickbook::state& state, hr) const {
+ void boostbook_encoder::operator()(quickbook::state& state, hr)
+ {
state.phrase << markup_map.at("hr").pre;
}
- void boostbook_encoder::operator()(quickbook::state& state, begin_section2 const& x) const {
+ void boostbook_encoder::operator()(quickbook::state& state, begin_section2 const& x)
+ {
state.phrase << "\n<section id=\"" << x.id << "\">\n";
if(x.linkend.empty()) {
state.phrase
@@ -199,11 +209,13 @@
}
}
- void boostbook_encoder::operator()(quickbook::state& state, end_section2 const& x) const {
+ void boostbook_encoder::operator()(quickbook::state& state, end_section2 const& x)
+ {
state.phrase << "</section>";
}
- void boostbook_encoder::operator()(quickbook::state& state, heading2 const& x) const {
+ void boostbook_encoder::operator()(quickbook::state& state, heading2 const& x)
+ {
state.phrase
<< "<anchor id=\"" << x.id << "\"/>"
<< "<bridgehead renderas=\"sect" << x.level << "\">";
@@ -220,7 +232,7 @@
state.phrase << "</bridgehead>";
}
- void boostbook_encoder::operator()(quickbook::state& state, variablelist const& x) const
+ void boostbook_encoder::operator()(quickbook::state& state, variablelist const& x)
{
state.phrase << "<variablelist>\n";
@@ -241,7 +253,7 @@
state.phrase << "</variablelist>\n";
}
- void boostbook_encoder::operator()(quickbook::state& state, table2 const& x) const
+ void boostbook_encoder::operator()(quickbook::state& state, table2 const& x)
{
if (x.title)
{
@@ -298,12 +310,12 @@
}
}
- void boostbook_encoder::operator()(quickbook::state& state, xinclude2 const& x) const
+ void boostbook_encoder::operator()(quickbook::state& state, xinclude2 const& x)
{
state.phrase << "\n<xi:include href=\"" << x.path << "\" />\n";
}
- void boostbook_encoder::operator()(quickbook::state& state, list2 const& x) const
+ void boostbook_encoder::operator()(quickbook::state& state, list2 const& x)
{
state.phrase << std::string(x.mark == '#' ? "<orderedlist>\n" : "<itemizedlist>\n");
@@ -318,7 +330,7 @@
state.phrase << std::string(x.mark == '#' ? "\n</orderedlist>" : "\n</itemizedlist>");
}
- void boostbook_encoder::operator()(quickbook::state& state, callout_link const& x) const
+ void boostbook_encoder::operator()(quickbook::state& state, callout_link const& x)
{
state.phrase
<< "<phrase role=\"" << x.role << "\">"
@@ -328,7 +340,7 @@
<< "</phrase>";
}
- void boostbook_encoder::operator()(quickbook::state& state, callout_list const& x) const
+ void boostbook_encoder::operator()(quickbook::state& state, callout_list const& x)
{
state.phrase
<< "<calloutlist>";
@@ -347,7 +359,7 @@
<< "</calloutlist>";
}
- void boostbook_encoder::operator()(quickbook::state& state, code_token const& x) const
+ void boostbook_encoder::operator()(quickbook::state& state, code_token const& x)
{
std::string type = x.type;
if(type == "space") {
@@ -361,7 +373,7 @@
}
}
- void boostbook_encoder::operator()(quickbook::state& state, doc_info const& info) const
+ void boostbook_encoder::operator()(quickbook::state& state, doc_info const& info)
{
// if we're ignoring the document info, we're done.
if (info.ignore) return;
@@ -478,7 +490,7 @@
if(info.doc_type == "library") state.phrase << title;
}
- void boostbook_encoder::operator()(quickbook::state& state, doc_info_post const& x) const
+ void boostbook_encoder::operator()(quickbook::state& state, doc_info_post const& x)
{
// if we're ignoring the document info, do nothing.
if (x.info.ignore) return;
Modified: branches/quickbook-1.5-spirit2/encoder.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/encoder.hpp (original)
+++ branches/quickbook-1.5-spirit2/encoder.hpp 2010-02-13 10:04:22 EST (Sat, 13 Feb 2010)
@@ -34,41 +34,41 @@
struct encoder {
void operator()(quickbook::state&, nothing) {}
- virtual void operator()(quickbook::state&, doc_info const&) const = 0;
- virtual void operator()(quickbook::state&, doc_info_post const&) const = 0;
+ virtual void operator()(quickbook::state&, doc_info const&) = 0;
+ virtual void operator()(quickbook::state&, doc_info_post const&) = 0;
// Note: char is a plain quickbook character, string is an encoded
// boostbook string. Oops.
- virtual void operator()(quickbook::state&, char) const = 0;
- virtual void operator()(quickbook::state&, std::string const&) const = 0;
- virtual void operator()(quickbook::state&, anchor const&) const = 0;
- virtual void operator()(quickbook::state&, link const&) const = 0;
- virtual void operator()(quickbook::state&, formatted const&) const = 0;
- virtual void operator()(quickbook::state&, break_ const&) const = 0;
- virtual void operator()(quickbook::state&, image2 const&) const = 0;
+ virtual void operator()(quickbook::state&, char) = 0;
+ virtual void operator()(quickbook::state&, std::string const&) = 0;
+ virtual void operator()(quickbook::state&, anchor const&) = 0;
+ virtual void operator()(quickbook::state&, link const&) = 0;
+ virtual void operator()(quickbook::state&, formatted const&) = 0;
+ virtual void operator()(quickbook::state&, break_ const&) = 0;
+ virtual void operator()(quickbook::state&, image2 const&) = 0;
- virtual void operator()(quickbook::state&, hr) const = 0;
- virtual void operator()(quickbook::state&, begin_section2 const&) const = 0;
- virtual void operator()(quickbook::state&, end_section2 const&) const = 0;
- virtual void operator()(quickbook::state&, heading2 const&) const = 0;
- virtual void operator()(quickbook::state&, variablelist const&) const = 0;
- virtual void operator()(quickbook::state&, table2 const&) const = 0;
- virtual void operator()(quickbook::state&, xinclude2 const&) const = 0;
- virtual void operator()(quickbook::state&, list2 const&) const = 0;
- virtual void operator()(quickbook::state&, callout_link const&) const = 0;
- virtual void operator()(quickbook::state&, callout_list const&) const = 0;
+ virtual void operator()(quickbook::state&, hr) = 0;
+ virtual void operator()(quickbook::state&, begin_section2 const&) = 0;
+ virtual void operator()(quickbook::state&, end_section2 const&) = 0;
+ virtual void operator()(quickbook::state&, heading2 const&) = 0;
+ virtual void operator()(quickbook::state&, variablelist const&) = 0;
+ virtual void operator()(quickbook::state&, table2 const&) = 0;
+ virtual void operator()(quickbook::state&, xinclude2 const&) = 0;
+ virtual void operator()(quickbook::state&, list2 const&) = 0;
+ virtual void operator()(quickbook::state&, callout_link const&) = 0;
+ virtual void operator()(quickbook::state&, callout_list const&) = 0;
- virtual void operator()(quickbook::state&, code_token const&) const = 0;
+ virtual void operator()(quickbook::state&, code_token const&) = 0;
- virtual std::string encode(std::string const&) const = 0;
- virtual std::string encode(char) const = 0;
- virtual std::string encode(char const*) const = 0;
+ virtual std::string encode(std::string const&) = 0;
+ virtual std::string encode(char) = 0;
+ virtual std::string encode(char const*) = 0;
};
struct encode_action
{
encode_action(quickbook::state& state,
- quickbook::encoder const& encoder)
+ quickbook::encoder& encoder)
: state(state), encoder(encoder) {}
template <typename T>
@@ -77,7 +77,7 @@
}
quickbook::state& state;
- quickbook::encoder const& encoder;
+ quickbook::encoder& encoder;
};
}
Modified: branches/quickbook-1.5-spirit2/encoder_impl.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/encoder_impl.hpp (original)
+++ branches/quickbook-1.5-spirit2/encoder_impl.hpp 2010-02-13 10:04:22 EST (Sat, 13 Feb 2010)
@@ -6,66 +6,66 @@
namespace quickbook
{
struct boostbook_encoder : encoder {
- virtual void operator()(quickbook::state&, doc_info const&) const;
- virtual void operator()(quickbook::state&, doc_info_post const&) const;
+ virtual void operator()(quickbook::state&, doc_info const&);
+ virtual void operator()(quickbook::state&, doc_info_post const&);
// Note: char is a plain quickbook character, string is an encoded
// boostbook string. Oops.
- virtual void operator()(quickbook::state&, char) const;
- virtual void operator()(quickbook::state&, std::string const&) const;
- virtual void operator()(quickbook::state&, anchor const&) const;
- virtual void operator()(quickbook::state&, link const&) const;
- virtual void operator()(quickbook::state&, formatted const&) const;
- virtual void operator()(quickbook::state&, break_ const&) const;
- virtual void operator()(quickbook::state&, image2 const&) const;
-
- virtual void operator()(quickbook::state&, hr) const;
- virtual void operator()(quickbook::state&, begin_section2 const&) const;
- virtual void operator()(quickbook::state&, end_section2 const&) const;
- virtual void operator()(quickbook::state&, heading2 const&) const;
- virtual void operator()(quickbook::state&, variablelist const&) const;
- virtual void operator()(quickbook::state&, table2 const&) const;
- virtual void operator()(quickbook::state&, xinclude2 const&) const;
- virtual void operator()(quickbook::state&, list2 const&) const;
- virtual void operator()(quickbook::state&, callout_link const&) const;
- virtual void operator()(quickbook::state&, callout_list const&) const;
-
- virtual void operator()(quickbook::state&, code_token const&) const;
-
- virtual std::string encode(std::string const&) const;
- virtual std::string encode(char) const;
- virtual std::string encode(char const*) const;
+ virtual void operator()(quickbook::state&, char);
+ virtual void operator()(quickbook::state&, std::string const&);
+ virtual void operator()(quickbook::state&, anchor const&);
+ virtual void operator()(quickbook::state&, link const&);
+ virtual void operator()(quickbook::state&, formatted const&);
+ virtual void operator()(quickbook::state&, break_ const&);
+ virtual void operator()(quickbook::state&, image2 const&);
+
+ virtual void operator()(quickbook::state&, hr);
+ virtual void operator()(quickbook::state&, begin_section2 const&);
+ virtual void operator()(quickbook::state&, end_section2 const&);
+ virtual void operator()(quickbook::state&, heading2 const&);
+ virtual void operator()(quickbook::state&, variablelist const&);
+ virtual void operator()(quickbook::state&, table2 const&);
+ virtual void operator()(quickbook::state&, xinclude2 const&);
+ virtual void operator()(quickbook::state&, list2 const&);
+ virtual void operator()(quickbook::state&, callout_link const&);
+ virtual void operator()(quickbook::state&, callout_list const&);
+
+ virtual void operator()(quickbook::state&, code_token const&);
+
+ virtual std::string encode(std::string const&);
+ virtual std::string encode(char);
+ virtual std::string encode(char const*);
};
struct html_encoder : encoder {
- virtual void operator()(quickbook::state&, doc_info const&) const;
- virtual void operator()(quickbook::state&, doc_info_post const&) const;
+ virtual void operator()(quickbook::state&, doc_info const&);
+ virtual void operator()(quickbook::state&, doc_info_post const&);
// Note: char is a plain quickbook character, string is an encoded
// html string. Oops.
- virtual void operator()(quickbook::state&, char) const;
- virtual void operator()(quickbook::state&, std::string const&) const;
- virtual void operator()(quickbook::state&, anchor const&) const;
- virtual void operator()(quickbook::state&, link const&) const;
- virtual void operator()(quickbook::state&, formatted const&) const;
- virtual void operator()(quickbook::state&, break_ const&) const;
- virtual void operator()(quickbook::state&, image2 const&) const;
-
- virtual void operator()(quickbook::state&, hr) const;
- virtual void operator()(quickbook::state&, begin_section2 const&) const;
- virtual void operator()(quickbook::state&, end_section2 const&) const;
- virtual void operator()(quickbook::state&, heading2 const&) const;
- virtual void operator()(quickbook::state&, variablelist const&) const;
- virtual void operator()(quickbook::state&, table2 const&) const;
- virtual void operator()(quickbook::state&, xinclude2 const&) const;
- virtual void operator()(quickbook::state&, list2 const&) const;
- virtual void operator()(quickbook::state&, callout_link const&) const;
- virtual void operator()(quickbook::state&, callout_list const&) const;
-
- virtual void operator()(quickbook::state&, code_token const&) const;
-
- virtual std::string encode(std::string const&) const;
- virtual std::string encode(char) const;
- virtual std::string encode(char const*) const;
+ virtual void operator()(quickbook::state&, char);
+ virtual void operator()(quickbook::state&, std::string const&);
+ virtual void operator()(quickbook::state&, anchor const&);
+ virtual void operator()(quickbook::state&, link const&);
+ virtual void operator()(quickbook::state&, formatted const&);
+ virtual void operator()(quickbook::state&, break_ const&);
+ virtual void operator()(quickbook::state&, image2 const&);
+
+ virtual void operator()(quickbook::state&, hr);
+ virtual void operator()(quickbook::state&, begin_section2 const&);
+ virtual void operator()(quickbook::state&, end_section2 const&);
+ virtual void operator()(quickbook::state&, heading2 const&);
+ virtual void operator()(quickbook::state&, variablelist const&);
+ virtual void operator()(quickbook::state&, table2 const&);
+ virtual void operator()(quickbook::state&, xinclude2 const&);
+ virtual void operator()(quickbook::state&, list2 const&);
+ virtual void operator()(quickbook::state&, callout_link const&);
+ virtual void operator()(quickbook::state&, callout_list const&);
+
+ virtual void operator()(quickbook::state&, code_token const&);
+
+ virtual std::string encode(std::string const&);
+ virtual std::string encode(char);
+ virtual std::string encode(char const*);
};
}
\ No newline at end of file
Modified: branches/quickbook-1.5-spirit2/html.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/html.cpp (original)
+++ branches/quickbook-1.5-spirit2/html.cpp 2010-02-13 10:04:22 EST (Sat, 13 Feb 2010)
@@ -23,17 +23,20 @@
return r;
}
- std::string html_encoder::encode(std::string const& x) const {
+ std::string html_encoder::encode(std::string const& x)
+ {
return encode_impl(x.begin(), x.end());
}
- std::string html_encoder::encode(char const* x) const {
+ std::string html_encoder::encode(char const* x)
+ {
char const* end = x;
while(*end) ++end;
return encode_impl(x, end);
}
- std::string html_encoder::encode(char c) const {
+ std::string html_encoder::encode(char c)
+ {
return encode_impl(&c, &c + 1);
}
@@ -101,21 +104,23 @@
} initialize_instance;
}
- void html_encoder::operator()(quickbook::state& state, std::string const& x) const
+ void html_encoder::operator()(quickbook::state& state, std::string const& x)
{
state.phrase << x;
}
- void html_encoder::operator()(quickbook::state& state, char x) const
+ void html_encoder::operator()(quickbook::state& state, char x)
{
state.phrase << encode(x);
}
- void html_encoder::operator()(quickbook::state& state, anchor const& x) const {
+ void html_encoder::operator()(quickbook::state& state, anchor const& x)
+ {
state.phrase << "<a id=\"" << encode(x.id) << "\"/>\n";
}
- void html_encoder::operator()(quickbook::state& state, link const& x) const {
+ void html_encoder::operator()(quickbook::state& state, link const& x)
+ {
html_markup m = markup_map.at(x.type);
if(*m.pre) {
state.phrase << m.pre;
@@ -129,17 +134,20 @@
}
}
- void html_encoder::operator()(quickbook::state& state, formatted const& x) const {
+ void html_encoder::operator()(quickbook::state& state, formatted const& x)
+ {
html_markup m = markup_map.at(x.type);
state.phrase << m.pre << x.content << m.post;
}
- void html_encoder::operator()(quickbook::state& state, break_ const& x) const {
+ void html_encoder::operator()(quickbook::state& state, break_ const& x)
+ {
html_markup m = markup_map.at("break");
state.phrase << m.pre;
}
- void html_encoder::operator()(quickbook::state& state, image2 const& x) const {
+ void html_encoder::operator()(quickbook::state& state, image2 const& x)
+ {
std::map<std::string, char const*> translate;
translate["alt"] = "alt";
translate["fileref"] = "src";
@@ -166,11 +174,13 @@
state.phrase << "/>";
}
- void html_encoder::operator()(quickbook::state& state, hr) const {
+ void html_encoder::operator()(quickbook::state& state, hr)
+ {
state.phrase << markup_map.at("hr").pre;
}
- void html_encoder::operator()(quickbook::state& state, begin_section2 const& x) const {
+ void html_encoder::operator()(quickbook::state& state, begin_section2 const& x)
+ {
// TODO: Should this be stored in the 'token', or at least have a nicer interface.
int level = state.section_level + 1;
if (level > 6) level = 6;
@@ -194,11 +204,13 @@
}
}
- void html_encoder::operator()(quickbook::state& state, end_section2 const& x) const {
+ void html_encoder::operator()(quickbook::state& state, end_section2 const& x)
+ {
state.phrase << "</section>";
}
- void html_encoder::operator()(quickbook::state& state, heading2 const& x) const {
+ void html_encoder::operator()(quickbook::state& state, heading2 const& x)
+ {
state.phrase
<< "<h" << x.level << " id=\"" << x.id << "\">"
;
@@ -213,7 +225,7 @@
state.phrase << "</h" << x.level << ">";
}
- void html_encoder::operator()(quickbook::state& state, variablelist const& x) const
+ void html_encoder::operator()(quickbook::state& state, variablelist const& x)
{
// TODO: What should I do for the title?
state.phrase << "<p>";
@@ -235,7 +247,7 @@
state.phrase << "</dl>\n";
}
- void html_encoder::operator()(quickbook::state& state, table2 const& x) const
+ void html_encoder::operator()(quickbook::state& state, table2 const& x)
{
if (x.title)
{
@@ -281,13 +293,13 @@
state.phrase << "</table>\n";
}
- void html_encoder::operator()(quickbook::state& state, xinclude2 const& x) const
+ void html_encoder::operator()(quickbook::state& state, xinclude2 const& x)
{
// TODO: ?????
//state.phrase << "\n<xi:include href=\"" << x.path << "\" />\n";
}
- void html_encoder::operator()(quickbook::state& state, list2 const& x) const
+ void html_encoder::operator()(quickbook::state& state, list2 const& x)
{
state.phrase << std::string(x.mark == '#' ? "<ol>\n" : "<ul>\n");
@@ -302,7 +314,7 @@
state.phrase << std::string(x.mark == '#' ? "\n</ol>" : "\n</ul>");
}
- void html_encoder::operator()(quickbook::state& state, callout_link const& x) const
+ void html_encoder::operator()(quickbook::state& state, callout_link const& x)
{
state.phrase
<< "<span"
@@ -318,7 +330,7 @@
;
}
- void html_encoder::operator()(quickbook::state& state, callout_list const& x) const
+ void html_encoder::operator()(quickbook::state& state, callout_list const& x)
{
state.phrase
<< "<dl class=\"calloutlist\">";
@@ -342,7 +354,7 @@
<< "</ol>";
}
- void html_encoder::operator()(quickbook::state& state, code_token const& x) const
+ void html_encoder::operator()(quickbook::state& state, code_token const& x)
{
std::string type = x.type;
if(type == "space") {
@@ -356,7 +368,7 @@
}
}
- void html_encoder::operator()(quickbook::state& state, doc_info const& info) const
+ void html_encoder::operator()(quickbook::state& state, doc_info const& info)
{
// if we're ignoring the document info, we're done.
if (info.ignore) return;
@@ -461,7 +473,7 @@
;
}
- void html_encoder::operator()(quickbook::state& state, doc_info_post const& x) const
+ void html_encoder::operator()(quickbook::state& state, doc_info_post const& x)
{
// if we're ignoring the document info, do nothing.
if (x.info.ignore) return;
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