stackbuf move ctor
This commit is contained in:
		@@ -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:
 | 
			
		||||
 
 | 
			
		||||
@@ -7,15 +7,8 @@ namespace details
 | 
			
		||||
struct log_msg
 | 
			
		||||
{
 | 
			
		||||
    log_msg() = default;
 | 
			
		||||
    log_msg(level::level_enum l):msg_level(l) {};
 | 
			
		||||
    log_msg(const log_msg& other)
 | 
			
		||||
    {
 | 
			
		||||
        msg_buf = other.msg_buf;
 | 
			
		||||
        msg_time = other.msg_time;
 | 
			
		||||
        msg_header_size = other.msg_header_size;
 | 
			
		||||
        msg_level = other.msg_level;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    log_msg(level::level_enum l):msg_level(l) {};    
 | 
			
		||||
    
 | 
			
		||||
    bufpair_t msg_buf;
 | 
			
		||||
    log_clock::time_point msg_time;
 | 
			
		||||
    std::size_t msg_header_size;
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,6 @@
 | 
			
		||||
// Fast memory storage
 | 
			
		||||
// stores its contents on the stack when possible, in vector<char> otherwise
 | 
			
		||||
// NOTE: User should be remember that returned buffer might be on the stack!!
 | 
			
		||||
 | 
			
		||||
namespace c11log
 | 
			
		||||
{
 | 
			
		||||
namespace details
 | 
			
		||||
@@ -18,9 +17,12 @@ template<std::size_t STACK_SIZE=128>
 | 
			
		||||
class stack_buf
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    stack_buf():_stack_size(0) {}
 | 
			
		||||
    stack_buf():_v(),_stack_buf(), _stack_size(0) {}
 | 
			
		||||
    ~stack_buf() {};
 | 
			
		||||
 | 
			
		||||
	stack_buf& operator=(const stack_buf other) = delete;
 | 
			
		||||
    stack_buf& operator=(stack_buf&& other) = delete;
 | 
			
		||||
 | 
			
		||||
    stack_buf(const bufpair_t& buf_to_copy):stack_buf()
 | 
			
		||||
    {
 | 
			
		||||
        append(buf_to_copy);
 | 
			
		||||
@@ -36,18 +38,15 @@ public:
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    stack_buf(stack_buf&& other)
 | 
			
		||||
    {
 | 
			
		||||
    {	
 | 
			
		||||
        _stack_size = other._stack_size;
 | 
			
		||||
        if(!other._v.empty())
 | 
			
		||||
            _v = other._v;
 | 
			
		||||
            _v = std::move(other._v);
 | 
			
		||||
        else if(_stack_size)
 | 
			
		||||
            std::copy(other._stack_buf.begin(), other._stack_buf.begin()+_stack_size, _stack_buf.begin());
 | 
			
		||||
        other.clear();
 | 
			
		||||
		other.clear();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    stack_buf& operator=(const stack_buf& other) = delete;
 | 
			
		||||
    stack_buf& operator=(stack_buf&& other) = delete;
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    void append(const char* buf, std::size_t buf_size)
 | 
			
		||||
    {
 | 
			
		||||
        //If we are aleady using _v, forget about the stack
 | 
			
		||||
 
 | 
			
		||||
@@ -16,10 +16,15 @@ public:
 | 
			
		||||
    stack_devicebuf() = default;
 | 
			
		||||
    ~stack_devicebuf() = default;
 | 
			
		||||
 | 
			
		||||
    stack_devicebuf(const stack_devicebuf& other) = delete;
 | 
			
		||||
    stack_devicebuf(stack_devicebuf&& other) = delete;
 | 
			
		||||
    stack_devicebuf& operator=(const stack_devicebuf&) = delete;
 | 
			
		||||
    stack_devicebuf& operator=(stack_devicebuf&&) = delete;
 | 
			
		||||
	stack_devicebuf& operator=(const stack_devicebuf&) = delete;
 | 
			
		||||
 | 
			
		||||
    stack_devicebuf(const stack_devicebuf& other):std::basic_streambuf<char>(),_stackbuf(other._stackbuf)
 | 
			
		||||
	{}
 | 
			
		||||
 | 
			
		||||
	stack_devicebuf(stack_devicebuf&& other):std::basic_streambuf<char>(),_stackbuf(std::move(other._stackbuf))
 | 
			
		||||
	{
 | 
			
		||||
		other.clear();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    bufpair_t buf() const
 | 
			
		||||
    {
 | 
			
		||||
@@ -63,9 +68,16 @@ public:
 | 
			
		||||
    stack_oss():std::ostream(&_dev) {}
 | 
			
		||||
    ~stack_oss() = default;
 | 
			
		||||
 | 
			
		||||
    stack_oss(const stack_oss& other) = delete;
 | 
			
		||||
    stack_oss(stack_oss&& other) = delete;
 | 
			
		||||
    stack_oss& operator=(const stack_oss& other) = delete;
 | 
			
		||||
	stack_oss& operator=(const stack_oss& other) = delete;
 | 
			
		||||
	stack_oss& operator=(const stack_oss&& other) = delete;
 | 
			
		||||
 | 
			
		||||
    stack_oss(const stack_oss& other):std::basic_ios<char>(), std::ostream(&_dev), _dev(other._dev)
 | 
			
		||||
	{}
 | 
			
		||||
 | 
			
		||||
    stack_oss(stack_oss&& other):std::basic_ios<char>(), std::ostream(&_dev), _dev(std::move(other._dev))
 | 
			
		||||
	{
 | 
			
		||||
		other.clear();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    bufpair_t buf() const
 | 
			
		||||
    {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user