|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r62844 - branches/quickbook-1.5-spirit2
From: daniel_james_at_[hidden]
Date: 2010-06-12 09:04:12
Author: danieljames
Date: 2010-06-12 09:04:11 EDT (Sat, 12 Jun 2010)
New Revision: 62844
URL: http://svn.boost.org/trac/boost/changeset/62844
Log:
Less use of std::pair.
Clang was having some issues with my use of fusion::reversed_view. But I
think this is cleaner anyway.
Text files modified:
branches/quickbook-1.5-spirit2/boostbook.cpp | 8 ++--
branches/quickbook-1.5-spirit2/doc_info.hpp | 10 +++++-
branches/quickbook-1.5-spirit2/doc_info_actions.cpp | 1
branches/quickbook-1.5-spirit2/doc_info_grammar.cpp | 61 +++++++++++++++++++--------------------
branches/quickbook-1.5-spirit2/html.cpp | 8 ++--
5 files changed, 47 insertions(+), 41 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-06-12 09:04:11 EDT (Sat, 12 Jun 2010)
@@ -461,8 +461,8 @@
BOOST_FOREACH(doc_info::author const& author, info.doc_authors) {
state.phrase
<< "<author>\n"
- << "<firstname>" << author.first << "</firstname>\n"
- << "<surname>" << author.second << "</surname>\n"
+ << "<firstname>" << author.firstname << "</firstname>\n"
+ << "<surname>" << author.surname << "</surname>\n"
<< "</author>\n";
}
state.phrase << "</authorgroup>\n";
@@ -473,12 +473,12 @@
{
state.phrase << "<copyright>\n";
- BOOST_FOREACH(unsigned int year, copyright.first) {
+ BOOST_FOREACH(unsigned int year, copyright.years) {
state.phrase << "<year>" << year << "</year>\n";
}
state.phrase
- << "<holder>" << copyright.second << "</holder>\n"
+ << "<holder>" << copyright.holder << "</holder>\n"
<< "</copyright>\n"
;
}
Modified: branches/quickbook-1.5-spirit2/doc_info.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/doc_info.hpp (original)
+++ branches/quickbook-1.5-spirit2/doc_info.hpp 2010-06-12 09:04:11 EDT (Sat, 12 Jun 2010)
@@ -22,10 +22,16 @@
struct doc_info
{
typedef std::vector<unsigned int> copyright_years;
- typedef std::pair<copyright_years, std::string> copyright_entry;
+ struct copyright_entry {
+ copyright_years years;
+ std::string holder;
+ };
typedef std::vector<copyright_entry> copyright_list;
typedef std::vector<raw_string> category_list;
- typedef std::pair<std::string, std::string> author;
+ struct author {
+ std::string firstname;
+ std::string surname;
+ };
typedef std::vector<author> author_list;
typedef boost::variant<raw_string, std::string> variant_string;
enum variant_string_enum { raw_string_type, string_type };
Modified: branches/quickbook-1.5-spirit2/doc_info_actions.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/doc_info_actions.cpp (original)
+++ branches/quickbook-1.5-spirit2/doc_info_actions.cpp 2010-06-12 09:04:11 EDT (Sat, 12 Jun 2010)
@@ -19,6 +19,7 @@
#include "doc_info_actions.hpp"
#include "state.hpp"
#include "utils.hpp"
+#include <iostream>
namespace quickbook
{
Modified: branches/quickbook-1.5-spirit2/doc_info_grammar.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/doc_info_grammar.cpp (original)
+++ branches/quickbook-1.5-spirit2/doc_info_grammar.cpp 2010-06-12 09:04:11 EDT (Sat, 12 Jun 2010)
@@ -18,8 +18,6 @@
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/spirit/include/phoenix_bind.hpp>
-#include <boost/fusion/include/std_pair.hpp>
-#include <boost/fusion/include/reverse_view.hpp>
#include "doc_info.hpp"
#include "grammar_impl.hpp"
#include "actions.hpp"
@@ -32,31 +30,29 @@
namespace qi = boost::spirit::qi;
namespace ph = boost::phoenix;
- void set_quickbook_version(boost::optional<std::pair<unsigned, unsigned> > version)
+ void set_quickbook_version(boost::fusion::vector<unsigned, unsigned> version)
{
- if (version)
- {
- qbk_major_version = version->first;
- qbk_minor_version = version->second;
- }
- else
- {
- qbk_major_version = 1;
- qbk_minor_version = 1;
-
- // TODO:
- //detail::outwarn(actions.filename.file_string(),1)
- // << "Warning: Quickbook version undefined. "
- // "Version 1.1 is assumed" << std::endl;
- }
-
+ qbk_major_version = boost::fusion::at_c<0>(version);
+ qbk_minor_version = boost::fusion::at_c<1>(version);
qbk_version_n = (qbk_major_version * 100) + qbk_minor_version;
}
+
+ void default_quickbook_version()
+ {
+ qbk_major_version = 1;
+ qbk_minor_version = 1;
+ qbk_version_n = 101;
+
+ // TODO:
+ //detail::outwarn(actions.filename.native_file_string(),1)
+ // << "Warning: Quickbook version undefined. "
+ // "Version 1.1 is assumed" << std::endl;
+ }
void quickbook_grammar::impl::init_doc_info()
{
qi::symbols<char>& doc_types = store_.create();
- qi::rule<iterator, std::pair<unsigned, unsigned>()>& quickbook_version = store_.create();
+ qi::rule<iterator>& quickbook_version = store_.create();
qi::rule<iterator, std::string()>& phrase = store_.create();
qi::rule<iterator, raw_source()>& doc_version = store_.create();
qi::rule<iterator, raw_source()>& doc_id = store_.create();
@@ -66,10 +62,9 @@
qi::rule<iterator, std::string()>& doc_source_mode = store_.create(); // TODO: raw_source
qi::rule<iterator, doc_info::variant_string()>& doc_purpose = store_.create();
qi::rule<iterator, doc_info::variant_string()>& doc_license = store_.create();
- qi::rule<iterator, std::pair<std::vector<unsigned int>, std::string>()>& doc_copyright = store_.create();
- qi::rule<iterator, std::vector<std::pair<std::string, std::string> >()>& doc_authors = store_.create();
- qi::rule<iterator, boost::fusion::reverse_view<
- std::pair<std::string, std::string> >()>& doc_author = store_.create();
+ qi::rule<iterator, doc_info::copyright_entry()>& doc_copyright = store_.create();
+ qi::rule<iterator, doc_info::author_list()>& doc_authors = store_.create();
+ qi::rule<iterator, doc_info::author()>& doc_author = store_.create();
qi::rule<iterator, quickbook::raw_string()>& raw_phrase = store_.create();
typedef qi::uint_parser<int, 10, 1, 2> uint2_t;
@@ -88,7 +83,7 @@
>> qi::raw[
*(qi::char_ - (qi::char_('[') | ']' | qi::eol))
] [member_assign(&doc_info::doc_title)]
- >> quickbook_version [set_quickbook_version]
+ >> quickbook_version
>>
*(
space >> '[' >>
@@ -111,15 +106,18 @@
>> space >> ']' >> +qi::eol
;
- quickbook_version = -(
- space >> '['
+ quickbook_version =
+ ( space
+ >> '['
>> "quickbook"
>> hard_space
>> qi::uint_
>> '.'
>> uint2_t()
>> space >> ']'
- );
+ ) [set_quickbook_version]
+ | qi::eps [default_quickbook_version]
+ ;
doc_version = "version" >> hard_space >> qi::raw[*(qi::char_ - ']')];
doc_id = "id" >> hard_space >> qi::raw[*(qi::char_ - ']')];
@@ -130,8 +128,9 @@
doc_copyright =
"copyright"
>> hard_space
- >> +(qi::uint_ >> space)
+ >> (+(qi::uint_ >> space)) [member_assign(&doc_info::copyright_entry::years)]
>> qi::raw[(*(qi::char_ - ']'))]
+ [member_assign(&doc_info::copyright_entry::holder)]
;
doc_purpose =
@@ -146,9 +145,9 @@
space
>> '['
>> space
- >> (*(qi::char_ - ','))
+ >> (*(qi::char_ - ',')) [member_assign(&doc_info::author::surname)]
>> ',' >> space
- >> (*(qi::char_ - ']'))
+ >> (*(qi::char_ - ']')) [member_assign(&doc_info::author::firstname)]
>> ']'
;
Modified: branches/quickbook-1.5-spirit2/html.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/html.cpp (original)
+++ branches/quickbook-1.5-spirit2/html.cpp 2010-06-12 09:04:11 EDT (Sat, 12 Jun 2010)
@@ -456,9 +456,9 @@
BOOST_FOREACH(doc_info::author const& author, info.doc_authors) {
state.phrase
<< "<dd>"
- << author.first
+ << author.firstname
<< " "
- << author.second
+ << author.surname
<< "</dd>\n";
}
}
@@ -476,7 +476,7 @@
unsigned int range_state = 0;
unsigned int previous = 0;
- BOOST_FOREACH(unsigned int year, copyright.first) {
+ BOOST_FOREACH(unsigned int year, copyright.years) {
switch(range_state) {
case 0: // Start
state.phrase << year;
@@ -504,7 +504,7 @@
state.phrase
<< " "
- << copyright.second
+ << copyright.holder
<< "</dd>\n"
;
}
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