Wt
4.11.0
|
#include <Wt/WStringStream.h>
Classes | |
struct | iterator |
An implementation of an output generator for appending data. More... | |
Public Member Functions | |
WStringStream () | |
Default constructor. | |
WStringStream & | operator= (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. | |
WStringStream & | operator<< (char) |
Appends a character. | |
WStringStream & | operator<< (const char *s) |
Appends a C string. | |
WStringStream & | operator<< (const std::string &s) |
Appends a C++ string. | |
WStringStream & | operator<< (bool) |
Appends a boolean. | |
WStringStream & | operator<< (int) |
Appends an integer number. | |
WStringStream & | operator<< (unsigned int) |
Appends an unsigned integer number. | |
WStringStream & | operator<< (long long) |
Appends an integer number. | |
WStringStream & | operator<< (double) |
Appends a double. | |
iterator | back_inserter () |
Iterator for appending. | |
const char * | c_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. | |
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).
Wt::WStringStream::WStringStream | ( | ) |
Default constructor.
Creates a string stream.
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.
Appends a string.
Appends length
bytes from the given string.
Returns the contents as a null-terminated C string.
The behaviour is only defined for a string stream with internal buffering.
void Wt::WStringStream::clear | ( | ) |
Clears the contents.
The behaviour is only defined for a string stream with internal buffering.
bool Wt::WStringStream::empty | ( | ) | const |
Returns whether the contents is empty.
The behaviour is only defined for a string stream with internal buffering.
std::size_t Wt::WStringStream::length | ( | ) | const |
Returns the total length.
The behaviour is only defined for a string stream with internal buffering.
WStringStream & Wt::WStringStream::operator<< | ( | bool | v | ) |
Appends a boolean.
This is written to the stream as true
or false
.
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.