OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #ifndef SkSVGValue_DEFINED |
| 9 #define SkSVGValue_DEFINED |
| 10 |
| 11 #include "SkColor.h" |
| 12 #include "SkMatrix.h" |
| 13 #include "SkPath.h" |
| 14 #include "SkTypes.h" |
| 15 |
| 16 class SkSVGValue : public SkNoncopyable { |
| 17 public: |
| 18 enum class Type { |
| 19 Color, |
| 20 Path, |
| 21 Transform, |
| 22 }; |
| 23 |
| 24 Type type() const { return fType; } |
| 25 |
| 26 template <typename T> |
| 27 const T* as() const { |
| 28 return fType == T::TYPE ? static_cast<const T*>(this) : nullptr; |
| 29 } |
| 30 |
| 31 protected: |
| 32 SkSVGValue(Type t) : fType(t) { } |
| 33 |
| 34 private: |
| 35 Type fType; |
| 36 }; |
| 37 |
| 38 template <typename SkiaType, SkSVGValue::Type ValueType> |
| 39 class SkSVGWrapperValue final : public SkSVGValue { |
| 40 public: |
| 41 static constexpr Type TYPE = ValueType; |
| 42 |
| 43 explicit SkSVGWrapperValue(const SkiaType& v) |
| 44 : INHERITED(ValueType) |
| 45 , fWrappedValue(v) { } |
| 46 |
| 47 operator const SkiaType&() const { return fWrappedValue; } |
| 48 |
| 49 private: |
| 50 SkiaType fWrappedValue; |
| 51 |
| 52 using INHERITED = SkSVGValue; |
| 53 }; |
| 54 |
| 55 using SkSVGColorValue = SkSVGWrapperValue<SkColor , SkSVGValue::Type::Color
>; |
| 56 using SkSVGPathValue = SkSVGWrapperValue<SkPath , SkSVGValue::Type::Path
>; |
| 57 using SkSVGTransformValue = SkSVGWrapperValue<SkMatrix, SkSVGValue::Type::Transf
orm>; |
| 58 |
| 59 #endif // SkSVGValue_DEFINED |
OLD | NEW |