如何基于basic_streambuf构建filtered_streambuf?
我有一个项目,要求我将过滤器插入流中,以便根据过滤器修改传出数据。经过一番研究,我似乎想要做的是创建一个像这样的filtered_streambuf:
template <class StreamBuf>
class filtered_streambuf: public StreamBuf
{ ... }
然后将filtered_streambuf<>
插入到我需要过滤的任何流中。我的问题是,我不知道在过滤流时需要维护哪些不变量,以确保
- 派生类可以按预期工作。特别是,我可能会发现我已经在其他filtered_streambufs上构建了filtered_streambufs。
- 所有各种流插入器、提取器和操纵器都按预期工作。
问题是我似乎无法弄清楚我需要提供什么最小接口才能保证 iostream 拥有正常工作所需的功能。
特别是,我是否需要伪造受保护指针变量的移动?我是否需要一个假数据缓冲区?我可以重写公共函数,根据基本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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Boost.Iostreams 可能对您有用。
从文档中:
我自己几乎没有使用过该库,所以我无法进一步发表评论。
Boost.Iostreams may be useful to you.
From the documentation:
I've barely used that libary myself, so I can't comment any further.