Code

fix combo enum, to handle enums of all types (not only the ones that range from 0...
[inkscape.git] / src / svg / stringstream.cpp
1 #include "svg/stringstream.h"
2 #include "svg/strip-trailing-zeros.h"
3 #include "prefs-utils.h"
4 #include <2geom/point.h>
6 Inkscape::SVGOStringStream::SVGOStringStream()
7 {
8     /* These two are probably unnecessary now that we provide our own operator<< for float and
9      * double. */
10     ostr.imbue(std::locale::classic());
11     ostr.setf(std::ios::showpoint);
13     /* This one is (currently) needed though, as we currently use ostr.precision as a sort of
14        variable for storing the desired precision: see our two precision methods and our operator<<
15        methods for float and double. */
16     ostr.precision(prefs_get_int_attribute("options.svgoutput", "numericprecision", 8));
17 }
19 Inkscape::SVGOStringStream &
20 operator<<(Inkscape::SVGOStringStream &os, float d)
21 {
22     /* Try as integer first. */
23     {
24         int const n = int(d);
25         if (d == n) {
26             os << n;
27             return os;
28         }
29     }
31     std::ostringstream s;
32     s.imbue(std::locale::classic());
33     s.flags(os.setf(std::ios::showpoint));
34     s.precision(os.precision());
35     s << d;
36     os << strip_trailing_zeros(s.str());
37     return os;
38 }
40 Inkscape::SVGOStringStream &
41 operator<<(Inkscape::SVGOStringStream &os, double d)
42 {
43     /* Try as integer first. */
44     {
45         int const n = int(d);
46         if (d == n) {
47             os << n;
48             return os;
49         }
50     }
52     std::ostringstream s;
53     s.imbue(std::locale::classic());
54     s.flags(os.setf(std::ios::showpoint));
55     s.precision(os.precision());
56     s << d;
57     os << strip_trailing_zeros(s.str());
58     return os;
59 }
61 Inkscape::SVGOStringStream &
62 operator<<(Inkscape::SVGOStringStream &os, Geom::Point const & p)
63 {
64     os << p[0] << ',' << p[1];
65     return os;
66 }
68 /*
69   Local Variables:
70   mode:c++
71   c-file-style:"stroustrup"
72   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
73   indent-tabs-mode:nil
74   fill-column:99
75   End:
76 */
77 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :