From 43a7280153efb239d74a902200f0a10c47c5de7a Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 20 Apr 2013 17:19:55 +0300 Subject: [PATCH] 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. --- source/io/filtered.h | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) 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; } }; -- 2.43.0