Wt  3.3.9
Classes | Public Member Functions | List of all members
Wt::Dbo::Wt::WStringStream Class Reference

#include <Wt/WStringStream>

Classes

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

Public Member Functions

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

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

Wt::Dbo::Wt::WStringStream::WStringStream ( )

Default constructor.

Creates a string stream.

Wt::Dbo::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

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

Appends a string.

Appends length bytes from the given string.

const char * Wt::Dbo::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.
void Wt::Dbo::Wt::WStringStream::clear ( )

Clears the contents.

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

bool Wt::Dbo::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::Dbo::Wt::WStringStream::length ( ) const

Returns the total length.

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

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

Appends a boolean.

This is written to the stream as true or false.

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

Returns the contents as a C++ string.

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


Generated on Tue Nov 21 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.11