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