spdlog/include/c11log/details/fast_oss.h

74 lines
1.4 KiB
C
Raw Normal View History

2014-01-25 04:09:04 -05:00
#pragma once
#include<streambuf>
#include<string>
namespace c11log {
namespace details {
class str_devicebuf:public std::streambuf {
public:
2014-02-03 13:28:19 -05:00
str_devicebuf() = default;
~str_devicebuf() = default;
str_devicebuf(const str_devicebuf&) = delete;
str_devicebuf& operator=(const str_devicebuf&) = delete;
2014-01-25 04:09:04 -05:00
2014-02-03 13:28:19 -05:00
const std::string& str_ref() const
2014-01-25 04:09:04 -05:00
{
return _str;
}
void clear()
{
_str.clear();
}
protected:
virtual int sync() override
{
return 0;
}
virtual std::streamsize xsputn(const char_type* s, std::streamsize count) override
{
_str.append(s, static_cast<unsigned int>(count));
return count;
}
virtual int_type overflow(int_type ch) override
{
if (ch != traits_type::eof())
_str.append((char*)&ch, 1);
return 1;
}
private:
std::string _str;
};
class fast_oss:public std::ostream {
public:
2014-02-03 13:28:19 -05:00
fast_oss():std::ostream(&_dev){}
~fast_oss() = default;
fast_oss(const fast_oss&) = delete;
fast_oss operator=(const fast_oss&) = delete;
2014-01-25 04:09:04 -05:00
const std::string& str_ref() const
2014-02-03 13:28:19 -05:00
{
return _dev.str_ref();
2014-01-25 04:09:04 -05:00
}
const std::string str() const
2014-02-03 13:28:19 -05:00
{
return _dev.str_ref();
2014-01-25 04:09:04 -05:00
}
void clear()
{
2014-02-03 13:28:19 -05:00
_dev.clear();
2014-01-25 04:09:04 -05:00
}
private:
str_devicebuf _dev;
};
}
2014-02-03 13:28:19 -05:00
}