Wt  3.3.8
Classes | Public Member Functions | List of all members
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::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.

Member Function Documentation

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

Appends a string.

Appends length bytes from the given string.

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


Generated on Mon Sep 4 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.11