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 | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 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 +struct Tie: public streambuf { // MSVC requires splitted streambuf for cin and cout + + Tie(streambuf* b, ofstream* f) : buf(b), file(f) {} + + 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(), ">> "); } + + streambuf* buf; + ofstream* file; + + int log(int c, const char* prefix) { + + static int last = '\n'; + + if (last == '\n') + file->rdbuf()->sputn(prefix, 3); + + return last = file->rdbuf()->sputc((char)c); + } +}; + class Logger { - Logger() : in(cin.rdbuf(), file), out(cout.rdbuf(), file) {} - ~Logger() { start(false); } - - struct Tie: public streambuf { // MSVC requires splitted streambuf for cin and cout - - Tie(streambuf* b, ofstream& f) : buf(b), file(f) {} - - 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) { - - static int last = '\n'; - - if (last == '\n') - file.rdbuf()->sputn(prefix, 3); - - return last = file.rdbuf()->sputc((char)c); - } - - streambuf* buf; - ofstream& file; - }; + Logger() : in(cin.rdbuf(), &file), out(cout.rdbuf(), &file) {} + ~Logger() { start(false); } ofstream file; Tie in, out;