Wt  4.11.0
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
Wt::WStringStream Class Reference

#include <Wt/WStringStream.h>

Classes

struct  iterator
 An implementation of an output generator for appending data. More...
 

Public Member Functions

 WStringStream ()
 Default constructor.
 
WStringStreamoperator= (const WStringStream &other)
 Assignment operator.
 
 WStringStream (std::ostream &sink)
 Constructor with std::ostream sink.
 
 ~WStringStream ()
 Destructor.
 
void append (const char *s, int length)
 Appends a string.
 
WStringStreamoperator<< (char)
 Appends a character.
 
WStringStreamoperator<< (const char *s)
 Appends a C string.
 
WStringStreamoperator<< (const std::string &s)
 Appends a C++ string.
 
WStringStreamoperator<< (bool)
 Appends a boolean.
 
WStringStreamoperator<< (int)
 Appends an integer number.
 
WStringStreamoperator<< (unsigned int)
 Appends an unsigned integer number.
 
WStringStreamoperator<< (long long)
 Appends an integer number.
 
WStringStreamoperator<< (double)
 Appends a double.
 
iterator back_inserter ()
 Iterator for appending.
 
const charc_str ()
 Returns the contents as a null-terminated C string.
 
std::string str () const
 Returns the contents as a C++ string.
 
bool empty () const
 Returns whether the contents is empty.
 
std::size_t length () const
 Returns the total length.
 
void clear ()
 Clears the contents.
 

Detailed Description

This is an efficient std::stringstream replacement. It is in particular more efficient when a relatively short string is being composed from many different pieces (avoiding any memory allocation all-together).

Compared to std::stringstream, it also avoids overhead by not supporting the formatting options of the latter, and by not making use of the std::locale, which apparently hampers std::ostream performance (Wt internally uses UTF-8 encoding throughout).

Constructor & Destructor Documentation

◆ WStringStream() [1/2]

Wt::WStringStream::WStringStream ( )

Default constructor.

Creates a string stream.

◆ WStringStream() [2/2]

Wt::WStringStream::WStringStream ( std::ostream &  sink)

Constructor with std::ostream sink.

Creates a string stream which flushes contents to an std::ostream, instead of relying on internal buffering. The output may still be internally buffered (for performance reasons), and this buffer is only flushed to the underlying ostream when you delete the string stream.

Member Function Documentation

◆ append()

void Wt::WStringStream::append ( const char s,
int  length 
)

Appends a string.

Appends length bytes from the given string.

◆ c_str()

const char * Wt::WStringStream::c_str ( )

Returns the contents as a null-terminated C string.

The behaviour is only defined for a string stream with internal buffering.

Note
This is only supported when the length of the total string is less than 1024 bytes. Returns 0 if the operation could not be completed.

◆ clear()

void Wt::WStringStream::clear ( )

Clears the contents.

The behaviour is only defined for a string stream with internal buffering.

◆ empty()

bool Wt::WStringStream::empty ( ) const

Returns whether the contents is empty.

The behaviour is only defined for a string stream with internal buffering.

◆ length()

std::size_t Wt::WStringStream::length ( ) const

Returns the total length.

The behaviour is only defined for a string stream with internal buffering.

◆ operator<<()

WStringStream & Wt::WStringStream::operator<< ( bool  v)

Appends a boolean.

This is written to the stream as true or false.

◆ str()

std::string Wt::WStringStream::str ( ) const

Returns the contents as a C++ string.

The behaviour is only defined for a string stream with internal buffering.