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