blob: 570a717e92a0663aab4abbb04ad061e2161e69c9 [file] [log] [blame]
commit-bot@chromium.org2e0c32a2014-04-28 16:19:45 +00001#include "SkRecords.h"
2#include "SkTLogic.h"
3
4// Type traits that are useful for working with SkRecords.
5
6namespace SkRecords {
7
8namespace {
9
10// Abstracts away whether the T is optional or not.
11template <typename T> const T* as_ptr(const SkRecords::Optional<T>& x) { return x; }
12template <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.
17template <typename Command> const SkPaint* GetPaint(const Command& x) { return as_ptr(x.paint); }
18
19// Have a paint? You are a draw command!
20template <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.
26template <typename Command> struct IsClip {
27 SK_CREATE_MEMBER_DETECTOR(op);
28 static const bool value = HasMember_op<Command>::value;
29};
30
31} // namespace SkRecords