blob: fc6392d7b667cba73048d44a2bbba34c0c84886c [file] [log] [blame]
William A. Kennington III4f5711c2022-08-12 17:01:53 -07001#include <stdplus/fd/fmt.hpp>
2#include <stdplus/fd/ops.hpp>
3
4namespace stdplus
5{
6namespace fd
7{
8
9FormatBuffer::FormatBuffer(stdplus::Fd& fd, size_t max) : fd(fd), max(max)
10{
11}
12
13FormatBuffer::~FormatBuffer() noexcept(false)
14{
15 flush();
16}
17
18void FormatBuffer::flush()
19{
20 if (buf.size() > 0)
21 {
22 stdplus::fd::write(fd, buf);
23 buf.clear();
24 }
25}
26
27void FormatBuffer::writeIfNeeded()
28{
29 if (buf.size() >= max)
30 {
31 flush();
32 }
33}
34
35} // namespace fd
36} // namespace stdplus