How do I build a filtered_streambuf based on basic_streambuf?
Posted
by swestrup
on Stack Overflow
See other posts from Stack Overflow
or by swestrup
Published on 2010-04-20T21:18:56Z
Indexed on
2010/04/20
21:23 UTC
Read the original article
Hit count: 256
I have a project that requires me to insert a filter into a stream so that outgoing data will be modified according to the filter. After some research, it seems that what I want to do is create a filtered_streambuf like this:
template <class StreamBuf>
class filtered_streambuf: public StreamBuf
{ ... }
And then insert a filtered_streambuf<>
into whichever stream I need to be filtered. My problem is that I don't know what invariants I need to maintain while filtering a stream, in order to ensure that
- Derived classes can work as expected. In particular, I may find I have filtered_streambufs built over other filtered_streambufs.
- All the various stream inserters, extractors and manipulators work as expected.
The trouble is that I just can't seem to work out what the minimal interface is that I need to supply in order to guarantee that an iostream will have what it needs to work correctly.
In particular, do I need to fake the movement of the protected pointer variables, or not? Do I need a fake data buffer, or not? Can I just override the public functions, rewriting them in terms of the base streambuf, or is that too simplistic?
© Stack Overflow or respective owner