blob: 1907dedd09e9013b27063be80b5e0010bbec2335 [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
Patrick Williamsd1984dd2023-05-10 16:12:44 -05009FormatBuffer::FormatBuffer(Fd& fd, size_t max) : fd(fd), max(max) {}
William A. Kennington III4f5711c2022-08-12 17:01:53 -070010
11FormatBuffer::~FormatBuffer() noexcept(false)
12{
13 flush();
14}
15
16void FormatBuffer::flush()
17{
18 if (buf.size() > 0)
19 {
William A. Kennington IIIa4f71f92022-08-18 14:17:00 -070020 writeExact(fd, buf);
William A. Kennington III4f5711c2022-08-12 17:01:53 -070021 buf.clear();
22 }
23}
24
25void FormatBuffer::writeIfNeeded()
26{
27 if (buf.size() >= max)
28 {
29 flush();
30 }
31}
32
William A. Kennington III4f5711c2022-08-12 17:01:53 -070033} // namespace fd
34} // namespace stdplus