/* * Copyright 2016 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef SkSVGValue_DEFINED #define SkSVGValue_DEFINED #include "include/core/SkColor.h" #include "include/core/SkMatrix.h" #include "include/core/SkPath.h" #include "include/core/SkTypes.h" #include "include/private/SkNoncopyable.h" #include "modules/svg/include/SkSVGTypes.h" class SkSVGValue : public SkNoncopyable { public: enum class Type { kClip, kColor, kDashArray, kFillRule, kLength, kLineCap, kLineJoin, kNumber, kPaint, kPath, kPoints, kSpreadMethod, kStopColor, kString, kTransform, kViewBox, kVisibility, }; Type type() const { return fType; } template const T* as() const { return fType == T::TYPE ? static_cast(this) : nullptr; } protected: SkSVGValue(Type t) : fType(t) { } private: Type fType; using INHERITED = SkNoncopyable; }; template class SkSVGWrapperValue final : public SkSVGValue { public: static constexpr Type TYPE = ValueType; explicit SkSVGWrapperValue(const T& v) : INHERITED(ValueType) , fWrappedValue(v) { } operator const T&() const { return fWrappedValue; } const T* operator->() const { return &fWrappedValue; } private: // Stack-only void* operator new(size_t) = delete; void* operator new(size_t, void*) = delete; const T& fWrappedValue; using INHERITED = SkSVGValue; }; using SkSVGClipValue = SkSVGWrapperValue; using SkSVGColorValue = SkSVGWrapperValue; using SkSVGFillRuleValue = SkSVGWrapperValue; using SkSVGLengthValue = SkSVGWrapperValue; using SkSVGPathValue = SkSVGWrapperValue; using SkSVGTransformValue = SkSVGWrapperValue; using SkSVGViewBoxValue = SkSVGWrapperValue; using SkSVGPaintValue = SkSVGWrapperValue; using SkSVGLineCapValue = SkSVGWrapperValue; using SkSVGLineJoinValue = SkSVGWrapperValue; using SkSVGNumberValue = SkSVGWrapperValue; using SkSVGPointsValue = SkSVGWrapperValue; using SkSVGStringValue = SkSVGWrapperValue; using SkSVGSpreadMethodValue = SkSVGWrapperValue; using SkSVGStopColorValue = SkSVGWrapperValue; using SkSVGVisibilityValue = SkSVGWrapperValue; using SkSVGDashArrayValue = SkSVGWrapperValue; #endif // SkSVGValue_DEFINED