Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60224 - branches/quickbook-1.5-spirit2
From: daniel_james_at_[hidden]
Date: 2010-03-06 05:47:46


Author: danieljames
Date: 2010-03-06 05:47:44 EST (Sat, 06 Mar 2010)
New Revision: 60224
URL: http://svn.boost.org/trac/boost/changeset/60224

Log:
A little more portable.
Text files modified:
   branches/quickbook-1.5-spirit2/boostbook.cpp | 19 +++++++++++++------
   branches/quickbook-1.5-spirit2/html.cpp | 19 +++++++++++++------
   branches/quickbook-1.5-spirit2/rule_store.hpp | 21 +++++++++++----------
   3 files changed, 37 insertions(+), 22 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-03-06 05:47:44 EST (Sat, 06 Mar 2010)
@@ -106,6 +106,13 @@
                 }
             }
         } initialize_instance;
+
+ boostbook_markup get_markup(std::string const& x) {
+ std::map<std::string, boostbook_markup>::const_iterator
+ pos = markup_map.find(x);
+ BOOST_ASSERT(pos != markup_map.end());
+ return pos->second;
+ }
     }
 
     void boostbook_encoder::operator()(quickbook::state& state, std::string const& x)
@@ -147,7 +154,7 @@
 
     void boostbook_encoder::operator()(quickbook::state& state, link const& x)
     {
- boostbook_markup m = markup_map.at(x.type);
+ boostbook_markup m = get_markup(x.type);
         state.phrase << m.pre;
         state.phrase << encode(x.destination);
         state.phrase << "\">";
@@ -157,13 +164,13 @@
 
     void boostbook_encoder::operator()(quickbook::state& state, formatted const& x)
     {
- boostbook_markup m = markup_map.at(x.type);
+ boostbook_markup m = get_markup(x.type);
         state.phrase << m.pre << x.content << m.post;
     }
 
     void boostbook_encoder::operator()(quickbook::state& state, break_ const& x)
     {
- boostbook_markup m = markup_map.at("break");
+ boostbook_markup m = get_markup("break");
         state.phrase << m.pre;
     }
 
@@ -203,7 +210,7 @@
 
     void boostbook_encoder::operator()(quickbook::state& state, hr)
     {
- state.phrase << markup_map.at("hr").pre;
+ state.phrase << get_markup("hr").pre;
     }
 
     void boostbook_encoder::operator()(quickbook::state& state, begin_section2 const& x)
@@ -260,7 +267,7 @@
         state.phrase << encode(x.title);
         state.phrase << "</title>\n";
 
- boostbook_markup m = markup_map.at("varlistentry");
+ boostbook_markup m = get_markup("varlistentry");
 
         for(std::vector<varlistentry>::const_iterator
             it = x.entries.begin(); it != x.entries.end(); ++it)
@@ -297,7 +304,7 @@
         // used the last count that was calculated.
         state.phrase << "<tgroup cols=\"" << x.cols << "\">\n";
 
- boostbook_markup m = markup_map.at("row");
+ boostbook_markup m = get_markup("row");
 
         if (x.head)
         {

Modified: branches/quickbook-1.5-spirit2/html.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/html.cpp (original)
+++ branches/quickbook-1.5-spirit2/html.cpp 2010-03-06 05:47:44 EST (Sat, 06 Mar 2010)
@@ -106,6 +106,13 @@
                 }
             }
         } initialize_instance;
+
+ html_markup get_markup(std::string const& x) {
+ std::map<std::string, html_markup>::const_iterator
+ pos = markup_map.find(x);
+ BOOST_ASSERT(pos != markup_map.end());
+ return pos->second;
+ }
     }
 
     void html_encoder::operator()(quickbook::state& state, std::string const& x)
@@ -145,7 +152,7 @@
 
     void html_encoder::operator()(quickbook::state& state, link const& x)
     {
- html_markup m = markup_map.at(x.type);
+ html_markup m = get_markup(x.type);
         if(*m.pre) {
             state.phrase << m.pre;
             state.phrase << encode(x.destination);
@@ -174,14 +181,14 @@
                 ;
         }
         else {
- html_markup m = markup_map.at(x.type);
+ html_markup m = get_markup(x.type);
             state.phrase << m.pre << x.content << m.post;
         }
     }
 
     void html_encoder::operator()(quickbook::state& state, break_ const& x)
     {
- html_markup m = markup_map.at("break");
+ html_markup m = get_markup("break");
         state.phrase << m.pre;
     }
 
@@ -215,7 +222,7 @@
 
     void html_encoder::operator()(quickbook::state& state, hr)
     {
- state.phrase << markup_map.at("hr").pre;
+ state.phrase << get_markup("hr").pre;
     }
 
     void html_encoder::operator()(quickbook::state& state, begin_section2 const& x)
@@ -277,7 +284,7 @@
 
         state.phrase << "<dl>\n";
 
- html_markup m = markup_map.at("varlistentry");
+ html_markup m = get_markup("varlistentry");
 
         for(std::vector<varlistentry>::const_iterator
             it = x.entries.begin(); it != x.entries.end(); ++it)
@@ -310,7 +317,7 @@
             state.phrase << ">\n";
         }
 
- html_markup m = markup_map.at("row");
+ html_markup m = get_markup("row");
 
         if (x.head)
         {

Modified: branches/quickbook-1.5-spirit2/rule_store.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/rule_store.hpp (original)
+++ branches/quickbook-1.5-spirit2/rule_store.hpp 2010-03-06 05:47:44 EST (Sat, 06 Mar 2010)
@@ -16,6 +16,7 @@
 
 #include <deque>
 #include <boost/assert.hpp>
+#include <utility>
 
 namespace quickbook
 {
@@ -29,7 +30,7 @@
         struct scoped_void
         {
             void* ptr_;
- void (*del_)(void* x);
+ void (*del_)(void*);
             
             scoped_void() : ptr_(0), del_(0) {}
             scoped_void(scoped_void const& src) : ptr_(0), del_(0) {
@@ -39,13 +40,9 @@
                 if(ptr_) del_(ptr_);
             }
             
- template <typename T>
- T* instantiate() {
- T* obj;
-
- del_ = &delete_impl<T>;
- ptr_ = obj = new T();
- return obj;
+ void store(void* ptr, void (*del)(void* x)) {
+ ptr = ptr_;
+ del = del_;
             }
         private:
             scoped_void& operator=(scoped_void const&);
@@ -61,15 +58,19 @@
             
             template <typename T>
             operator T&() {
+ std::auto_ptr<T> obj(new T());
+ T& ref = *obj;
                 s.store_.push_back(detail::scoped_void());
- return *s.store_.back().instantiate<T>();
+ s.store_.back().store(obj.release(), &detail::delete_impl<T>);
+ return ref;
             }
         };
 
         rule_store() {}
 
         instantiate create() {
- return instantiate(*this);
+ instantiate i(*this);
+ return i;
         }
 
         std::deque<detail::scoped_void> store_;


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