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