Code

Super duper mega (fun!) commit: replaced encoding=utf-8 with fileencoding=utf-8 in...
[inkscape.git] / src / svg / css-ostringstream.h
1 #ifndef SVG_CSS_OSTRINGSTREAM_H_INKSCAPE
2 #define SVG_CSS_OSTRINGSTREAM_H_INKSCAPE
4 #include <glib/gtypes.h>
5 #include <sstream>
7 namespace Inkscape {
9 typedef std::ios_base &(*std_oct_type)(std::ios_base &);
11 /**
12  * A thin wrapper around std::ostringstream, but writing floating point numbers in the format
13  * required by CSS: `.' as decimal separator, no `e' notation, no nan or inf.
14  */
15 class CSSOStringStream {
16 private:
17     std::ostringstream ostr;
19 public:
20     CSSOStringStream();
22 #define INK_CSS_STR_OP(_t) \
23     CSSOStringStream &operator<<(_t arg) {  \
24         ostr << arg;    \
25         return *this;   \
26     }
28     INK_CSS_STR_OP(char)
29     INK_CSS_STR_OP(signed char)
30     INK_CSS_STR_OP(unsigned char)
31     INK_CSS_STR_OP(short)
32     INK_CSS_STR_OP(unsigned short)
33     INK_CSS_STR_OP(int)
34     INK_CSS_STR_OP(unsigned int)
35     INK_CSS_STR_OP(long)
36     INK_CSS_STR_OP(unsigned long)
37     INK_CSS_STR_OP(char const *)
38     INK_CSS_STR_OP(signed char const *)
39     INK_CSS_STR_OP(unsigned char const *)
40     INK_CSS_STR_OP(std::string const &)
41     INK_CSS_STR_OP(std_oct_type)
43 #undef INK_CSS_STR_OP
45     gchar const *gcharp() const {
46         return reinterpret_cast<gchar const *>(ostr.str().c_str());
47     }
49     std::string str() const {
50         return ostr.str();
51     }
53     std::streamsize precision() const {
54         return ostr.precision();
55     }
57     std::streamsize precision(std::streamsize p) {
58         return ostr.precision(p);
59     }
60 };
62 }
64 Inkscape::CSSOStringStream &operator<<(Inkscape::CSSOStringStream &os, float d);
66 Inkscape::CSSOStringStream &operator<<(Inkscape::CSSOStringStream &os, double d);
69 #endif /* !SVG_CSS_OSTRINGSTREAM_H_INKSCAPE */
71 /*
72   Local Variables:
73   mode:c++
74   c-file-style:"stroustrup"
75   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
76   indent-tabs-mode:nil
77   fill-column:99
78   End:
79 */
80 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :