ToString is a convenience class for converting non-string types to strings. More...
#include <ToString.h>
Public Types | |
typedef ostringstream::fmtflags | fmtflags |
typedef ostringstream::iostate | iostate |
Public Member Functions | |
ToString (const ToString &) | |
ToString () | |
template<typename T > | |
const string & | operator() (const T &obj) SSRC_DECL_THROW(std |
Converts an object to a string. | |
template<typename T > | |
const char * | c_str (const T &obj) SSRC_DECL_THROW(std |
fmtflags | flags () const |
fmtflags | flags (const fmtflags flags) |
fmtflags | setf (const fmtflags flags) |
fmtflags | setf (const fmtflags flags, const fmtflags mask) |
void | unsetf (const fmtflags flags) |
iostate | rdstate () const |
void | clear (iostate state=ostringstream::goodbit) |
void | setstate (iostate state) |
Detailed Description
ToString is a convenience class for converting non-string types to strings.
Even though this functionality (and more) is provided by boost::lexical_cast, that implementation uses a free-function and does not allow you to hold on to a casting object. Therefore, it reinstantiates a stringstream (and possibly other objects) on every use. ToString is meant to be used in situations where you will be repeatedly converting numbers to strings (such as in a loop or in a service call) and would like to avoid the overhead of the reinstantiation performed by boost::lexical_cast.
Definition at line 58 of file ToString.h.
Member Typedef Documentation
typedef ostringstream::fmtflags ToString::fmtflags |
Definition at line 144 of file ToString.h.
typedef ostringstream::iostate ToString::iostate |
Definition at line 145 of file ToString.h.
Constructor & Destructor Documentation
ToString::ToString | ( | const ToString & | ) | [inline] |
Definition at line 147 of file ToString.h.
ToString::ToString | ( | ) | [inline] |
Definition at line 153 of file ToString.h.
Member Function Documentation
const char* ToString::c_str | ( | const T & | obj | ) | [inline] |
Definition at line 189 of file ToString.h.
void ToString::clear | ( | iostate | state = ostringstream::goodbit | ) | [inline] |
Definition at line 222 of file ToString.h.
fmtflags ToString::flags | ( | ) | const [inline] |
Definition at line 196 of file ToString.h.
fmtflags ToString::flags | ( | const fmtflags | flags | ) | [inline] |
Definition at line 200 of file ToString.h.
const string& ToString::operator() | ( | const T & | obj | ) | [inline] |
Converts an object to a string.
Be careful of constructs such as foo.append(_string_cast(bar)).append(_string_cast(baz)) because the cast returns a reference and the compiler may order calls in such a way that both appends end up with the same value.
- Parameters:
-
T The type of the object to convert. It must define the << operator for use with an ostream. obj The object to convert.
- Returns:
- A string representation of the object.
Definition at line 183 of file ToString.h.
iostate ToString::rdstate | ( | ) | const [inline] |
Definition at line 218 of file ToString.h.
fmtflags ToString::setf | ( | const fmtflags | flags | ) | [inline] |
Definition at line 204 of file ToString.h.
fmtflags ToString::setf | ( | const fmtflags | flags, |
const fmtflags | mask | ||
) | [inline] |
Definition at line 208 of file ToString.h.
void ToString::setstate | ( | iostate | state | ) | [inline] |
Definition at line 226 of file ToString.h.
void ToString::unsetf | ( | const fmtflags | flags | ) | [inline] |
Definition at line 214 of file ToString.h.
The documentation for this class was generated from the following file: