blob: 94d3bc10727eae869d979a791fdddcbf1344c1ea [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
William A. Kennington IIIa4f71f92022-08-18 14:17:00 -07009FormatBuffer::FormatBuffer(Fd& fd, size_t max) : fd(fd), max(max)
William A. Kennington III4f5711c2022-08-12 17:01:53 -070010{
11}
12
13FormatBuffer::~FormatBuffer() noexcept(false)
14{
15 flush();
16}
17
18void FormatBuffer::flush()
19{
20 if (buf.size() > 0)
21 {
William A. Kennington IIIa4f71f92022-08-18 14:17:00 -070022 writeExact(fd, buf);
William A. Kennington III4f5711c2022-08-12 17:01:53 -070023 buf.clear();
24 }
25}
26
27void FormatBuffer::writeIfNeeded()
28{
29 if (buf.size() >= max)
30 {
31 flush();
32 }
33}
34
William A. Kennington III4f5711c2022-08-12 17:01:53 -070035} // namespace fd
36} // namespace stdplus