OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkRecordPattern_DEFINED | 8 #ifndef SkRecordPattern_DEFINED |
9 #define SkRecordPattern_DEFINED | 9 #define SkRecordPattern_DEFINED |
10 | 10 |
11 #include "SkTLogic.h" | 11 #include "SkTLogic.h" |
12 | 12 |
13 namespace SkRecords { | 13 namespace SkRecords { |
14 | 14 |
15 // First, some matchers. These match a single command in the SkRecord, | 15 // First, some matchers. These match a single command in the SkRecord, |
16 // and may hang onto some data from it. If so, you can get the data by calling
.get(). | 16 // and may hang onto some data from it. If so, you can get the data by calling
.get(). |
17 | 17 |
18 // Matches a command of type T, and stores that command. | 18 // Matches a command of type T, and stores that command. |
19 template <typename T> | 19 template <typename T> |
20 class Is { | 20 class Is { |
21 public: | 21 public: |
22 Is() : fPtr(NULL) {} | 22 Is() : fPtr(nullptr) {} |
23 | 23 |
24 typedef T type; | 24 typedef T type; |
25 type* get() { return fPtr; } | 25 type* get() { return fPtr; } |
26 | 26 |
27 bool operator()(T* ptr) { | 27 bool operator()(T* ptr) { |
28 fPtr = ptr; | 28 fPtr = ptr; |
29 return true; | 29 return true; |
30 } | 30 } |
31 | 31 |
32 template <typename U> | 32 template <typename U> |
33 bool operator()(U*) { | 33 bool operator()(U*) { |
34 fPtr = NULL; | 34 fPtr = nullptr; |
35 return false; | 35 return false; |
36 } | 36 } |
37 | 37 |
38 private: | 38 private: |
39 type* fPtr; | 39 type* fPtr; |
40 }; | 40 }; |
41 | 41 |
42 // Matches any command that draws, and stores its paint. | 42 // Matches any command that draws, and stores its paint. |
43 class IsDraw { | 43 class IsDraw { |
44 SK_CREATE_MEMBER_DETECTOR(paint); | 44 SK_CREATE_MEMBER_DETECTOR(paint); |
45 public: | 45 public: |
46 IsDraw() : fPaint(NULL) {} | 46 IsDraw() : fPaint(nullptr) {} |
47 | 47 |
48 typedef SkPaint type; | 48 typedef SkPaint type; |
49 type* get() { return fPaint; } | 49 type* get() { return fPaint; } |
50 | 50 |
51 template <typename T> | 51 template <typename T> |
52 SK_WHEN(HasMember_paint<T>, bool) operator()(T* draw) { | 52 SK_WHEN(HasMember_paint<T>, bool) operator()(T* draw) { |
53 fPaint = AsPtr(draw->paint); | 53 fPaint = AsPtr(draw->paint); |
54 return true; | 54 return true; |
55 } | 55 } |
56 | 56 |
57 template <typename T> | 57 template <typename T> |
58 SK_WHEN(!HasMember_paint<T>, bool) operator()(T*) { | 58 SK_WHEN(!HasMember_paint<T>, bool) operator()(T*) { |
59 fPaint = NULL; | 59 fPaint = nullptr; |
60 return false; | 60 return false; |
61 } | 61 } |
62 | 62 |
63 // SaveLayer has an SkPaint named paint, but it's not a draw. | 63 // SaveLayer has an SkPaint named paint, but it's not a draw. |
64 bool operator()(SaveLayer*) { | 64 bool operator()(SaveLayer*) { |
65 fPaint = NULL; | 65 fPaint = nullptr; |
66 return false; | 66 return false; |
67 } | 67 } |
68 | 68 |
69 private: | 69 private: |
70 // Abstracts away whether the paint is always part of the command or optiona
l. | 70 // Abstracts away whether the paint is always part of the command or optiona
l. |
71 template <typename T> static T* AsPtr(SkRecords::Optional<T>& x) { return x;
} | 71 template <typename T> static T* AsPtr(SkRecords::Optional<T>& x) { return x;
} |
72 template <typename T> static T* AsPtr(T& x) { return &x; } | 72 template <typename T> static T* AsPtr(T& x) { return &x; } |
73 | 73 |
74 type* fPaint; | 74 type* fPaint; |
75 }; | 75 }; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 198 |
199 template <typename A, typename B, typename C, typename D, typename E, typename F
> | 199 template <typename A, typename B, typename C, typename D, typename E, typename F
> |
200 struct Pattern6 : Cons<A, Pattern5<B, C, D, E, F> > {}; | 200 struct Pattern6 : Cons<A, Pattern5<B, C, D, E, F> > {}; |
201 | 201 |
202 template <typename A, typename B, typename C, typename D, typename E, typename F
, typename G> | 202 template <typename A, typename B, typename C, typename D, typename E, typename F
, typename G> |
203 struct Pattern7 : Cons<A, Pattern6<B, C, D, E, F, G> > {}; | 203 struct Pattern7 : Cons<A, Pattern6<B, C, D, E, F, G> > {}; |
204 | 204 |
205 } // namespace SkRecords | 205 } // namespace SkRecords |
206 | 206 |
207 #endif//SkRecordPattern_DEFINED | 207 #endif//SkRecordPattern_DEFINED |
OLD | NEW |