Began refactoring the source properly this time 'round.
[aesalon.git] / include / util / StreamAsString.h
blob2fe9c2198dc2df010e6f4380f6194683c5cb3167
1 /** Aesalon, a tool to visualize program behaviour in real time.
2 Copyright (C) 2009-2011, Aesalon development team.
4 Aesalon is distributed under the terms of the GNU GPLv3. See
5 the included file LICENSE for more information.
7 @file include/util/StreamAsString.h
8 */
10 #ifndef AesalonUtil_StreamAsString_H
11 #define AesalonUtil_StreamAsString_H
13 #include <sstream>
15 namespace Util {
17 class StreamAsString {
18 public:
19 /** Automatic conversion to a std::string.
20 @return The internal stringstream, converted to a std::string.
22 operator std::string() const {
23 return get_stream().str();
25 /** Add something onto the internal std::stringstream.
26 @param data The data to add.
27 @return The new stringstream, with the data added.
29 template<typename Type>
30 StreamAsString &operator<<(const Type &data) {
31 get_stream() << data;
33 return *this;
35 protected:
36 /** Get the internal stringstream.
37 @return The internal stringstream, in non-const form.
39 std::ostringstream &get_stream() { return stream; }
40 /** Get the internal stringstream.
41 @return The internal stringstream, in const form.
43 const std::ostringstream &get_stream() const { return stream; }
44 private:
45 /** The internal stringstream. */
46 std::ostringstream stream;
49 } // namespace Util
51 #endif