stackbuf move ctor

This commit is contained in:
gabime
2014-05-06 17:38:11 +03:00
parent 3463dcd1aa
commit b72098101e
6 changed files with 52 additions and 40 deletions

View File

@@ -39,18 +39,23 @@ public:
line_logger& operator=(const line_logger&) = delete;
line_logger& operator=(line_logger&&) = delete;
line_logger(line_logger&& other) :
_callback_logger(other._callback_logger),
_log_msg(other._log_msg),
// The move ctor should only be called on start of logging line,
// where no logging happened yet for this line so no need to copy the oss from the other
_oss(),
_enabled(other._enabled) {}
_log_msg(std::move(other._log_msg)),
_oss(std::move(other._oss)),
_enabled(other._enabled),
_empty(other._empty)
{
other.disable();
}
~line_logger()
{
//only if enabled and not empty
if (!_empty)
if (_enabled && !_empty)
{
_oss << os::eol();
_log_msg.msg_buf = _oss.buf();
@@ -75,6 +80,11 @@ public:
return *this;
}
void disable()
{
_enabled = false;
}
private: