Update of /cvsroot/boost/boost/tools/quickbook/detail
In directory
sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv7968/tools/quickbook/detail
Modified Files:
actions.cpp actions.hpp actions_class.cpp actions_class.hpp
collector.cpp collector.hpp quickbook.cpp
Log Message:
New stream infrastructure. Uses boost::iostream.
Index: actions.cpp
===================================================================
RCS file: /cvsroot/boost/boost/tools/quickbook/detail/actions.cpp,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- actions.cpp 7 Jun 2006 04:20:13 -0000 1.38
+++ actions.cpp 8 Jun 2006 06:50:48 -0000 1.39
@@ -21,26 +21,26 @@
namespace quickbook
{
- void error_action::operator()(iterator const& first, iterator const&
/*last*/) const
+ void error_action::operator()(iterator first, iterator /*last*/) const
{
boost::spirit::file_position const pos = first.get_position();
detail::outerr(pos.file,pos.line)
<< "Syntax Error near column " << pos.column << ".\n";
}
- void phrase_action::operator()(iterator const& first, iterator const&
last) const
+ void phrase_action::operator()(iterator first, iterator last) const
{
- std::string str = phrase.str();
+ std::string str;
+ phrase.swap(str);
detail::convert_nbsp(str);
- phrase.str(std::string());
out << pre << str << post;
}
- void header_action::operator()(iterator const& first, iterator const&
last) const
+ void header_action::operator()(iterator first, iterator last) const
{
- std::string str = phrase.str();
+ std::string str;
+ phrase.swap(str);
detail::convert_nbsp(str);
- phrase.str(std::string());
if (qbk_version_n < 103) // version 1.2 and below
{
@@ -67,21 +67,21 @@
}
}
- void generic_header_action::operator()(iterator const& first, iterator
const& last) const
+ void generic_header_action::operator()(iterator first, iterator last) const
{
int level_ = section_level + 2; // section_level is zero-based. We
need to use a
// 0ne-based heading which is one
greater
// than the current. Thus:
section_level + 2.
if (level_ > 6) // The max is h6, clip it if it
goes
level_ = 6; // further than that
- std::string str = phrase.str();
+ std::string str;
+ phrase.swap(str);
detail::convert_nbsp(str);
std::string anchor =
library_id + '.' + qualified_section_id + '.' +
detail::make_identifier(str.begin(), str.end());
- phrase.str(std::string());
out
<< "<anchor id=\"" << anchor << "\"/>"
<< "<bridgehead renderas=\"sect" << level_ << "\">"
@@ -92,7 +92,7 @@
;
}
- void simple_phrase_action::operator()(iterator first, iterator const&
last) const
+ void simple_phrase_action::operator()(iterator first, iterator last) const
{
out << pre;
std::string str(first, last);
@@ -108,12 +108,11 @@
out << post;
}
- void list_action::operator()(iterator const& first, iterator const& last)
const
+ void list_action::operator()(iterator first, iterator last) const
{
BOOST_ASSERT(!list_marks.empty()); // there must be at least one item
in the stack
- std::string str = list_buffer.str();
- list_buffer.str(std::string());
- out << str;
+ out << list_buffer.str();
+ list_buffer.clear();
while (!list_marks.empty())
{
@@ -127,7 +126,7 @@
list_indent = -1; // reset
}
- void list_format_action::operator()(iterator first, iterator const& last)
const
+ void list_format_action::operator()(iterator first, iterator last) const
{
int new_indent = 0;
while (first != last && (*first == ' ' || *first == '\t'))
@@ -164,11 +163,11 @@
// </listitem> to accomodate this sub-list. We'll close
// the listelem later.
- std::string str = out.str();
+ std::string str;
+ out.swap(str);
std::string::size_type pos = str.rfind("\n</listitem>");
BOOST_ASSERT(pos <= str.size());
str.erase(str.begin()+pos, str.end());
- out.str(std::string());
out << str;
}
out << std::string((mark == '#') ? "<orderedlist>\n" :
"<itemizedlist>\n");
@@ -199,7 +198,7 @@
}
}
- void span::operator()(iterator first, iterator const& last) const
+ void span::operator()(iterator first, iterator last) const
{
out << "<phrase role=\"" << name << "\">";
while (first != last)
@@ -212,7 +211,7 @@
out << '#'; // print out an unexpected character
}
- void anchor_action::operator()(iterator first, iterator const& last) const
+ void anchor_action::operator()(iterator first, iterator last) const
{
out << "<anchor id=\"";
while (first != last)
@@ -246,39 +245,32 @@
detail::print_space(ch, out.get());
}
- void space::operator()(iterator first, iterator const& last) const
+ void space::operator()(iterator first, iterator last) const
{
while (first != last)
detail::print_space(*first++, out.get());
}
- void pre_escape_back::operator()(iterator const& first, iterator const&
last) const
+ void pre_escape_back::operator()(iterator first, iterator last) const
{
- save = escape_actions.phrase.str(); // save the stream
+ escape_actions.phrase.push(); // save the stream
}
- void post_escape_back::operator()(iterator const& first, iterator const&
last) const
+ void post_escape_back::operator()(iterator first, iterator last) const
{
- std::string str = escape_actions.phrase.str();
- escape_actions.phrase.str(save); // restore the stream
- out << str;
+ out << escape_actions.phrase.str();
+ escape_actions.phrase.pop(); // restore the stream
}
- void code_action::operator()(iterator const& first, iterator const& last)
const
+ void code_action::operator()(iterator first, iterator last) const
{
- std::string save = phrase.str();
- phrase.str(std::string());
+ std::string save;
+ phrase.swap(save);
// preprocess the code section to remove the initial indentation
- std::string program_(first, last);
- detail::unindent(program_);
-
- // $$$ fix me $$$ this is wasteful. we have to convert
- // back to a vector<char> so we can use the same iterator type
- // used by the rest of the system, otherwise, it is wasteful
- // of function template instantiations
+ std::string program(first, last);
+ detail::unindent(program);
- std::vector<char> program(program_.begin(), program_.end());
iterator first_(program.begin(), program.end());
iterator last_(program.end(), program.end());
first_.set_position(first.get_position());
@@ -293,20 +285,19 @@
parse(first_, last_, python_p);
}
- std::string str = temp.str();
- temp.str(std::string());
- phrase.str(std::string());
- phrase << save;
+ std::string str;
+ temp.swap(str);
+ phrase.swap(save);
out << "<programlisting>\n";
out << str;
out << "</programlisting>\n";
}
- void inline_code_action::operator()(iterator const& first, iterator const&
last) const
+ void inline_code_action::operator()(iterator first, iterator last) const
{
- std::string save = out.str();
- out.str(std::string());
+ std::string save;
+ out.swap(save);
// print the code with syntax coloring
if (source_mode == "c++")
@@ -317,11 +308,10 @@
{
parse(first, last, python_p);
}
- std::string str = temp.str();
- temp.str(std::string());
- out.str(std::string());
+ std::string str;
+ temp.swap(str);
+ out.swap(save);
- out << save;
out << "<code>";
out << str;
out << "</code>";
@@ -332,7 +322,7 @@
phrase << ch;
}
- void raw_char_action::operator()(iterator const& first, iterator const&
/*last*/) const
+ void raw_char_action::operator()(iterator first, iterator /*last*/) const
{
phrase << *first;
}
@@ -342,12 +332,12 @@
detail::print_char(ch, phrase.get());
}
- void plain_char_action::operator()(iterator const& first, iterator const&
/*last*/) const
+ void plain_char_action::operator()(iterator first, iterator /*last*/) const
{
detail::print_char(*first, phrase.get());
}
- void image_action::operator()(iterator first, iterator const& last) const
+ void image_action::operator()(iterator first, iterator last) const
{
fs::path const img_path(std::string(first, last));
@@ -367,23 +357,22 @@
phrase << "</inlinemediaobject>";
}
- void macro_identifier_action::operator()(iterator const& first, iterator
const& last) const
+ void macro_identifier_action::operator()(iterator first, iterator last)
const
{
actions.macro_id.assign(first, last);
- actions.macro_phrase_save = actions.phrase.str();
- actions.phrase.str(std::string());
+ actions.phrase.push(); // save the phrase
}
- void macro_definition_action::operator()(iterator const& first, iterator
const& last) const
+ void macro_definition_action::operator()(iterator first, iterator last)
const
{
actions.macro.add(
actions.macro_id.begin()
, actions.macro_id.end()
, actions.phrase.str());
- actions.phrase.str(actions.macro_phrase_save);
+ actions.phrase.pop(); // restore the phrase
}
- void template_body_action::operator()(iterator const& first, iterator
const& last) const
+ void template_body_action::operator()(iterator first, iterator last) const
{
BOOST_ASSERT(actions.template_info.size());
actions.template_info.push_back(std::string(first, last));
@@ -394,7 +383,7 @@
actions.template_info.clear();
}
- void do_template_action::operator()(iterator const& first, iterator
const&) const
+ void do_template_action::operator()(iterator first, iterator) const
{
boost::spirit::file_position const pos = first.get_position();
++actions.template_depth;
@@ -408,9 +397,7 @@
std::string result;
actions.push(); // scope the actions' states
- {
- actions.phrase.str(std::string()); // clear the phrase
-
+ {
simple_phrase_grammar<quickbook::actions> phrase_p(actions);
block_grammar<quickbook::actions, true> block_p(actions);
@@ -478,12 +465,11 @@
{
actions.templates.add(tpl->begin(), tpl->end(), template_);
}
- actions.phrase.str(std::string()); // clear the phrase
++arg; ++tpl;
}
// parse the template body:
- std::vector<char> temp;
+ std::string temp;
temp.assign(tpl->begin(), tpl->end());
temp.reserve(temp.size()+2); // reserve 2 more
@@ -492,7 +478,7 @@
// a newline, then we regard is as a block, otherwise, we parse
// it as a phrase.
- std::vector<char>::const_iterator iter = temp.begin();
+ std::string::const_iterator iter = temp.begin();
while (iter != temp.end() && ((*iter == ' ') || (*iter == '\t')))
++iter; // skip spaces and tabs
bool is_block = (iter != temp.end()) && ((*iter == '\r') || (*iter
== '\n'));
@@ -505,7 +491,7 @@
first.set_position(template_pos);
iterator last(temp.end(), temp.end());
r = boost::spirit::parse(first, last, phrase_p).full;
- result = actions.phrase.str();
+ actions.phrase.swap(result);
}
else
{
@@ -520,7 +506,7 @@
first.set_position(template_pos);
iterator last(temp.end(), temp.end());
r = boost::spirit::parse(first, last, block_p).full;
- result = actions.out.str();
+ actions.out.swap(result);
}
if (!r)
@@ -536,7 +522,7 @@
--actions.template_depth;
}
- void link_action::operator()(iterator first, iterator const& last) const
+ void link_action::operator()(iterator first, iterator last) const
{
iterator save = first;
phrase << tag;
@@ -568,8 +554,8 @@
detail::print_char(*first++, actions.out.get());
actions.out << "</title>\n";
- std::string str = actions.phrase.str();
- actions.phrase.str(std::string());
+ std::string str;
+ actions.phrase.swap(str);
actions.out << str;
actions.out << "</variablelist>\n";
@@ -602,9 +588,9 @@
actions.out << "<tbody>\n";
- std::string str = actions.phrase.str();
+ std::string str;
+ actions.phrase.swap(str);
detail::convert_nbsp(str);
- actions.phrase.str(std::string());
actions.out << str;
actions.out << "</tbody>\n"
@@ -620,8 +606,7 @@
// the first row is the header
if (header.empty() && !phrase.str().empty())
{
- header = phrase.str();
- phrase.str(std::string());
+ phrase.swap(header);
}
phrase << start_row_;
@@ -639,7 +624,7 @@
++span;
}
- void begin_section_action::operator()(iterator first, iterator const&
last) const
+ void begin_section_action::operator()(iterator first, iterator last) const
{
if (section_id.empty())
section_id = detail::make_identifier(first, last);
@@ -662,8 +647,7 @@
<< "." << qualified_section_id << "\">\n";
}
std::string str;
- str = phrase.str();
- phrase.str(std::string());
+ phrase.swap(str);
if (qbk_version_n < 103) // version 1.2 and below
{
@@ -681,7 +665,7 @@
}
}
- void end_section_action::operator()(iterator const& first, iterator const&
last) const
+ void end_section_action::operator()(iterator first, iterator last) const
{
out << "</section>";
@@ -720,7 +704,7 @@
return std::accumulate(xml, xmlfile.end(), xmltmp, concat);
}
- void xinclude_action::operator()(iterator const& first, iterator const&
last) const
+ void xinclude_action::operator()(iterator first, iterator last) const
{
// Given an xml file to include and the current filename, calculate the
// path to the XML file relative to the output directory.
@@ -737,7 +721,7 @@
out << "\" />\n";
}
- void include_action::operator()(iterator const& first, iterator const&
last) const
+ void include_action::operator()(iterator first, iterator last) const
{
fs::path filein(std::string(first, last), fs::native);
std::string doc_type, doc_id, doc_dirname, doc_last_revision;
@@ -945,9 +929,8 @@
out << "\n</" << actions.doc_type << ">\n\n";
}
- void phrase_to_string_action::operator()(iterator const& first, iterator
const& last) const
+ void phrase_to_string_action::operator()(iterator first, iterator last)
const
{
- out = phrase.str();
- phrase.str(std::string());
+ phrase.swap(out);
}
}
Index: actions.hpp
===================================================================
RCS file: /cvsroot/boost/boost/tools/quickbook/detail/actions.hpp,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- actions.hpp 7 Jun 2006 04:20:13 -0000 1.32
+++ actions.hpp 8 Jun 2006 06:50:48 -0000 1.33
@@ -16,7 +16,6 @@
#include <vector>
#include <stack>
#include <algorithm>
-#include <sstream>
#include <boost/spirit/iterator/position_iterator.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/foreach.hpp>
@@ -33,9 +32,7 @@
namespace quickbook
{
namespace fs = boost::filesystem;
- typedef std::vector<char> file_storage;
- typedef position_iterator<file_storage::const_iterator> iterator;
- typedef std::string::const_iterator string_iterator;
+ typedef position_iterator<std::string::const_iterator> iterator;
typedef symbols<std::string> string_symbols;
// template symbols are stored as follows:
@@ -70,7 +67,7 @@
{
// Prints an error message to std::cerr
- void operator()(iterator const& first, iterator const& /*last*/) const;
+ void operator()(iterator first, iterator /*last*/) const;
};
struct phrase_action
@@ -88,7 +85,7 @@
, pre(pre)
, post(post) {}
- void operator()(iterator const& first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
collector& out;
collector& phrase;
@@ -116,7 +113,7 @@
, pre(pre)
, post(post) {}
- void operator()(iterator const& first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
collector& out;
collector& phrase;
@@ -145,7 +142,7 @@
, qualified_section_id(qualified_section_id)
, section_level(section_level) {}
- void operator()(iterator const& first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
collector& out;
collector& phrase;
@@ -169,7 +166,7 @@
, post(post)
, macro(macro) {}
- void operator()(iterator first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
collector& out;
std::string pre;
@@ -192,7 +189,7 @@
, list_indent(list_indent)
, list_marks(list_marks) {}
- void operator()(iterator const& first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
collector& out;
collector& list_buffer;
@@ -213,7 +210,7 @@
, list_indent(list_indent)
, list_marks(list_marks) {}
- void operator()(iterator first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
collector& out;
int& list_indent;
@@ -227,7 +224,7 @@
span(char const* name, collector& out)
: name(name), out(out) {}
- void operator()(iterator first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
char const* name;
collector& out;
@@ -252,7 +249,7 @@
anchor_action(collector& out)
: out(out) {}
- void operator()(iterator first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
collector& out;
};
@@ -281,7 +278,7 @@
space(collector& out)
: out(out) {}
- void operator()(iterator first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
void operator()(char ch) const;
collector& out;
@@ -294,7 +291,7 @@
pre_escape_back(actions& escape_actions, std::string& save)
: escape_actions(escape_actions), save(save) {}
- void operator()(iterator const& first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
actions& escape_actions;
std::string& save;
@@ -307,7 +304,7 @@
post_escape_back(collector& out, actions& escape_actions, std::string&
save)
: out(out), escape_actions(escape_actions), save(save) {}
- void operator()(iterator const& first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
collector& out;
actions& escape_actions;
@@ -358,7 +355,7 @@
{
}
- void operator()(iterator const& first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
collector& out;
collector& phrase;
@@ -386,7 +383,7 @@
, python_p(temp, macro, do_macro_action(temp), escape_actions)
{}
- void operator()(iterator const& first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
collector& out;
std::string const& source_mode;
@@ -405,7 +402,7 @@
: phrase(phrase) {}
void operator()(char ch) const;
- void operator()(iterator const& first, iterator const& /*last*/) const;
+ void operator()(iterator first, iterator /*last*/) const;
collector& phrase;
};
@@ -419,7 +416,7 @@
: phrase(phrase) {}
void operator()(char ch) const;
- void operator()(iterator const& first, iterator const& /*last*/) const;
+ void operator()(iterator first, iterator /*last*/) const;
collector& phrase;
};
@@ -431,7 +428,7 @@
image_action(collector& phrase)
: phrase(phrase) {}
- void operator()(iterator first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
collector& phrase;
};
@@ -466,7 +463,7 @@
macro_identifier_action(quickbook::actions& actions)
: actions(actions) {}
- void operator()(iterator const& first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
quickbook::actions& actions;
};
@@ -478,7 +475,7 @@
macro_definition_action(quickbook::actions& actions)
: actions(actions) {}
- void operator()(iterator const& first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
quickbook::actions& actions;
};
@@ -490,7 +487,7 @@
template_body_action(quickbook::actions& actions)
: actions(actions) {}
- void operator()(iterator const& first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
quickbook::actions& actions;
};
@@ -502,7 +499,7 @@
do_template_action(quickbook::actions& actions)
: actions(actions) {}
- void operator()(iterator const& first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
quickbook::actions& actions;
};
@@ -514,7 +511,7 @@
link_action(collector& phrase, char const* tag)
: phrase(phrase), tag(tag) {}
- void operator()(iterator first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
collector& phrase;
char const* tag;
@@ -590,7 +587,7 @@
, section_level(section_level)
, qualified_section_id(qualified_section_id) {}
- void operator()(iterator first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
collector& out;
collector& phrase;
@@ -610,7 +607,7 @@
, section_level(section_level)
, qualified_section_id(qualified_section_id) {}
- void operator()(iterator const& first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
collector& out;
int& section_level;
@@ -623,7 +620,7 @@
xinclude_action(collector& out_, quickbook::actions& actions_)
: out(out_), actions(actions_) {}
- void operator()(iterator const& first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
collector& out;
quickbook::actions& actions;
@@ -636,7 +633,7 @@
include_action(quickbook::actions& actions_)
: actions(actions_) {}
- void operator()(iterator const& first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
quickbook::actions& actions;
};
@@ -673,7 +670,7 @@
phrase_to_string_action(std::string& out, collector& phrase)
: out(out) , phrase(phrase) {}
- void operator()(iterator const& first, iterator const& last) const;
+ void operator()(iterator first, iterator last) const;
std::string& out;
collector& phrase;
Index: actions_class.cpp
===================================================================
RCS file: /cvsroot/boost/boost/tools/quickbook/detail/actions_class.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- actions_class.cpp 7 Jun 2006 04:20:13 -0000 1.2
+++ actions_class.cpp 8 Jun 2006 06:50:48 -0000 1.3
@@ -17,7 +17,7 @@
namespace quickbook
{
- actions::actions(char const* filein_, fs::path const& outdir_,
std::stringstream& out_)
+ actions::actions(char const* filein_, fs::path const& outdir_,
string_stream& out_)
// header info
: doc_type()
, doc_title()
@@ -58,7 +58,6 @@
, table_span(0)
, table_header()
, macro_id()
- , macro_phrase_save()
, list_marks()
, list_indent(-1)
, template_info()
Index: actions_class.hpp
===================================================================
RCS file: /cvsroot/boost/boost/tools/quickbook/detail/actions_class.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- actions_class.hpp 7 Jun 2006 04:20:13 -0000 1.2
+++ actions_class.hpp 8 Jun 2006 06:50:48 -0000 1.3
@@ -20,7 +20,7 @@
struct actions
{
- actions(char const* filein_, fs::path const& outdir,
std::stringstream& out_);
+ actions(char const* filein_, fs::path const& outdir, string_stream&
out_);
///////////////////////////////////////////////////////////////////////////
// State
@@ -84,7 +84,6 @@
unsigned table_span;
std::string table_header;
std::string macro_id;
- std::string macro_phrase_save;
std::stack<mark_type> list_marks;
int list_indent;
string_list template_info;
Index: collector.cpp
===================================================================
RCS file: /cvsroot/boost/boost/tools/quickbook/detail/collector.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- collector.cpp 7 Jun 2006 04:20:13 -0000 1.1
+++ collector.cpp 8 Jun 2006 06:50:48 -0000 1.2
@@ -11,13 +11,31 @@
namespace quickbook
{
+ string_stream::string_stream()
+ : buffer_ptr(new std::string())
+ , stream_ptr(new
ostream(boost::iostreams::back_inserter(*buffer_ptr.get())))
+ {}
+
+ string_stream::string_stream(string_stream const& other)
+ : buffer_ptr(other.buffer_ptr)
+ , stream_ptr(other.stream_ptr)
+ {}
+
+ string_stream&
+ string_stream::operator=(string_stream const& other)
+ {
+ buffer_ptr = other.buffer_ptr;
+ stream_ptr = other.stream_ptr;
+ return *this;
+ }
+
collector::collector()
: main(default_)
, top(default_)
{
}
- collector::collector(std::stringstream& out)
+ collector::collector(string_stream& out)
: main(out)
, top(out)
{
@@ -28,41 +46,22 @@
BOOST_ASSERT(streams.empty()); // assert there are no more pushes than
pops!!!
}
- std::ostream&
- collector::get() const
- {
- return top.get();
- }
-
- std::string
- collector::str() const
- {
- return top.get().str();
- }
-
- void
- collector::str(std::string const& s)
- {
- top.get().str(s);
- }
-
void
collector::push()
{
- streams.push(new std::stringstream());
- top = boost::ref(*streams.top());
+ streams.push(string_stream());
+ top = boost::ref(streams.top());
}
void
collector::pop()
{
BOOST_ASSERT(!streams.empty());
- delete streams.top();
streams.pop();
if (streams.empty())
top = boost::ref(main);
else
- top = boost::ref(*streams.top());
+ top = boost::ref(streams.top());
}
}
Index: collector.hpp
===================================================================
RCS file: /cvsroot/boost/boost/tools/quickbook/detail/collector.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- collector.hpp 7 Jun 2006 04:20:13 -0000 1.1
+++ collector.hpp 8 Jun 2006 06:50:48 -0000 1.2
@@ -11,30 +11,96 @@
#include <string>
#include <stack>
-#include <sstream>
#include <boost/ref.hpp>
+#include <boost/shared_ptr.hpp>
#include <boost/noncopyable.hpp>
+#include <boost/iostreams/device/back_inserter.hpp>
+#include <boost/iostreams/filtering_stream.hpp>
namespace quickbook
{
+ struct string_stream
+ {
+ typedef boost::iostreams::filtering_ostream ostream;
+
+ string_stream();
+ string_stream(string_stream const& other);
+ string_stream& operator=(string_stream const& other);
+
+ std::string const& str() const
+ {
+ stream_ptr->flush();
+ return *buffer_ptr.get();
+ }
+
+ std::ostream& get() const
+ {
+ return *stream_ptr.get();
+ }
+
+ void clear()
+ {
+ buffer_ptr->clear();
+ }
+
+ void swap(std::string& other)
+ {
+ stream_ptr->flush();
+ std::swap(other, *buffer_ptr.get());
+ }
+
+ void append(std::string const& other)
+ {
+ stream_ptr->flush();
+ *buffer_ptr.get() += other;
+ }
+
+ private:
+
+ boost::shared_ptr<std::string> buffer_ptr;
+ boost::shared_ptr<ostream> stream_ptr;
+ };
+
struct collector : boost::noncopyable
{
collector();
- collector(std::stringstream& out);
+ collector(string_stream& out);
~collector();
- std::ostream& get() const;
- std::string str() const;
- void str(std::string const& s);
void push();
void pop();
+ std::ostream& get() const
+ {
+ return top.get().get();
+ }
+
+ std::string const& str() const
+ {
+ return top.get().str();
+ }
+
+ void clear()
+ {
+ top.get().clear();
+ }
+
+ void swap(std::string& other)
+ {
+ top.get().swap(other);
+ }
+
+ void append(std::string const& other)
+ {
+ top.get().append(other);
+ }
+
private:
- std::stack<std::stringstream*> streams;
- boost::reference_wrapper<std::stringstream> main;
- boost::reference_wrapper<std::stringstream> top;
- std::stringstream default_;
+ std::stack<string_stream> streams;
+ boost::reference_wrapper<string_stream> main;
+ boost::reference_wrapper<string_stream> top;
+ string_stream default_;
};
template <typename T>
@@ -44,6 +110,13 @@
out.get() << val;
return out;
}
+
+ inline collector&
+ operator<<(collector& out, std::string const& val)
+ {
+ out.append(val);
+ return out;
+ }
}
#endif // BOOST_SPIRIT_QUICKBOOK_COLLECTOR_HPP
Index: quickbook.cpp
===================================================================
RCS file: /cvsroot/boost/boost/tools/quickbook/detail/quickbook.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- quickbook.cpp 7 Jun 2006 04:20:13 -0000 1.27
+++ quickbook.cpp 8 Jun 2006 06:50:48 -0000 1.28
@@ -21,7 +21,6 @@
#include <stdexcept>
#include <fstream>
#include <iostream>
-#include <sstream>
#if (defined(BOOST_MSVC) && (BOOST_MSVC <= 1310))
#pragma warning(disable:4355)
@@ -47,7 +46,7 @@
//
///////////////////////////////////////////////////////////////////////////
static int
- load(char const* filename, file_storage& storage)
+ load(char const* filename, std::string& storage)
{
using std::cerr;
using std::endl;
@@ -91,12 +90,12 @@
using std::vector;
using std::string;
- file_storage storage;
+ std::string storage;
int err = quickbook::load(filein_, storage);
if (err != 0)
return err;
- typedef position_iterator<file_storage::const_iterator> iterator_type;
+ typedef position_iterator<std::string::const_iterator> iterator_type;
iterator_type first(storage.begin(), storage.end(), filein_);
iterator_type last(storage.end(), storage.end());
@@ -127,7 +126,7 @@
}
static int
- parse(char const* filein_, fs::path const& outdir, std::stringstream& out,
bool ignore_docinfo = false)
+ parse(char const* filein_, fs::path const& outdir, string_stream& out,
bool ignore_docinfo = false)
{
actions actor(filein_, outdir, out);
bool r = parse(filein_, actor);
@@ -153,7 +152,7 @@
outdir = ".";
if (pretty_print)
{
- std::stringstream buffer;
+ string_stream buffer;
result = parse(filein_, outdir, buffer);
if (result == 0)
{
@@ -162,7 +161,7 @@
}
else
{
- std::stringstream buffer;
+ string_stream buffer;
result = parse(filein_, outdir, buffer);
fileout << buffer.str();
}
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs