/src/skia/modules/svg/include/SkSVGValue.h
Line | Count | Source (jump to first uncovered line) |
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 "include/core/SkColor.h" |
12 | | #include "include/core/SkMatrix.h" |
13 | | #include "include/core/SkPath.h" |
14 | | #include "include/core/SkTypes.h" |
15 | | #include "include/private/base/SkNoncopyable.h" |
16 | | #include "modules/svg/include/SkSVGTypes.h" |
17 | | |
18 | | class SK_API SkSVGValue : public SkNoncopyable { |
19 | | public: |
20 | | enum class Type { |
21 | | kColor, |
22 | | kFilter, |
23 | | kLength, |
24 | | kNumber, |
25 | | kObjectBoundingBoxUnits, |
26 | | kPreserveAspectRatio, |
27 | | kStopColor, |
28 | | kString, |
29 | | kTransform, |
30 | | kViewBox, |
31 | | }; |
32 | | |
33 | 0 | Type type() const { return fType; } |
34 | | |
35 | | template <typename T> |
36 | 23 | const T* as() const { |
37 | 23 | return fType == T::TYPE ? static_cast<const T*>(this) : nullptr; |
38 | 23 | } SkSVGWrapperValue<SkSVGLength, (SkSVGValue::Type)2> const* SkSVGValue::as<SkSVGWrapperValue<SkSVGLength, (SkSVGValue::Type)2> >() const Line | Count | Source | 36 | 9 | const T* as() const { | 37 | 9 | return fType == T::TYPE ? static_cast<const T*>(this) : nullptr; | 38 | 9 | } |
SkSVGWrapperValue<SkRect, (SkSVGValue::Type)9> const* SkSVGValue::as<SkSVGWrapperValue<SkRect, (SkSVGValue::Type)9> >() const Line | Count | Source | 36 | 6 | const T* as() const { | 37 | 6 | return fType == T::TYPE ? static_cast<const T*>(this) : nullptr; | 38 | 6 | } |
Unexecuted instantiation: SkSVGWrapperValue<SkSVGPreserveAspectRatio, (SkSVGValue::Type)5> const* SkSVGValue::as<SkSVGWrapperValue<SkSVGPreserveAspectRatio, (SkSVGValue::Type)5> >() const SkSVGWrapperValue<SkMatrix, (SkSVGValue::Type)8> const* SkSVGValue::as<SkSVGWrapperValue<SkMatrix, (SkSVGValue::Type)8> >() const Line | Count | Source | 36 | 8 | const T* as() const { | 37 | 8 | return fType == T::TYPE ? static_cast<const T*>(this) : nullptr; | 38 | 8 | } |
|
39 | | |
40 | | protected: |
41 | 59 | SkSVGValue(Type t) : fType(t) { } |
42 | | |
43 | | private: |
44 | | Type fType; |
45 | | |
46 | | using INHERITED = SkNoncopyable; |
47 | | }; |
48 | | |
49 | | template <typename T, SkSVGValue::Type ValueType> |
50 | | class SK_API SkSVGWrapperValue final : public SkSVGValue { |
51 | | public: |
52 | | static constexpr Type TYPE = ValueType; |
53 | | |
54 | | explicit SkSVGWrapperValue(const T& v) |
55 | | : INHERITED(ValueType) |
56 | 59 | , fWrappedValue(v) { } SkSVGWrapperValue<SkSVGLength, (SkSVGValue::Type)2>::SkSVGWrapperValue(SkSVGLength const&) Line | Count | Source | 56 | 42 | , fWrappedValue(v) { } |
Unexecuted instantiation: SkSVGWrapperValue<SkSVGObjectBoundingBoxUnits, (SkSVGValue::Type)4>::SkSVGWrapperValue(SkSVGObjectBoundingBoxUnits const&) Unexecuted instantiation: SkSVGWrapperValue<SkSVGPreserveAspectRatio, (SkSVGValue::Type)5>::SkSVGWrapperValue(SkSVGPreserveAspectRatio const&) SkSVGWrapperValue<SkString, (SkSVGValue::Type)7>::SkSVGWrapperValue(SkString const&) Line | Count | Source | 56 | 3 | , fWrappedValue(v) { } |
SkSVGWrapperValue<SkMatrix, (SkSVGValue::Type)8>::SkSVGWrapperValue(SkMatrix const&) Line | Count | Source | 56 | 8 | , fWrappedValue(v) { } |
SkSVGWrapperValue<SkRect, (SkSVGValue::Type)9>::SkSVGWrapperValue(SkRect const&) Line | Count | Source | 56 | 6 | , fWrappedValue(v) { } |
|
57 | | |
58 | 23 | operator const T&() const { return fWrappedValue; } SkSVGWrapperValue<SkSVGLength, (SkSVGValue::Type)2>::operator SkSVGLength const&() const Line | Count | Source | 58 | 9 | operator const T&() const { return fWrappedValue; } |
SkSVGWrapperValue<SkRect, (SkSVGValue::Type)9>::operator SkRect const&() const Line | Count | Source | 58 | 6 | operator const T&() const { return fWrappedValue; } |
Unexecuted instantiation: SkSVGWrapperValue<SkSVGPreserveAspectRatio, (SkSVGValue::Type)5>::operator SkSVGPreserveAspectRatio const&() const SkSVGWrapperValue<SkMatrix, (SkSVGValue::Type)8>::operator SkMatrix const&() const Line | Count | Source | 58 | 8 | operator const T&() const { return fWrappedValue; } |
|
59 | | const T* operator->() const { return &fWrappedValue; } |
60 | | |
61 | | private: |
62 | | // Stack-only |
63 | | void* operator new(size_t) = delete; |
64 | | void* operator new(size_t, void*) = delete; |
65 | | |
66 | | const T& fWrappedValue; |
67 | | |
68 | | using INHERITED = SkSVGValue; |
69 | | }; |
70 | | |
71 | | using SkSVGColorValue = SkSVGWrapperValue<SkSVGColorType , SkSVGValue::Type::kColor >; |
72 | | using SkSVGLengthValue = SkSVGWrapperValue<SkSVGLength , SkSVGValue::Type::kLength >; |
73 | | using SkSVGTransformValue = SkSVGWrapperValue<SkSVGTransformType, SkSVGValue::Type::kTransform >; |
74 | | using SkSVGViewBoxValue = SkSVGWrapperValue<SkSVGViewBoxType , SkSVGValue::Type::kViewBox >; |
75 | | using SkSVGNumberValue = SkSVGWrapperValue<SkSVGNumberType , SkSVGValue::Type::kNumber >; |
76 | | using SkSVGStringValue = SkSVGWrapperValue<SkSVGStringType , SkSVGValue::Type::kString >; |
77 | | using SkSVGStopColorValue = SkSVGWrapperValue<SkSVGStopColor , SkSVGValue::Type::kStopColor >; |
78 | | |
79 | | using SkSVGPreserveAspectRatioValue = SkSVGWrapperValue<SkSVGPreserveAspectRatio, |
80 | | SkSVGValue::Type::kPreserveAspectRatio>; |
81 | | |
82 | | using SkSVGObjectBoundingBoxUnitsValue = SkSVGWrapperValue<SkSVGObjectBoundingBoxUnits, |
83 | | SkSVGValue::Type::kObjectBoundingBoxUnits>; |
84 | | |
85 | | #endif // SkSVGValue_DEFINED |