From 6becc8144686b9a40d8dc9d5e0ce4dec28cbcb6a Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sun, 8 Jul 2012 10:22:42 +0100 Subject: [PATCH] Silence a MSVC warning in class Tie With warning level 4 MSVC complains that a default assignment operator could not be generated due to member 'file' is a reference (warning C4512). Use a pointer instead of a reference and move struct Tie outisde class Logger while there. No functional change. Signed-off-by: Marco Costalba --- src/misc.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/misc.cpp b/src/misc.cpp index 0f0fca46..1a092c61 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -94,33 +94,33 @@ void dbg_print() { /// usual i/o functionality and without changing a single line of code! /// Idea from http://groups.google.com/group/comp.lang.c++/msg/1d941c0f26ea0d81 -class Logger { +struct Tie: public streambuf { // MSVC requires splitted streambuf for cin and cout - Logger() : in(cin.rdbuf(), file), out(cout.rdbuf(), file) {} - ~Logger() { start(false); } + Tie(streambuf* b, ofstream* f) : buf(b), file(f) {} - struct Tie: public streambuf { // MSVC requires splitted streambuf for cin and cout + int sync() { return file->rdbuf()->pubsync(), buf->pubsync(); } + int overflow(int c) { return log(buf->sputc((char)c), "<< "); } + int underflow() { return buf->sgetc(); } + int uflow() { return log(buf->sbumpc(), ">> "); } - Tie(streambuf* b, ofstream& f) : buf(b), file(f) {} + streambuf* buf; + ofstream* file; - int sync() { return file.rdbuf()->pubsync(), buf->pubsync(); } - int overflow(int c) { return log(buf->sputc((char)c), "<< "); } - int underflow() { return buf->sgetc(); } - int uflow() { return log(buf->sbumpc(), ">> "); } + int log(int c, const char* prefix) { - int log(int c, const char* prefix) { + static int last = '\n'; - static int last = '\n'; + if (last == '\n') + file->rdbuf()->sputn(prefix, 3); - if (last == '\n') - file.rdbuf()->sputn(prefix, 3); + return last = file->rdbuf()->sputc((char)c); + } +}; - return last = file.rdbuf()->sputc((char)c); - } +class Logger { - streambuf* buf; - ofstream& file; - }; + Logger() : in(cin.rdbuf(), &file), out(cout.rdbuf(), &file) {} + ~Logger() { start(false); } ofstream file; Tie in, out; -- 2.39.2