doxygen
Public Member Functions | List of all members
TextStream Class Referencefinal

Text streaming class that buffers data. More...

#include <textstream.h>

Public Member Functions

 TextStream (size_t capacity=INITIAL_CAPACITY)
 Creates an empty stream object.
 
 TextStream (std::ostream *s)
 Create a text stream object for writing to a std::ostream. More...
 
 TextStream (const std::string &s)
 Create a text stream, initializing the buffer with string s.
 
 ~TextStream ()
 Writes any data that is buffered to the attached std::ostream.
 
 TextStream (const TextStream &)=delete
 
TextStreamoperator= (const TextStream &)=delete
 
 TextStream (TextStream &&)=default
 
TextStreamoperator= (TextStream &&)=delete
 
void setStream (std::ostream *s)
 Sets or changes the std::ostream to write to. More...
 
void setFile (FILE *f)
 
std::ostream * stream () const
 Returns the attached std::ostream object. More...
 
FILE * file () const
 
TextStreamoperator<< (char c)
 Adds a character to the stream.
 
TextStreamoperator<< (unsigned char c)
 Adds an unsigned character to the stream.
 
TextStreamoperator<< (unsigned char *s)
 Adds an unsigned character string to the stream.
 
TextStreamoperator<< (const char *s)
 Adds a C-style string to the stream.
 
TextStreamoperator<< (const QCString &s)
 Adds a QCString to the stream.
 
TextStreamoperator<< (const std::string &s)
 Adds a std::string to the stream.
 
TextStreamoperator<< (signed short i)
 Adds a signed short integer to the stream.
 
TextStreamoperator<< (unsigned short i)
 Adds a unsigned short integer to the stream.
 
TextStreamoperator<< (signed int i)
 Adds a signed integer to the stream.
 
TextStreamoperator<< (unsigned int i)
 Adds a unsigned integer to the stream.
 
template<typename T , typename std::enable_if< std::is_same< T, size_t >::value, T >::type * = nullptr>
TextStreamoperator<< (T i)
 Adds a size_t integer to the stream. More...
 
TextStreamoperator<< (float f)
 Adds a float to the stream.
 
TextStreamoperator<< (double d)
 Adds a double to the stream.
 
void write (const char *buf, size_t len)
 Adds a array of character to the stream. More...
 
void flush ()
 Flushes the buffer. More...
 
void clear ()
 Clears any buffered data.
 
std::string str () const
 Return the contents of the buffer as a std::string object.
 
void str (const std::string &s)
 Sets the buffer's contents to string s. More...
 
void str (const char *s)
 Sets the buffer's contents to string s Any data already in the buffer will be flushed.
 
bool empty () const
 Returns true iff the buffer is empty.
 

Detailed Description

Text streaming class that buffers data.

Simpler version of std::ostringstream that has much better performance.

Constructor & Destructor Documentation

◆ TextStream()

TextStream::TextStream ( std::ostream *  s)
inlineexplicit

Create a text stream object for writing to a std::ostream.

Note
data is buffered until flush() is called or the object is destroyed.

Member Function Documentation

◆ flush()

void TextStream::flush ( )
inline

Flushes the buffer.

If a std::ostream is attached, the buffer's contents will be written to the stream.

◆ operator<<()

template<typename T , typename std::enable_if< std::is_same< T, size_t >::value, T >::type * = nullptr>
TextStream& TextStream::operator<< ( i)
inline

Adds a size_t integer to the stream.

We use SFINAE to avoid a compiler error in case size_t already matches the 'unsigned int' overload.

◆ setStream()

void TextStream::setStream ( std::ostream *  s)
inline

Sets or changes the std::ostream to write to.

Note
Any data already buffered will be flushed.

◆ str()

void TextStream::str ( const std::string &  s)
inline

Sets the buffer's contents to string s.

Any data already in the buffer will be flushed.

◆ stream()

std::ostream* TextStream::stream ( ) const
inline

Returns the attached std::ostream object.

See also
setStream()

◆ write()

void TextStream::write ( const char *  buf,
size_t  len 
)
inline

Adds a array of character to the stream.

Parameters
bufthe character buffer
lenthe number of characters in the buffer to write

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