1 #ifndef INKSCAPE_STRINGSTREAM_H
2 #define INKSCAPE_STRINGSTREAM_H
4 #include <glib/gtypes.h>
5 #include <sstream>
6 #include <string>
8 namespace Inkscape {
10 typedef std::ios_base &(*std_oct_type)(std::ios_base &);
12 class SVGOStringStream {
13 private:
14 std::ostringstream ostr;
16 public:
17 SVGOStringStream();
19 #define INK_SVG_STR_OP(_t) \
20 SVGOStringStream &operator<<(_t arg) { \
21 ostr << arg; \
22 return *this; \
23 }
25 INK_SVG_STR_OP(char)
26 INK_SVG_STR_OP(signed char)
27 INK_SVG_STR_OP(unsigned char)
28 INK_SVG_STR_OP(short)
29 INK_SVG_STR_OP(unsigned short)
30 INK_SVG_STR_OP(int)
31 INK_SVG_STR_OP(unsigned int)
32 INK_SVG_STR_OP(long)
33 INK_SVG_STR_OP(unsigned long)
34 INK_SVG_STR_OP(char const *)
35 INK_SVG_STR_OP(signed char const *)
36 INK_SVG_STR_OP(unsigned char const *)
37 INK_SVG_STR_OP(std::string const &)
38 INK_SVG_STR_OP(std_oct_type)
40 #undef INK_SVG_STR_OP
42 gchar const *gcharp() const {
43 return reinterpret_cast<gchar const *>(ostr.str().c_str());
44 }
46 std::string str() const {
47 return ostr.str();
48 }
50 void str (std::string &s) {
51 return ostr.str(s);
52 }
54 std::streamsize precision() const {
55 return ostr.precision();
56 }
58 std::streamsize precision(std::streamsize p) {
59 return ostr.precision(p);
60 }
62 std::ios::fmtflags setf(std::ios::fmtflags fmtfl) {
63 return ostr.setf(fmtfl);
64 }
66 std::ios::fmtflags setf(std::ios::fmtflags fmtfl, std::ios::fmtflags mask) {
67 return ostr.setf(fmtfl, mask);
68 }
70 void unsetf(std::ios::fmtflags mask) {
71 ostr.unsetf(mask);
72 }
73 };
75 }
77 Inkscape::SVGOStringStream &operator<<(Inkscape::SVGOStringStream &os, float d);
79 Inkscape::SVGOStringStream &operator<<(Inkscape::SVGOStringStream &os, double d);
82 #endif
84 /*
85 Local Variables:
86 mode:c++
87 c-file-style:"stroustrup"
88 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
89 indent-tabs-mode:nil
90 fill-column:99
91 End:
92 */
93 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :