From: Mikko Rasa Date: Sat, 20 Apr 2013 14:19:55 +0000 (+0300) Subject: Add activation check to the rest of Filtered's virtual functions X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=commitdiff_plain;h=43a7280153efb239d74a902200f0a10c47c5de7a Add activation check to the rest of Filtered's virtual functions 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. --- diff --git a/source/io/filtered.h b/source/io/filtered.h index 0d323ec..a4a4319 100644 --- a/source/io/filtered.h +++ b/source/io/filtered.h @@ -4,6 +4,7 @@ namespace Msp { namespace IO { +// XXX This needs a redesign template class Filtered: public B { @@ -53,9 +54,32 @@ protected: } 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; } };