Ookii.CommandLine for C++  1.0.0
Public Types | Public Member Functions | Protected Member Functions | List of all members
ookii::basic_line_wrapping_streambuf< CharType, Traits > Class Template Reference

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>

Inheritance diagram for ookii::basic_line_wrapping_streambuf< CharType, Traits >:
Inheritance graph
[legend]
Collaboration diagram for ookii::basic_line_wrapping_streambuf< CharType, Traits >:
Collaboration graph
[legend]

Public Types

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.
 

Public Member Functions

 basic_line_wrapping_streambuf () noexcept=default
 Initializes a new instance of the basic_line_wrapping_streambuf class. More...
 
 basic_line_wrapping_streambuf (base_type *streambuf, size_t max_line_length)
 Initializes a new instance of the basic_line_wrapping_streambuf class with the specified underlying stream buffer and maximum line length. More...
 
 basic_line_wrapping_streambuf (basic_line_wrapping_streambuf &&other) noexcept
 Move constructor.
 
 basic_line_wrapping_streambuf (basic_line_wrapping_streambuf &)=delete
 
size_t indent () const
 Gets the current number of spaces that each line is indented with.
 
void indent (size_t indent) noexcept
 Sets the number of spaces that each line is indented with. More...
 
void init (base_type *streambuf, size_t max_line_length) noexcept
 Initializes this basic_line_wrapping_streambuf instance with the specified underlying stream buffer and maximum line length. More...
 
basic_line_wrapping_streambufoperator= (basic_line_wrapping_streambuf &&other) noexcept
 Move assignment operator.
 
basic_line_wrapping_streambufoperator= (basic_line_wrapping_streambuf &)=delete
 
bool reset_indent ()
 Disables indentation for the next line. More...
 
void swap (basic_line_wrapping_streambuf &other) noexcept
 Swaps the contents basic_line_wrapping_streambuf instance with another. More...
 

Protected Member Functions

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...
 

Detailed Description

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.

Several typedefs for common character types are provided:

Type Definition
ookii::line_wrapping_streambuf ookii::basic_line_wrapping_streambuf<char>
ookii::wline_wrapping_streambuf ookii::basic_line_wrapping_streambuf<wchar_t>
Template Parameters
CharTypeThe type of characters used by the target stream buffer.
TraitsThe character traits used by the target stream buffer.

Constructor & Destructor Documentation

◆ basic_line_wrapping_streambuf() [1/2]

template<typename CharType , typename Traits = std::char_traits<CharType>>
ookii::basic_line_wrapping_streambuf< CharType, Traits >::basic_line_wrapping_streambuf ( )
defaultnoexcept

Initializes a new instance of the basic_line_wrapping_streambuf class.

This instance cannot be used until init() is called.

◆ basic_line_wrapping_streambuf() [2/2]

template<typename CharType , typename Traits = std::char_traits<CharType>>
ookii::basic_line_wrapping_streambuf< CharType, Traits >::basic_line_wrapping_streambuf ( base_type streambuf,
size_t  max_line_length 
)
inline

Initializes a new instance of the basic_line_wrapping_streambuf class with the specified underlying stream buffer and maximum line length.

Parameters
streambufThe stream buffer to write output to.
max_line_lengthThe 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.

Member Function Documentation

◆ imbue()

template<typename CharType , typename Traits = std::char_traits<CharType>>
virtual void ookii::basic_line_wrapping_streambuf< CharType, Traits >::imbue ( const std::locale &  loc)
inlineoverrideprotectedvirtual

Change the locale of the stream buffer.

Parameters
locThe new locale.

◆ indent()

template<typename CharType , typename Traits = std::char_traits<CharType>>
void ookii::basic_line_wrapping_streambuf< CharType, Traits >::indent ( size_t  indent)
inlinenoexcept

Sets the number of spaces that each line is indented with.

Parameters
indentThe new indentation size.

◆ init()

template<typename CharType , typename Traits = std::char_traits<CharType>>
void ookii::basic_line_wrapping_streambuf< CharType, Traits >::init ( base_type streambuf,
size_t  max_line_length 
)
inlinenoexcept

Initializes this basic_line_wrapping_streambuf instance with the specified underlying stream buffer and maximum line length.

Parameters
streambufThe stream buffer to write output to.
max_line_lengthThe 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.

◆ overflow()

template<typename CharType , typename Traits = std::char_traits<CharType>>
virtual int_type ookii::basic_line_wrapping_streambuf< CharType, Traits >::overflow ( int_type  ch = traits_type::eof())
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
chThe 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>>
bool ookii::basic_line_wrapping_streambuf< CharType, Traits >::reset_indent ( )
inline

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>>
void ookii::basic_line_wrapping_streambuf< CharType, Traits >::swap ( basic_line_wrapping_streambuf< CharType, Traits > &  other)
inlinenoexcept

Swaps the contents basic_line_wrapping_streambuf instance with another.

Parameters
otherThe basic_line_wrapping_streambuf to swap with.

◆ sync()

template<typename CharType , typename Traits = std::char_traits<CharType>>
virtual int ookii::basic_line_wrapping_streambuf< CharType, Traits >::sync ( )
inlineoverrideprotectedvirtual

Flushes the buffer to the underlying stream buffer.

Returns
The result of calling pubsync() on the underlying stream buffer.

The documentation for this class was generated from the following file: