开发者

How do I build a filtered_streambuf based on basic_streambuf?

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 tha开发者_JAVA技巧t 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?


Boost.Iostreams may be useful to you.

From the documentation:

Boost.Iostreams has three aims:

  • To make it easy to create standard C++ streams and stream buffers for accessing new Sources and Sinks.
  • To provide a framework for defining Filters and attaching them to standard streams and stream buffers.
  • To provide a collection of ready-to-use Filters, Sources and Sinks.

I've barely used that libary myself, so I can't comment any further.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜