Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r70549 - in trunk/boost/spirit/home/qi/stream: . detail
From: hartmut.kaiser_at_[hidden]
Date: 2011-03-25 20:55:05


Author: hkaiser
Date: 2011-03-25 20:55:03 EDT (Fri, 25 Mar 2011)
New Revision: 70549
URL: http://svn.boost.org/trac/boost/changeset/70549

Log:
Spirit: fixing iterator handling in stream parser
Text files modified:
   trunk/boost/spirit/home/qi/stream/detail/iterator_source.hpp | 27 +++++++++++++++++++++++----
   trunk/boost/spirit/home/qi/stream/stream.hpp | 8 +++++++-
   2 files changed, 30 insertions(+), 5 deletions(-)

Modified: trunk/boost/spirit/home/qi/stream/detail/iterator_source.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/stream/detail/iterator_source.hpp (original)
+++ trunk/boost/spirit/home/qi/stream/detail/iterator_source.hpp 2011-03-25 20:55:03 EDT (Fri, 25 Mar 2011)
@@ -24,10 +24,10 @@
         typedef typename
             boost::detail::iterator_traits<Iterator>::value_type
         char_type;
- typedef boost::iostreams::source_tag category;
+ typedef boost::iostreams::seekable_device_tag category;
 
- iterator_source (Iterator& first_, Iterator const& last_)
- : first(first_), last(last_)
+ iterator_source (Iterator const& first_, Iterator const& last_)
+ : first(first_), last(last_), pos(0)
         {}
 
         // Read up to n characters from the input sequence into the buffer s,
@@ -45,11 +45,30 @@
                 if (++first == last)
                     break;
             }
+
+ pos += bytes_read;
             return bytes_read;
         }
 
- Iterator& first;
+ // Write is implemented only to satisfy the requirements of a
+ // boost::iostreams::seekable_device. We need to have see support to
+ // be able to figure out how many characters have been actually
+ // consumed by the stream.
+ std::streamsize write(const char*, std::streamsize)
+ {
+ BOOST_ASSERT(false); // not supported
+ return -1;
+ }
+
+ std::streampos seek(boost::iostreams::stream_offset, std::ios_base::seekdir way)
+ {
+ BOOST_ASSERT(way == std::ios_base::cur); // only support queries
+ return pos; // return current position
+ }
+
+ Iterator first;
         Iterator const& last;
+ std::streamsize pos;
 
     private:
         // silence MSVC warning C4512: assignment operator could not be generated

Modified: trunk/boost/spirit/home/qi/stream/stream.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/stream/stream.hpp (original)
+++ trunk/boost/spirit/home/qi/stream/stream.hpp 2011-03-25 20:55:03 EDT (Fri, 25 Mar 2011)
@@ -64,8 +64,14 @@
             typedef boost::iostreams::stream<source_device> instream;
 
             qi::skip_over(first, last, skipper);
- instream in(first, last);
+
+ instream in(first, last); // copies 'first'
             in >> attr; // use existing operator>>()
+
+ // advance the iterator if everything is ok
+ if (in.good())
+ std::advance(first, in.tellg());
+
             return in.good() || in.eof();
         }
 


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