This fixes a bug manifesting in builder where a put call that triggers a
BufferedFile's buffer flush causes the buffer contents to be written to
the file twice.
namespace Msp {
namespace IO {
+// XXX This needs a redesign
template<typename B, typename F>
class Filtered: public B
{
}
public:
- virtual unsigned put(char c) { return filter.put(c); }
- virtual bool getline(std::string &l) { return filter.getline(l); }
- virtual int get() { return filter.get(); }
+ virtual unsigned put(char c)
+ {
+ if(active)
+ return B::put(c);
+
+ Activator a(*this);
+ return filter.put(c);
+ }
+
+ virtual bool getline(std::string &l)
+ {
+ if(active)
+ return B::getline(l);
+
+ Activator a(*this);
+ return filter.getline(l);
+ }
+
+ virtual int get()
+ {
+ if(active)
+ return B::get();
+
+ Activator a(*this);
+ return filter.get();
+ }
F &get_filter() { return filter; }
};