From 62a9f87f4596d941c18b95477bf9456929f02ad6 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 18 Nov 2016 14:56:05 +0000 Subject: [PATCH] Added osg::MakeString class to make it easier to create std::string's using std::ostream style << usage. --- include/osg/io_utils | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/include/osg/io_utils b/include/osg/io_utils index 6f6d9aaf0..95768c90c 100644 --- a/include/osg/io_utils +++ b/include/osg/io_utils @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -35,6 +36,43 @@ namespace osg { +/** Convinience class for building std::string using stringstream. + * Usage: + * MakeString str; + * std::string s = str<<"Mix strings with numbers "<<0" ; + * std::string s2 = str.clear()<<"and other classes such as ("< + MakeString& operator << (const T& t) + { + sstream << t; + return *this; + } + + MakeString& operator << (std::ostream& (*fun)(std::ostream&)) + { + sstream << fun; + return *this; + } + + inline MakeString& clear() { sstream.str("") ; return *this; } + + inline operator std::string () const { return sstream.str(); } + + inline std::string str() const { return sstream.str(); } + inline const char* c_str() const { return sstream.str().c_str(); } +}; + + + +inline std::ostream& operator << (std::ostream& output, const MakeString& str) { output << str.str(); return output; } + ////////////////////////////////////////////////////////////////////////// // Vec2f streaming operators inline std::ostream& operator << (std::ostream& output, const Vec2f& vec)