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? TIA, -- Daniel Schlyder http://bitblaze.com/
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
participants (2)
-
Daniel Schlyder
-
Jonathan Turkanis