The Battle for Wesnoth  1.15.1+dev
Public Member Functions | Private Attributes | List of all members
formatter Class Reference

std::ostringstream wrapper. More...

#include <formatter.hpp>

Public Member Functions

 formatter ()
template<typename T >
formatteroperator<< (const T &o)
std::string str () const
 operator std::string () const

Private Attributes

std::ostringstream stream_

Detailed Description

std::ostringstream wrapper.

ostringstream's operator<< doesn't return a ostringstream&. It returns an ostream& instead. This is unfortunate, because it means that you can't do something like this: (ostringstream() << n).str() to convert an integer to a string, all in one line instead you have to use this far more tedious approach: ostringstream s; s << n; s.str(); This class corrects this shortcoming, allowing something like this: string result = (formatter() << "blah " << n << x << " blah").str();

Actually, due to the ref qualified versions below, you can get away with this

string result = formatter() << "blah " << n << x << " blah";

Definition at line 38 of file formatter.hpp.

Constructor & Destructor Documentation

◆ formatter()

formatter::formatter ( )

Definition at line 41 of file formatter.hpp.

Member Function Documentation

◆ operator std::string()

formatter::operator std::string ( ) const

Definition at line 69 of file formatter.hpp.

References stream_.

◆ operator<<()

template<typename T >
formatter& formatter::operator<< ( const T &  o)

Definition at line 47 of file formatter.hpp.

References stream_.

◆ str()

std::string formatter::str ( ) const

Definition at line 64 of file formatter.hpp.

References stream_.

Referenced by mp::game_info::game_info().

Member Data Documentation

◆ stream_

std::ostringstream formatter::stream_

Definition at line 78 of file formatter.hpp.

Referenced by operator std::string(), operator<<(), and str().

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