1 #ifndef AESALON_MISC_STREAM_AS_STRING_H
2 #define AESALON_MISC_STREAM_AS_STRING_H
10 /** StreamAsString class.
12 Allows for nice inline stringstreams, such as
13 Exception(StreamAsString() << "Exception occured, line " << __line__);
15 class StreamAsString
{
17 /** Automatic conversion to a std::string.
18 @return The internal stringstream, converted to a std::string.
20 operator std::string() const {
21 return get_stream().str();
23 /** Add something onto the internal std::stringstream.
24 @param data The data to add.
25 @return The new stringstream, with the data added.
27 template<typename Type
>
28 StreamAsString
&operator<<(const Type
&data
) {
34 /** Get the internal stringstream.
35 @return The internal stringstream, in non-const form.
37 std::ostringstream
&get_stream() { return stream
; }
38 /** Get the internal stringstream.
39 @return The internal stringstream, in const form.
41 const std::ostringstream
&get_stream() const { return stream
; }
43 /** The internal stringstream. */
44 std::ostringstream stream
;
48 } // namespace Aesalon