From 7e421a557b5a15607d5a05ec93cb80098d76cd3c Mon Sep 17 00:00:00 2001 From: ishmal Date: Sat, 14 Jun 2008 21:17:27 +0000 Subject: [PATCH] Add SVGValue class --- src/dom/svg2.h | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/src/dom/svg2.h b/src/dom/svg2.h index 0e980cf89..0da3d861d 100644 --- a/src/dom/svg2.h +++ b/src/dom/svg2.h @@ -245,6 +245,92 @@ const char *svgElementEnumToStr(int type); +/*######################################################################### +## SVGValue +#########################################################################*/ + + +/** + * A helper class to provide a common API across several data types + */ +class SVGValue +{ +public: + + /** + * Constructors + */ + SVGValue() + { init(); } + + SVGValue(const SVGValue &other) + { assign(other); } + + SVGValue(double val) + { init(); type = SVG_DOUBLE; dval = val; } + + SVGValue(long val) + { init(); type = SVG_INT; ival = val; } + + SVGValue(const DOMString &val) + { init(); type = SVG_STRING; sval = val; } + + int getType() + { return type; } + + /** + * Assignment + */ + SVGValue &operator=(const SVGValue &val) + { assign(val); return *this; } + + SVGValue &operator=(double val) + { init(); type = SVG_DOUBLE; dval = val; return *this; } + + SVGValue &operator=(long val) + { init(); type = SVG_INT; ival = val; return *this; } + + SVGValue &operator=(const DOMString &val) + { init(); type = SVG_STRING; sval = val; return *this; } + + /** + * Getters + */ + double doubleValue() + { return dval; } + + long intValue() + { return ival; } + + DOMString &stringValue() + { return sval; } + +private: + + void init() + { + type = SVG_DOUBLE; + dval = 0.0; + ival = 0; + sval.clear(); + } + + void assign(const SVGValue &other) + { + type = other.type; + dval = other.dval; + ival = other.ival; + sval = other.sval; + } + + int type; + double dval; + long ival; + DOMString sval; + +}; + + /*######################################################################### ## SVGElement #########################################################################*/ -- 2.30.2