Stream buffer that wraps lines on white-space characters at the specified line length, and with support for indentation.
More...
#include <ookii/line_wrapping_stream.h>
|
using | base_type = std::basic_streambuf< CharType, Traits > |
| The concrete type that this class derives from.
|
|
using | char_type = typename base_type::char_type |
| Character type used by the base type.
|
|
using | int_type = typename base_type::int_type |
| Integer type used by the base type.
|
|
using | traits_type = typename base_type::traits_type |
| Traits type used by the base type.
|
|
|
virtual void | imbue (const std::locale &loc) override |
| Change the locale of the stream buffer. More...
|
|
virtual int_type | overflow (int_type ch=traits_type::eof()) override |
| Ensure there is space to write at least one character to the buffer. More...
|
|
virtual int | sync () override |
| Flushes the buffer to the underlying stream buffer. More...
|
|
template<typename CharType, typename Traits = std::char_traits<CharType>>
class ookii::basic_line_wrapping_streambuf< CharType, Traits >
Stream buffer that wraps lines on white-space characters at the specified line length, and with support for indentation.
This stream buffer writes its output to another stream buffer, which could belong to any stream (like a file stream, or string stream).
- Warning
- This class assumes that the target stream buffer is at the start of a line when writing starts, and that no other users are writing to the same stream buffer. Otherwise, output will not be correctly wrapped or indented.
-
Syncing this buffer will not flush the contents of the last unfinished line. Use sync() with the
flush_last_line
parameter set to true
to make sure all content is flushed (this may insert an additional new line character).
Several typedefs for common character types are provided:
- Template Parameters
-
CharType | The type of characters used by the target stream buffer. |
Traits | The character traits used by the target stream buffer. |
◆ basic_line_wrapping_streambuf() [1/2]
template<typename CharType , typename Traits = std::char_traits<CharType>>
◆ basic_line_wrapping_streambuf() [2/2]
template<typename CharType , typename Traits = std::char_traits<CharType>>
Initializes a new instance of the basic_line_wrapping_streambuf class with the specified underlying stream buffer and maximum line length.
- Parameters
-
streambuf | The stream buffer to write output to. |
max_line_length | The maximum line length, or a value of 0 or larger than 65536 to specify no limit. Use the use_console_width constant to use the console width as the maximum. |
◆ ~basic_line_wrapping_streambuf()
template<typename CharType , typename Traits = std::char_traits<CharType>>
◆ imbue()
template<typename CharType , typename Traits = std::char_traits<CharType>>
|
inlineoverrideprotectedvirtual |
Change the locale of the stream buffer.
- Parameters
-
◆ indent()
template<typename CharType , typename Traits = std::char_traits<CharType>>
Sets the number of spaces that each line is indented with.
- Parameters
-
indent | The new indentation size. |
◆ init()
template<typename CharType , typename Traits = std::char_traits<CharType>>
Initializes this basic_line_wrapping_streambuf instance with the specified underlying stream buffer and maximum line length.
- Parameters
-
streambuf | The stream buffer to write output to. |
max_line_length | The maximum line length, or a value of 0 or larger than 65536 to specify no limit. Use the use_console_width constant to use the console width as the maximum. |
count_formatting | Include virtual terminal sequences when calculating the length of a line. |
◆ overflow()
template<typename CharType , typename Traits = std::char_traits<CharType>>
|
inlineoverrideprotectedvirtual |
Ensure there is space to write at least one character to the buffer.
Called when there is no more space in the buffer, or when sync() is called.
- Attention
- This function flushes the buffer to the underlying stream buffer, wrapping lines and adding indent as necessary. The passed character, if not eof, will be added to the buffer afterwards.
- Parameters
-
ch | The character to put in the buffer. |
- Returns
- A value not equal to
Traits::eof()
on success, and Traits::eof()
on failure.
◆ reset_indent()
template<typename CharType , typename Traits = std::char_traits<CharType>>
Disables indentation for the next line.
- Warning
- If the last character written to the buffer was not a new line, one is inserted.
- Returns
false
if a new line character was needed but could not be written; otherwise, true
.
◆ swap()
template<typename CharType , typename Traits = std::char_traits<CharType>>
◆ sync() [1/2]
template<typename CharType , typename Traits = std::char_traits<CharType>>
|
inlineoverrideprotectedvirtual |
Flushes the buffer to the underlying stream buffer.
If the buffer contains a line that's shorter than the maximum and was not terminated by a line break, this function will not flush that final line, because doing so would make it impossible to find the correct place to wrap the line later if that place was already flushed.
- Returns
- The result of calling
pubsync()
on the underlying stream buffer.
◆ sync() [2/2]
template<typename CharType , typename Traits = std::char_traits<CharType>>
Flushes the buffer to the underlying stream buffer, optionally including the the final, partial line.
If the buffer contains a line that's shorter than the maximum and was not terminated by a line break, the normal pubsync()
function will not flush that final line, because doing so would make it impossible to find the correct place to break the line later if that place was already flushed.
This function offers the ability to flush the buffer including the last line. If there is a non-empty, non-terminated line in the buffer, that line will be flushed, followed by a line break.
- Parameters
-
flush_last_line | true to flush the final non-terminated line; false to leave that line in the buffer. |
- Returns
- The result of calling
pubsync()
on the underlying stream buffer.
The documentation for this class was generated from the following file: