/* * 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 { kColor, kFilter, kLength, kNumber, kObjectBoundingBoxUnits, kPreserveAspectRatio, kStopColor, kString, kTransform, kViewBox, }; 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 SkSVGColorValue = SkSVGWrapperValue; using SkSVGLengthValue = SkSVGWrapperValue; using SkSVGTransformValue = SkSVGWrapperValue; using SkSVGViewBoxValue = SkSVGWrapperValue; using SkSVGNumberValue = SkSVGWrapperValue; using SkSVGStringValue = SkSVGWrapperValue; using SkSVGStopColorValue = SkSVGWrapperValue; using SkSVGPreserveAspectRatioValue = SkSVGWrapperValue; using SkSVGObjectBoundingBoxUnitsValue = SkSVGWrapperValue; #endif // SkSVGValue_DEFINED