1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/*
* 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 "SkColor.h"
#include "SkMatrix.h"
#include "SkPath.h"
#include "SkSVGTypes.h"
#include "SkTypes.h"
class SkSVGValue : public SkNoncopyable {
public:
enum class Type {
kClip,
kColor,
kFillRule,
kLength,
kLineCap,
kLineJoin,
kNumber,
kPaint,
kPath,
kPoints,
kSpreadMethod,
kString,
kTransform,
kViewBox,
};
Type type() const { return fType; }
template <typename T>
const T* as() const {
return fType == T::TYPE ? static_cast<const T*>(this) : nullptr;
}
protected:
SkSVGValue(Type t) : fType(t) { }
private:
Type fType;
typedef SkNoncopyable INHERITED;
};
template <typename T, SkSVGValue::Type ValueType>
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<SkSVGClip , SkSVGValue::Type::kClip >;
using SkSVGColorValue = SkSVGWrapperValue<SkSVGColorType , SkSVGValue::Type::kColor >;
using SkSVGFillRuleValue = SkSVGWrapperValue<SkSVGFillRule , SkSVGValue::Type::kFillRule >;
using SkSVGLengthValue = SkSVGWrapperValue<SkSVGLength , SkSVGValue::Type::kLength >;
using SkSVGPathValue = SkSVGWrapperValue<SkPath , SkSVGValue::Type::kPath >;
using SkSVGTransformValue = SkSVGWrapperValue<SkSVGTransformType, SkSVGValue::Type::kTransform>;
using SkSVGViewBoxValue = SkSVGWrapperValue<SkSVGViewBoxType , SkSVGValue::Type::kViewBox >;
using SkSVGPaintValue = SkSVGWrapperValue<SkSVGPaint , SkSVGValue::Type::kPaint >;
using SkSVGLineCapValue = SkSVGWrapperValue<SkSVGLineCap , SkSVGValue::Type::kLineCap >;
using SkSVGLineJoinValue = SkSVGWrapperValue<SkSVGLineJoin , SkSVGValue::Type::kLineJoin >;
using SkSVGNumberValue = SkSVGWrapperValue<SkSVGNumberType , SkSVGValue::Type::kNumber >;
using SkSVGPointsValue = SkSVGWrapperValue<SkSVGPointsType , SkSVGValue::Type::kPoints >;
using SkSVGStringValue = SkSVGWrapperValue<SkSVGStringType , SkSVGValue::Type::kString >;
using SkSVGSpreadMethodValue = SkSVGWrapperValue<SkSVGSpreadMethod ,
SkSVGValue::Type::kSpreadMethod>;
#endif // SkSVGValue_DEFINED
|