Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-11-24 16:23:06


"Reece Dunn" <msclrhd_at_[hidden]> wrote in message
news:co2o7c$ms8$1_at_sea.gmane.org...
> Jeff Flinn wrote:
> > Jonathan,
> >
> > Just to let you know the apply_if -> eval_if changes that I previously
> > mentioned were sufficient in my case to utilize your library with boost
> > 1.32.0.
>
> I can confirm this, as I am using it myself. However, msvc-8.0 requires
> inclusion of <ios> in the file
boost/io/detail/streambufs/linked_streambuf.hpp to fix an error at line 54.

Thanks -- I'll make a note of this. I have 8.0 beta now, and it seems to be much
better behaved in some respects. I'm getting a lot fewer ICEs and out of
resource type errors.

> > The library is used to 'wrap' MFC non-standard facilities for
> > cut/copy/paste and drag/drop for use with Robert's serialization library. In
> > this case I am not using many of the more advanced features of your library
> > (yet).
>
> I am playing around with the library. Here are a few thoughts:
>
> [1] And is it possible to access Sink members from stream_facade, for
> example:
>
> stream_facade< speech_reader > speech;
> speech.set_pitch( 50 );
> speech.set_voice( "LH Michelle" );
> speech << "This is the Lernout & Hauspie Michelle voice.\n"

This would require stream_facade to derive from the policy class, which I didn't
do for several reasons. The way to access the policy is with operators * or ->:

  stream_facade< speech_reader > speech;
  speech->set_pitch( 50 );
  // Or: (*speech).set_pitch( 50 );

> [2] I would like to collapse:
>
> std::ofstream out( "encoded.txt" );
> boost::io::filtering_ostream os;
> os.push( ascii85_encoder());
> os.push( out );
> os << ...;
>
> to:
>
> class ascii85_ofstream: public boost::io::filtering_ostream
> {
> std::ofstream out;
> public:
> ascii85_ofstream( const char * fn ): out( fn )
> {
> push( ascii85_encoder());
> push( out );
> }
> };
>
> ascii85_ofstream os( "encoded.txt" );
> os << ...;

Yes, this is certainly one of the intended uses of the library.

> but this results in a crash at the destructor (tested with msvc-8.0).
>
> Maybe if filtering_ostream takes a bool denoting if it closes on the
> destructor (default to true), so I could do:
>
> ascii85_ofstream::ascii85_ofstream( const char * fn ):
> filtering_ostream( false ),
> out( fn )
> {
> push( ascii85_encoder());
> push( out );
> }
>
> ascii85_ofstream::~ascii85_ofstream()
> {
> close();
> }

I believe the problem is that the filtering_ostream (a base class) is accessing
the ofstream (a member of a derived class) after the ofstream has been
destroyed. This would be unacceptable even if filtering_ostream had a
no-close-on-exit option. I believe the solution is to pop the ofstream in the
ascii85_ofstream destructor.

     ascii85_ofstream::~ascii85_ofstream()
     {
        pop(); // Or: reset();
     }

Please let me know if this works.

> Regards,
> Reece

Jonathan


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