| 14 | StreamOutputBuffer(std::ostream& stream) : stream(&stream) { pos = 0; } |
| 15 | |
| 16 | void write(const char* content, size_t length) { |
| 17 | if (pos + length > STREAM_OUTPUT_BUFFER_SIZE) { |
| 18 | const size_t n_avail = STREAM_OUTPUT_BUFFER_SIZE - pos; |
| 19 | write_core(content, n_avail); |
| 20 | length -= n_avail; |
| 21 | content += n_avail; |
| 22 | flush(); |
| 23 | if (length > STREAM_OUTPUT_BUFFER_SIZE) { |
| 24 | stream->write(content, length); |
| 25 | return; |
| 26 | } |
| 27 | } |
| 28 | write_core(content, length); |
| 29 | } |
| 30 | |
| 31 | void write_char(const char ch) { |
| 32 | if (pos == STREAM_OUTPUT_BUFFER_SIZE) { |