summaryrefslogtreecommitdiffstats
path: root/src/svg/css-ostringstream.h
blob: 0df04062119b430c68b901bdcbcfb8d4697d3e8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
 * TODO: insert short description here
 *//*
 * Authors: see git history
 *
 * Copyright (C) 2014 Authors
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */
#ifndef SVG_CSS_OSTRINGSTREAM_H_INKSCAPE
#define SVG_CSS_OSTRINGSTREAM_H_INKSCAPE

#include <sstream>

namespace Inkscape {

typedef std::ios_base &(*std_oct_type)(std::ios_base &);

/**
 * A thin wrapper around std::ostringstream, but writing floating point numbers in the format
 * required by CSS: `.' as decimal separator, no `e' notation, no nan or inf.
 */
class CSSOStringStream {
private:
    std::ostringstream ostr;

public:
    CSSOStringStream();

#define INK_CSS_STR_OP(_t) \
    CSSOStringStream &operator<<(_t arg) {  \
        ostr << arg;    \
        return *this;   \
    }

    INK_CSS_STR_OP(char)
    INK_CSS_STR_OP(signed char)
    INK_CSS_STR_OP(unsigned char)
    INK_CSS_STR_OP(short)
    INK_CSS_STR_OP(unsigned short)
    INK_CSS_STR_OP(int)
    INK_CSS_STR_OP(unsigned int)
    INK_CSS_STR_OP(long)
    INK_CSS_STR_OP(unsigned long)
    INK_CSS_STR_OP(char const *)
    INK_CSS_STR_OP(signed char const *)
    INK_CSS_STR_OP(unsigned char const *)
    INK_CSS_STR_OP(std::string const &)
    INK_CSS_STR_OP(std_oct_type)

#undef INK_CSS_STR_OP

    std::string str() const {
        return ostr.str();
    }

    std::streamsize precision() const {
        return ostr.precision();
    }

    std::streamsize precision(std::streamsize p) {
        return ostr.precision(p);
    }
};

}

Inkscape::CSSOStringStream &operator<<(Inkscape::CSSOStringStream &os, float d);

Inkscape::CSSOStringStream &operator<<(Inkscape::CSSOStringStream &os, double d);


#endif /* !SVG_CSS_OSTRINGSTREAM_H_INKSCAPE */

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :