Boost logo

Boost Users :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-12-30 12:55:45


Daniel Schlyder wrote:
> Hi,
>
> I have a class derived from boost::io::sink that I use as follows:
>
> boost::io::stream_facade<printsink> os;
> os << "foo" << std::flush;
> os->set_colour(255, 255, 0);
> os << "bar";
>
> How can I flush the buffer in set_colour() method instead of
> requiring the user to do it?

Very good question!

There is currently no way to access the stream_facade from the policy class.
While I could provide a means to do this, I suspect it might lead to problems
with buffer synchronization, or worse, to accidental recursion and stack
overflow.

The best way to handle this problem is to derive a print_stream from
stream_facade<printsink>. You can then use operator-> to access the policy class
so that you can define a member function set_colour which flushes the stream
before setting the color.

For the new docs, I'm planning to write a 'case study' on writing streams which
derive from stream_facade or filtering_stream. I'm also going to allow direct
access to the filters and devices in a chain, using an interface patterned on
TR1 function target access.

Jonathan


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