Hi all,
I have a class used as a Boost iostream:
boost::iostreams::stream ms;
The my_stream class implements a couple of extra methods (one example being to
insert a block of data in the middle of the stream) however the stream does
not get flushed before the call to these extra functions, which results in
corrupted data:
ms.write("1234", 4);
ms.seekp(-2, std::ios::cur);
ms->insert(2); // my_stream method
This should result in "12__34", but unfortunately because of buffering, the
insert() ends up happening before the write(), leaving you with just "1234".
The problem is solved by flushing the cache all over the place:
ms.write("1234", 4);
ms.flush();
ms.seekp(-2, std::ios::cur);
ms->insert(2);
ms.flush();
However this isn't really ideal. I would rather the insert() function was
able to flush itself before manipulating the underlying stream.
Is this possible? Or am I going about this in entirely the wrong way?? ;-)
Many thanks,
Adam.
--
class my_stream {
public:
typedef char char_type;
typedef io::seekable_device_tag category;
...