mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
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 <mcostalba@gmail.com>
This commit is contained in:
parent
6b5322ce00
commit
6becc81446
1 changed files with 25 additions and 25 deletions
24
src/misc.cpp
24
src/misc.cpp
|
@ -94,34 +94,34 @@ void dbg_print() {
|
||||||
/// usual i/o functionality and without changing a single line of code!
|
/// usual i/o functionality and without changing a single line of code!
|
||||||
/// Idea from http://groups.google.com/group/comp.lang.c++/msg/1d941c0f26ea0d81
|
/// Idea from http://groups.google.com/group/comp.lang.c++/msg/1d941c0f26ea0d81
|
||||||
|
|
||||||
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
|
struct Tie: public streambuf { // MSVC requires splitted streambuf for cin and cout
|
||||||
|
|
||||||
Tie(streambuf* b, ofstream& f) : buf(b), file(f) {}
|
Tie(streambuf* b, ofstream* f) : buf(b), file(f) {}
|
||||||
|
|
||||||
int sync() { return file.rdbuf()->pubsync(), buf->pubsync(); }
|
int sync() { return file->rdbuf()->pubsync(), buf->pubsync(); }
|
||||||
int overflow(int c) { return log(buf->sputc((char)c), "<< "); }
|
int overflow(int c) { return log(buf->sputc((char)c), "<< "); }
|
||||||
int underflow() { return buf->sgetc(); }
|
int underflow() { return buf->sgetc(); }
|
||||||
int uflow() { return log(buf->sbumpc(), ">> "); }
|
int uflow() { return log(buf->sbumpc(), ">> "); }
|
||||||
|
|
||||||
|
streambuf* buf;
|
||||||
|
ofstream* file;
|
||||||
|
|
||||||
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')
|
if (last == '\n')
|
||||||
file.rdbuf()->sputn(prefix, 3);
|
file->rdbuf()->sputn(prefix, 3);
|
||||||
|
|
||||||
return last = file.rdbuf()->sputc((char)c);
|
return last = file->rdbuf()->sputc((char)c);
|
||||||
}
|
}
|
||||||
|
|
||||||
streambuf* buf;
|
|
||||||
ofstream& file;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Logger {
|
||||||
|
|
||||||
|
Logger() : in(cin.rdbuf(), &file), out(cout.rdbuf(), &file) {}
|
||||||
|
~Logger() { start(false); }
|
||||||
|
|
||||||
ofstream file;
|
ofstream file;
|
||||||
Tie in, out;
|
Tie in, out;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue