/** * @file formatter.hpp * @author myusgun@gmail.com * @brief Formatter */ #ifndef __formatter_hpp__ #define __formatter_hpp__ #include #include /** * make string using Formatter * @see Formatter */ #define STR(_x) (cf::formatter() << _x).str() namespace cf { /** * a wrapper-class of std::ostringstream for temporary instance * @see STR() macro * @remarks http://stackoverflow.com/questions/303562/c-format-macro-inline-ostringstream */ class formatter { private: std::ostringstream mOSS; public: template formatter & operator << (const T & v) { mOSS << v; return *this; } formatter & operator << (cf::char_t * v) { mOSS << (v ? v : "null"); return *this; } formatter & operator << (const cf::char_t * v) { mOSS << (v ? v : "null"); return *this; } std::string str() { return mOSS.str(); } }; } #endif // #ifndef __formatter_hpp__