aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/svg/model/SkSVGValue.h
blob: a83c4fe07fa926b988774a393889ca1684eed5de (plain)
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
/*
 * 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 {
        kColor,
        kLength,
        kPath,
        kTransform,
    };

    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 SkiaType, SkSVGValue::Type ValueType>
class SkSVGWrapperValue final : public SkSVGValue {
public:
    static constexpr Type TYPE = ValueType;

    explicit SkSVGWrapperValue(const SkiaType& v)
        : INHERITED(ValueType)
        , fWrappedValue(v) { }

    operator const SkiaType&() const { return fWrappedValue; }

private:
    SkiaType fWrappedValue;

    typedef SkSVGValue INHERITED;
};

using SkSVGColorValue     = SkSVGWrapperValue<SkSVGColor , SkSVGValue::Type::kColor    >;
using SkSVGLengthValue    = SkSVGWrapperValue<SkSVGLength, SkSVGValue::Type::kLength   >;
using SkSVGPathValue      = SkSVGWrapperValue<SkPath     , SkSVGValue::Type::kPath     >;
using SkSVGTransformValue = SkSVGWrapperValue<SkMatrix   , SkSVGValue::Type::kTransform>;

#endif // SkSVGValue_DEFINED