diff options
| author | MenTaLguY <mental@rydia.net> | 2006-01-16 02:36:01 +0000 |
|---|---|---|
| committer | mental <mental@users.sourceforge.net> | 2006-01-16 02:36:01 +0000 |
| commit | 179fa413b047bede6e32109e2ce82437c5fb8d34 (patch) | |
| tree | a5a6ac2c1708bd02288fbd8edb2ff500ff2e0916 /src/svg/css-ostringstream.h | |
| download | inkscape-179fa413b047bede6e32109e2ce82437c5fb8d34.tar.gz inkscape-179fa413b047bede6e32109e2ce82437c5fb8d34.zip | |
moving trunk for module inkscape
(bzr r1)
Diffstat (limited to 'src/svg/css-ostringstream.h')
| -rw-r--r-- | src/svg/css-ostringstream.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/svg/css-ostringstream.h b/src/svg/css-ostringstream.h new file mode 100644 index 000000000..48ecf2992 --- /dev/null +++ b/src/svg/css-ostringstream.h @@ -0,0 +1,80 @@ +#ifndef SVG_CSS_OSTRINGSTREAM_H_INKSCAPE +#define SVG_CSS_OSTRINGSTREAM_H_INKSCAPE + +#include <glib/gtypes.h> +#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 + + gchar const *gcharp() const { + return reinterpret_cast<gchar const *>(ostr.str().c_str()); + } + + 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:encoding=utf-8:textwidth=99 : |
