commit-bot@chromium.org | 2e0c32a | 2014-04-28 16:19:45 +0000 | [diff] [blame^] | 1 | #include "SkRecords.h" |
| 2 | #include "SkTLogic.h" |
| 3 | |
| 4 | // Type traits that are useful for working with SkRecords. |
| 5 | |
| 6 | namespace SkRecords { |
| 7 | |
| 8 | namespace { |
| 9 | |
| 10 | // Abstracts away whether the T is optional or not. |
| 11 | template <typename T> const T* as_ptr(const SkRecords::Optional<T>& x) { return x; } |
| 12 | template <typename T> const T* as_ptr(const T& x) { return &x; } |
| 13 | |
| 14 | } // namespace |
| 15 | |
| 16 | // Gets the paint from any command that may have one. |
| 17 | template <typename Command> const SkPaint* GetPaint(const Command& x) { return as_ptr(x.paint); } |
| 18 | |
| 19 | // Have a paint? You are a draw command! |
| 20 | template <typename Command> struct IsDraw { |
| 21 | SK_CREATE_MEMBER_DETECTOR(paint); |
| 22 | static const bool value = HasMember_paint<Command>::value; |
| 23 | }; |
| 24 | |
| 25 | // Have a clip op? You are a clip command. |
| 26 | template <typename Command> struct IsClip { |
| 27 | SK_CREATE_MEMBER_DETECTOR(op); |
| 28 | static const bool value = HasMember_op<Command>::value; |
| 29 | }; |
| 30 | |
| 31 | } // namespace SkRecords |