You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
spdlog/include/c11log/details/stack_oss.h

90 lines
1.7 KiB
C

12 years ago
#pragma once
// Faster than ostringstream--returns its string by ref
#include <ostream>
12 years ago
#include "c11log/details/stack_buf.h"
12 years ago
namespace c11log
{
namespace details
{
class str_devicebuf:public std::streambuf
{
public:
12 years ago
using Base = std::streambuf;
12 years ago
str_devicebuf() = default;
~str_devicebuf() = default;
str_devicebuf(const str_devicebuf& other) = delete;
str_devicebuf(str_devicebuf&& other) = delete;
str_devicebuf& operator=(const str_devicebuf&) = delete;
str_devicebuf& operator=(str_devicebuf&&) = delete;
12 years ago
12 years ago
bufpair_t buf()
{
12 years ago
return _stackbuf.get();
}
std::size_t size()
{
return _stackbuf.size();
12 years ago
}
12 years ago
void clear()
{
12 years ago
_stackbuf.clear();
12 years ago
}
protected:
// copy the give buffer into the accumulated fast buffer
12 years ago
std::streamsize xsputn(const char_type* s, std::streamsize count) override
12 years ago
{
12 years ago
_stackbuf.append(s, static_cast<unsigned int>(count));
12 years ago
return count;
}
int_type overflow(int_type ch) override
12 years ago
{
if (traits_type::not_eof(ch))
12 years ago
{
char c = traits_type::to_char_type(ch);
xsputn(&c, 1);
}
return ch;
12 years ago
}
private:
12 years ago
stack_buf<192> _stackbuf;
12 years ago
};
12 years ago
class stack_oss:public std::ostream
12 years ago
{
public:
12 years ago
stack_oss():std::ostream(&_dev) {}
~stack_oss() = default;
12 years ago
12 years ago
stack_oss(const stack_oss& other) = delete;
stack_oss(stack_oss&& other) = delete;
stack_oss& operator=(const stack_oss& other) = delete;
12 years ago
bufpair_t buf()
{
return _dev.buf();
}
12 years ago
std::size_t size()
{
return _dev.size();
}
12 years ago
void clear()
12 years ago
{
12 years ago
_dev.clear();
12 years ago
}
private:
str_devicebuf _dev;
};
}
}