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

Output string stream 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_ostringstream< CharType, Traits, Allocator >:
Inheritance graph
[legend]
Collaboration diagram for ookii::basic_line_wrapping_ostringstream< CharType, Traits, Allocator >:
Collaboration graph
[legend]

Public Types

using base_type = basic_line_wrapping_ostream< CharType, Traits >
 The concrete type that this class derives from.
 
using ostringstream_type = std::basic_ostringstream< CharType, Traits, Allocator >
 The concrete type of std::basic_ostringstream used.
 
using string_type = std::basic_string< CharType, Traits, Allocator >
 The concrete type of std::basic_string used.
 
- Public Types inherited from ookii::basic_line_wrapping_ostream< CharType, std::char_traits< CharType > >
using base_type = std::basic_ostream< CharType, std::char_traits< CharType > >
 The concrete type that this class derives from.
 
using streambuf_type = std::basic_streambuf< CharType, std::char_traits< CharType > >
 The concrete base stream buffer type used by this stream.
 

Public Member Functions

 basic_line_wrapping_ostringstream (size_t max_line_length, bool count_formatting=false)
 Initializes a new instance of the basic_line_wrapping_ostringstream class with the specified maximum line length. More...
 
string_type str () &&
 Gets a string move-constructed from the underlying string. More...
 
string_type str () const &
 Gets a copy of the underlying string object. More...
 
template<typename SAlloc , std::enable_if_t< details::is_allocator< SAlloc >::value, int > = 0>
std::basic_string< CharType, Traits, SAlloc > str (const SAlloc &alloc) const
 Gets a copy of the underlying string object, using alloc as allocator. More...
 
template<typename SAlloc >
void str (const std::basic_string< CharType, Traits, SAlloc > &s)
 Replaces the contents of the underlying string. More...
 
void str (const string_type &s)
 Replaces the contents of the underlying string. More...
 
void str (string_type &&s)
 Replaces the contents of the underlying string. More...
 
std::basic_string_view< CharType, Traits > view () const noexcept
 Gets a view over the underlying string. More...
 
- Public Member Functions inherited from ookii::basic_line_wrapping_ostream< CharType, std::char_traits< CharType > >
 basic_line_wrapping_ostream ()
 Initializes a new instance of the basic_line_wrapping_ostream class. More...
 
 basic_line_wrapping_ostream (base_type &base_stream, size_t max_line_length, bool count_formatting=false)
 Initializes a new instance of the basic_line_wrapping_ostream class with the specified underlying stream and maximum line length. More...
 
 basic_line_wrapping_ostream (basic_line_wrapping_ostream &&other) noexcept
 Move constructor. More...
 
void flush (bool flush_last_line)
 Flushes the buffer to the underlying stream buffer, optionally including the the final, partial line. More...
 
void init (base_type &base_stream, size_t max_line_length, bool count_formatting=false)
 Initializes a new instance of the basic_line_wrapping_ostream class with the specified underlying stream and maximum line length. More...
 
basic_line_wrapping_ostreamoperator= (basic_line_wrapping_ostream &&other) noexcept
 Move assignment operator. More...
 
void swap (basic_line_wrapping_ostream &other) noexcept
 Swaps this basic_line_wrapping_ostream instance with another. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from ookii::basic_line_wrapping_ostream< CharType, std::char_traits< CharType > >
static basic_line_wrapping_ostream for_cerr (short default_width=80)
 Creates a basic_line_wrapping_ostream that writes to the standard error stream, using the console width as the line width. More...
 
static basic_line_wrapping_ostream for_cout (short default_width=80)
 Creates a basic_line_wrapping_ostream that writes to the standard output stream, using the console width as the line width. More...
 

Detailed Description

template<typename CharType, typename Traits = std::char_traits<CharType>, typename Allocator = std::allocator<CharType>>
class ookii::basic_line_wrapping_ostringstream< CharType, Traits, Allocator >

Output string stream that wraps lines on white-space characters at the specified line length, and with support for indentation.

This stream writes to a string, whose contents can be retrieved using the str() and view() methods.

Warning
Flushing this stream will not flush the contents of the last unfinished line. Use ookii::flush() 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:

Type Definition
ookii::line_wrapping_ostringstream ookii::basic_line_wrapping_ostringstream<char>
ookii::wline_wrapping_ostringstream ookii::basic_line_wrapping_ostringstream<wchar_t>
Template Parameters
CharTypeThe type of characters used.
TraitsThe character traits used.
AllocatorThe allocator to use for strings.

Constructor & Destructor Documentation

◆ basic_line_wrapping_ostringstream()

template<typename CharType , typename Traits = std::char_traits<CharType>, typename Allocator = std::allocator<CharType>>
ookii::basic_line_wrapping_ostringstream< CharType, Traits, Allocator >::basic_line_wrapping_ostringstream ( size_t  max_line_length,
bool  count_formatting = false 
)
inline

Initializes a new instance of the basic_line_wrapping_ostringstream class with the specified maximum line length.

Parameters
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.
count_formattingInclude virtual terminal sequences when calculating the length of a line.

Member Function Documentation

◆ str() [1/6]

template<typename CharType , typename Traits = std::char_traits<CharType>, typename Allocator = std::allocator<CharType>>
string_type ookii::basic_line_wrapping_ostringstream< CharType, Traits, Allocator >::str ( ) &&
inline

Gets a string move-constructed from the underlying string.

To make sure the result contains all the written text, you must flush the string using ookii:flush(), specifying true to flush the final line.

◆ str() [2/6]

template<typename CharType , typename Traits = std::char_traits<CharType>, typename Allocator = std::allocator<CharType>>
string_type ookii::basic_line_wrapping_ostringstream< CharType, Traits, Allocator >::str ( ) const &
inline

Gets a copy of the underlying string object.

To make sure the result contains all the written text, you must flush the string using ookii:flush(), specifying true to flush the final line.

◆ str() [3/6]

template<typename CharType , typename Traits = std::char_traits<CharType>, typename Allocator = std::allocator<CharType>>
template<typename SAlloc , std::enable_if_t< details::is_allocator< SAlloc >::value, int > = 0>
std::basic_string<CharType, Traits, SAlloc> ookii::basic_line_wrapping_ostringstream< CharType, Traits, Allocator >::str ( const SAlloc &  alloc) const
inline

Gets a copy of the underlying string object, using alloc as allocator.

To make sure the result contains all the written text, you must flush the string using ookii:flush(), specifying true to flush the final line.

◆ str() [4/6]

template<typename CharType , typename Traits = std::char_traits<CharType>, typename Allocator = std::allocator<CharType>>
template<typename SAlloc >
void ookii::basic_line_wrapping_ostringstream< CharType, Traits, Allocator >::str ( const std::basic_string< CharType, Traits, SAlloc > &  s)
inline

Replaces the contents of the underlying string.

Parameters
sThe new contents.

◆ str() [5/6]

template<typename CharType , typename Traits = std::char_traits<CharType>, typename Allocator = std::allocator<CharType>>
void ookii::basic_line_wrapping_ostringstream< CharType, Traits, Allocator >::str ( const string_type s)
inline

Replaces the contents of the underlying string.

Parameters
sThe new contents.

◆ str() [6/6]

template<typename CharType , typename Traits = std::char_traits<CharType>, typename Allocator = std::allocator<CharType>>
void ookii::basic_line_wrapping_ostringstream< CharType, Traits, Allocator >::str ( string_type &&  s)
inline

Replaces the contents of the underlying string.

Parameters
sThe new contents.

◆ view()

template<typename CharType , typename Traits = std::char_traits<CharType>, typename Allocator = std::allocator<CharType>>
std::basic_string_view<CharType, Traits> ookii::basic_line_wrapping_ostringstream< CharType, Traits, Allocator >::view ( ) const
inlinenoexcept

Gets a view over the underlying string.

To make sure the result contains all the written text, you must flush the string using ookii:flush(), specifying true to flush the final line.


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