|
Boost Users : |
Subject: Re: [Boost-users] [iostreams] How can I use the Stream Insertion operator (<<) with a filtering_streambuf?
From: Larry Evans (cppljevans_at_[hidden])
Date: 2013-08-01 14:39:31
On 07/31/13 07:16, Larry Evans wrote:
> On 07/30/13 13:59, Larry Evans wrote:
>> On 07/29/13 11:27, Larry Evans wrote:
>>> On 07/29/13 11:10, Larry Evans wrote:
>>> [snip]
>>>> BTW, I tried modifying Ken's code to use filtering_ostream instead
>>>> of filtering_streambuf, and it worked. I also removed the ios_base
>>>> flags and it still worked. Then I tried using stringstream instead
>>>> of filestream and it no longer worked. Anyone have any clues about
>>>> why stringstream doesn't work? The code is attached. With the
>>>> attached code and attached Jamfile.v2, and with:
>>>>
>>>> #define USE_STRINGSTRM
>>>>
>>>> in the code, the KenApplebyStrm.output produced by bjam is
>>>> in the next attachment.
>>>> In contrast, with:
>>>> //#define USE_STRINGSTRM
>>>> int the code, the KenApplebyStrm.output produced by bjam is
>>>> in the last attachment.
>>> [snip]
>>> OOPS. The code attached previously used streambuf instead of
>>> stream. The current attachment uses stream.
>>
>> Based on running the attached both with:
>>
>> #define USE_FILT_COMPRESS
>>
>> then with:
>>
>> //#define USE_FILT_COMPRESS
>>
>> on line 40 showed that using the gzip_decompressor starts reading
>> at the end of the stream instead of at the beginning.
>>
>> The corresponding outputs are also attached.
>>
>> This contrasts with the count filter which starts reading, as one
>> would expect, at the beginning of the stream.
>>
>> Still trying to track down why.
>>
> Changing the:
>
> out.flush()
>
> around line 93 to:
>
> out.strict_sync();
>
> which is described here:
>
> http://www.boost.org/doc/libs/1_54_0/libs/iostreams/doc/classes/filtering_stream.html#sync
>
> failed to solve problem :(
> Still trying to track down why.
>
Maybe the reason is the filter's are not flushable.
However, even though the counter filter is also not flushable,
the output turns out OK.
Finally, I read about reset and pop:
http://www.boost.org/doc/libs/1_54_0/libs/iostreams/doc/classes/filtering_stream.html#pop
and both worked to get proper value for actual_out in the
attached.
The root cause of my difficulties was my assumptions about
what out.flush() or out.strict_sync() should have done,
and not reading about reset or pop. However, my excuse
was that flush and sync are names with pretty much
standard meanings; yet, with iostreams, those meanings
don't apply completely :(.
Hopefully this will help others running into the same
problem.
-regards,
Larry
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net