📄 actions.hpp
字号:
: phrase(phrase), tag(tag) {}
template <typename Iterator>
void operator()(Iterator first, Iterator last) const
{
Iterator save = first;
phrase << tag;
while (first != last)
detail::print_char(*first++, phrase);
phrase << "\">";
// Yes, it is safe to dereference last here. When we
// reach here, *last is certainly valid. We test if
// *last == ']'. In which case, the url is the text.
// Example: [@http://spirit.sourceforge.net/]
if (*last == ']')
{
first = save;
while (first != last)
detail::print_char(*first++, phrase);
}
}
std::ostream& phrase;
char const* tag;
};
template <typename Actions>
struct variablelist_action
{
// Handles variable lists
variablelist_action(Actions& actions)
: actions(actions) {}
template <typename Iterator>
void operator()(Iterator, Iterator) const
{
if (!!actions.out)
{
actions.out << "<variablelist>\n";
actions.out << "<title>";
std::string::iterator first = actions.table_title.begin();
std::string::iterator last = actions.table_title.end();
while (first != last)
detail::print_char(*first++, actions.out);
actions.out << "</title>\n";
std::string str = actions.phrase.str();
actions.phrase.str(std::string());
actions.out << str;
actions.out << "</variablelist>\n";
actions.table_span = 0;
actions.table_header.clear();
actions.table_title.clear();
}
}
Actions& actions;
};
template <typename Actions>
struct table_action
{
// Handles tables
table_action(Actions& actions)
: actions(actions) {}
template <typename Iterator>
void operator()(Iterator, Iterator) const
{
if (!!actions.out)
{
actions.out << "<informaltable frame=\"all\">\n"
<< "<bridgehead renderas=\"sect4\">";
actions.out << "<phrase role=\"table-title\">";
std::string::iterator first = actions.table_title.begin();
std::string::iterator last = actions.table_title.end();
while (first != last)
detail::print_char(*first++, actions.out);
actions.out << "</phrase>";
actions.out << "</bridgehead>\n"
<< "<tgroup cols=\"" << actions.table_span << "\">\n";
if(!actions.table_header.empty())
{
actions.out << "<thead>" << actions.table_header << "</thead>\n";
}
actions.out << "<tbody>\n";
std::string str = actions.phrase.str();
actions.phrase.str(std::string());
actions.out << str;
actions.out << "</tbody>\n"
<< "</tgroup>\n"
<< "</informaltable>\n";
actions.table_span = 0;
actions.table_header.clear();
actions.table_title.clear();
}
}
Actions& actions;
};
struct start_row_action
{
// Handles table rows
start_row_action(std::stringstream& phrase, unsigned& span, std::string& header)
: phrase(phrase), span(span), header(header) {}
template <typename T>
void operator()(T const&) const
{
// the first row is the header
if(header.empty() && !phrase.str().empty())
{
header = phrase.str();
phrase.str(std::string());
}
phrase << start_row_;
span = 0;
}
template <typename T>
void operator()(T const& t,T const&) const
{
(*this)(t);
}
std::stringstream& phrase;
unsigned& span;
std::string& header;
};
struct start_col_action
{
// Handles table columns
start_col_action(std::ostream& phrase, unsigned& span)
: phrase(phrase), span(span) {}
template <typename T>
void operator()(T const&) const
{
phrase << start_cell_; ++span;
}
std::ostream& phrase;
unsigned& span;
};
struct begin_section_action
{
// Handles begin page
begin_section_action(
std::ostream& phrase
, std::string& library_id
, std::string& section_id)
: phrase(phrase)
, library_id(library_id)
, section_id(section_id) {}
template <typename Iterator>
void operator()(Iterator first, Iterator last) const
{
if (section_id.empty())
section_id = detail::make_identifier(first, last);
phrase << "\n<section id=\"" << library_id << "." << section_id << "\">\n";
phrase << "<title>";
while (first != last)
detail::print_char(*first++, phrase);
phrase << "</title>\n";
}
std::ostream& phrase;
std::string& library_id;
std::string& section_id;
};
struct xinclude_action
{
// Handles XML includes
xinclude_action(std::ostream& out_)
: out(out_) {}
template <typename Iterator>
void operator()(Iterator first, Iterator last) const
{
out << "\n<xi:include href=\"";
while (first != last)
detail::print_char(*first++, out);
out << "\" />\n";
}
std::ostream& out;
};
struct xml_author
{
// Handles xml author
xml_author(std::ostream& out)
: out(out) {}
void operator()(std::pair<std::string, std::string> const& author) const
{
out << " <author>\n"
<< " <firstname>" << author.first << "</firstname>\n"
<< " <surname>" << author.second << "</surname>\n"
<< " </author>\n";
}
std::ostream& out;
};
struct xml_year
{
// Handles xml year
xml_year(std::ostream& out)
: out(out) {}
void operator()(std::string const &year) const
{
out << " <year>" << year << "</year>\n";
}
std::ostream& out;
};
template <typename Actions>
void pre(std::ostream& out, Actions& actions)
{
// The quickbook file has been parsed. Now, it's time to
// generate the output. Here's what we'll do *before* anything else.
if (actions.doc_id.empty())
actions.doc_id = detail::make_identifier(
actions.doc_title.begin(),actions.doc_title.end());
if (actions.doc_dirname.empty())
actions.doc_dirname = actions.doc_id;
if (actions.doc_last_revision.empty())
{
// default value for last-revision is now
char strdate[ 30 ];
time_t t = time(0);
strftime(
strdate, sizeof(strdate),
"$" /* prevent CVS substitution */ "Date: %Y/%m/%d %H:%M:%S $",
gmtime(&t)
);
actions.doc_last_revision = strdate;
}
out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
<< "<!DOCTYPE library PUBLIC \"-//Boost//DTD BoostBook XML V1.0//EN\"\n"
<< " \"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd\">\n"
<< '<' << actions.doc_type << "\n"
<< " id=\"" << actions.doc_id << "\"\n"
<< " name=\"" << actions.doc_title << "\"\n"
<< " dirname=\"" << actions.doc_dirname << "\"\n"
<< " last-revision=\"" << actions.doc_last_revision << "\" \n"
<< " xmlns:xi=\"http://www.w3.org/2001/XInclude\">\n"
<< " <" << actions.doc_type << "info>\n";
for_each(
actions.doc_authors.begin()
, actions.doc_authors.end()
, xml_author(out));
if (!actions.doc_copyright_holder.empty())
{
out << "\n" << " <copyright>\n";
for_each(
actions.doc_copyright_years.begin()
, actions.doc_copyright_years.end()
, xml_year(out));
out << " <holder>" << actions.doc_copyright_holder << "</holder>\n"
<< " </copyright>\n"
<< "\n"
;
}
if (!actions.doc_license.empty())
{
out << " <legalnotice>\n"
<< " <para>\n"
<< " " << actions.doc_license << "\n"
<< " </para>\n"
<< " </legalnotice>\n"
<< "\n"
;
}
if (!actions.doc_purpose.empty())
{
out << " <" << actions.doc_type << "purpose>\n"
<< " " << actions.doc_purpose
<< " </" << actions.doc_type << "purpose>\n"
<< "\n"
;
}
if (!actions.doc_purpose.empty())
{
out << " <" << actions.doc_type << "category name=\"category:"
<< actions.doc_category
<< "\"></" << actions.doc_type << "category>\n"
<< "\n"
;
}
out << " </" << actions.doc_type << "info>\n"
<< "\n"
;
if (!actions.doc_title.empty())
{
out << " <title>" << actions.doc_title;
if (!actions.doc_version.empty())
out << ' ' << actions.doc_version;
out << "</title>\n\n\n";
}
}
template <typename Actions>
void post(std::ostream& out, Actions& actions)
{
// We've finished generating our output. Here's what we'll do
// *after* everything else.
out << "\n</" << actions.doc_type << ">\n\n";
}
}
#endif // BOOST_SPIRIT_QUICKBOOK_UTILS_HPP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -