Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-06-02 07:01:38


"Jonathan Turkanis" <technews_at_[hidden]> writes:

> "David Abrahams" <dave_at_[hidden]> wrote in message
> news:uisebatkh.fsf_at_boost-consulting.com...
>> slavek.f.kuzniar_at_[hidden] writes:
>>
>> > The previous version available at
>> > http://www.xmission.com/~turkanis/iostreams/.
>> >
>> > I've since made some major simplifications and improvements, and
> am
>> > scrambing to update the docs. It now contains support for
>> > memory-mapped files (from Craig Henderson) and for compression and
>> > decompression in the zlib, gzip and bzip2 formats.
>>
>> The thing I wanted recently was an "offset streambuf", an adapter
>> for another streambuf that presents an "offset view" (i.e. with
>> respect to seeking) of the underlying streambuf.
>
> This sounds like it might be a job for a 'SeekableFilter' -- something
> I included support for even though I didn't have any use for it. The
> interface for a seekable filter is basically this:
>
> struct seekable_filter {
> // some typedefs
> streamsize read(char* s, streamsize n, streambuf& next);
> void write(const char* s, streamsize n, streambuf& next);
> streamoff seek(streamoff off, ios_base::seekdir way,
> streambuf& next);
> };
>
> Here 'next' is the streambuf being filtered. Any number of filters can
> be chained.

I didn't really think of this as a "filtering" operation, but anyway...

> You take a filtering_streambuf<seekable>, add your filter, then add
> the underlying streambuf:
>
> filtering_streambuf<seekable> filtered;
> filtered.push(seekable_filter());
> filtered.push(sbuf);
>
> What exactly did you want the offset streambuf to do?

I wanted to represent a region of offsets in the underlying streambuf
as the whole stream. So, for example,

   void operate_on_region(streambuf& s)
   {
      region_streambuf s1(s, 500, 1000); // a stream over 500 bytes of s
      s1.pubseekpos(10); // I probably don't have this call quite right
      traits::int_type c = s1.sbumpc(); // reads byte 510 from s
   }

Obviously I would want it to work for all the other seeking
operations.

> I'd be interested to see if I can implement it using the above
> framework.

Me too ;-)

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk