Skip to content
Snippets Groups Projects
Commit f7ebb47d authored by René Fritze's avatar René Fritze
Browse files

[logging] move nested class method defs out-of-line

parent 2b4fec7b
No related branches found
No related tags found
No related merge requests found
......@@ -74,21 +74,8 @@ public:
} // Resume
protected:
virtual std::streamsize xsputn(const char_type* s, std::streamsize count)
{
if (enabled())
return BaseType::xsputn(s, count);
// pretend everything was written
return std::streamsize(count);
}
virtual int_type overflow(int_type ch = traits_type::eof())
{
if (enabled())
return BaseType::overflow(ch);
// anything not equal to traits::eof is considered a success
return traits_type::eof() + 1;
}
virtual std::streamsize xsputn(const char_type* s, std::streamsize count);
virtual int_type overflow(int_type ch = traits_type::eof());
private:
inline bool enabled() const
......@@ -105,6 +92,21 @@ private:
PriorityType suspend_priority_;
};
std::streamsize SuspendableStrBuffer::xsputn(const char_type* s, std::streamsize count)
{
if (enabled())
return BaseType::xsputn(s, count);
// pretend everything was written
return std::streamsize(count);
}
SuspendableStrBuffer::int_type SuspendableStrBuffer::overflow(SuspendableStrBuffer::int_type ch)
{
if (enabled())
return BaseType::overflow(ch);
// anything not equal to traits::eof is considered a success
return traits_type::eof() + 1;
}
class LogStream : public std::basic_ostream<char, std::char_traits<char>>
{
......@@ -136,12 +138,7 @@ public:
}
//! dump buffer into file/stream and clear it
virtual LogStream& flush()
{
assert(buffer_);
buffer_->pubsync();
return *this;
}
virtual LogStream& flush();
/** \brief forwards suspend to buffer
* the suspend_priority_ mechanism provides a way to silence streams from 'higher' modules
......@@ -151,7 +148,7 @@ public:
{
assert(buffer_);
buffer_->suspend(priority);
} // Suspend
}
/** \brief start accepting input into the buffer again
* no-op if not suspended
......@@ -164,9 +161,15 @@ public:
private:
SuspendableStrBuffer* buffer_;
}; // LogStream
LogStream& LogStream::flush()
{
assert(buffer_);
buffer_->pubsync();
return *this;
}
//! ostream compatible class wrapping file and console output
class FileLogStream : public LogStream
{
......@@ -184,16 +187,7 @@ private:
std::ofstream& logfile_;
protected:
virtual int sync()
{
// flush buffer into stream
std::cout << str();
std::cout.flush();
logfile_ << str();
logfile_.flush();
str("");
return 0;
}
virtual int sync();
};
public:
......@@ -208,6 +202,17 @@ private:
FileBuffer logBuffer_;
}; // class FileLogStream
int FileLogStream::FileBuffer::sync()
{
// flush buffer into stream
std::cout << str();
std::cout.flush();
logfile_ << str();
logfile_.flush();
str("");
return 0;
}
//! /dev/null
class EmptyLogStream : public LogStream
{
......@@ -221,11 +226,7 @@ private:
}
protected:
virtual int sync()
{
str("");
return 0;
}
virtual int sync();
};
public:
......@@ -240,6 +241,12 @@ private:
EmptyBuffer logBuffer_;
}; // class EmptyLogStream
int EmptyLogStream::EmptyBuffer::sync()
{
str("");
return 0;
}
namespace {
int dev_null_logflag;
EmptyLogStream dev_null(dev_null_logflag);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment