/* * 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 "experimental/svg/model/SkSVGTypes.h" #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" class SkSVGValue : public SkNoncopyable { public: enum class Type { kClip, kColor, kDashArray, kFillRule, kLength, kLineCap, kLineJoin, kNumber, kPaint, kPath, kPoints, kSpreadMethod, 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; typedef SkNoncopyable INHERITED; }; 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; typedef SkSVGValue INHERITED; }; 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 SkSVGVisibilityValue = SkSVGWrapperValue; using SkSVGDashArrayValue = SkSVGWrapperValue; #endif // SkSVGValue_DEFINED