source: libcf++/trunk/include/cf/formatter.hpp@ 4

Last change on this file since 4 was 4, checked in by cheese, 9 years ago

#1 commit prototype

File size: 942 bytes
Line 
1/**
2 * @file formatter.hpp
3 * @author myusgun@gmail.com
4 * @brief Formatter
5 */
6#ifndef __formatter_hpp__
7#define __formatter_hpp__
8
9#include <sstream>
10#include <string>
11
12/**
13 * make string using Formatter
14 * @see Formatter
15 */
16#define STR(_x) (cf::formatter() << _x).str()
17
18namespace cf
19{
20 /**
21 * a wrapper-class of std::ostringstream for temporary instance
22 * @see STR() macro
23 * @remarks http://stackoverflow.com/questions/303562/c-format-macro-inline-ostringstream
24 */
25 class formatter
26 {
27 private:
28 std::ostringstream mOSS;
29
30 public:
31 template<typename T>
32 formatter & operator << (const T & v)
33 {
34 mOSS << v;
35 return *this;
36 }
37
38 formatter & operator << (cf::char_t * v)
39 {
40 mOSS << (v ? v : "null");
41 return *this;
42 }
43
44 formatter & operator << (const cf::char_t * v)
45 {
46 mOSS << (v ? v : "null");
47 return *this;
48 }
49
50 std::string str()
51 {
52 return mOSS.str();
53 }
54 };
55}
56
57#endif // #ifndef __formatter_hpp__
Note: See TracBrowser for help on using the repository browser.