3 * Copyright 2006 The Android Open Source Project
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 #ifndef SkMemberInfo_DEFINED
11 #define SkMemberInfo_DEFINED
13 #if defined SK_BUILD_CONDENSED
14 #define SK_USE_CONDENSED_INFO 0
17 #include "SkDisplayType.h"
20 #include "SkIntArray.h"
26 // temporary hacks until name change is more complete
27 #define SkFloat SkScalar
32 // if fCount == 0, record is member property
33 // then fType can be type, so caller doesn't have to check
34 #if SK_USE_CONDENSED_INFO == 0
35 const char* fName; // may be NULL for anonymous functions
36 size_t fOffset; // if negative, is index into member pointer table (for properties and functions)
38 int fCount; // for properties, actual type (count is always assumed to be 1)
45 SkDisplayTypes arrayType() const {
46 SkASSERT(fType == SkType_Array);
47 return (SkDisplayTypes) fCount; // hack, but worth it?
49 int functionIndex() const {
50 SkASSERT(fType == SkType_MemberFunction);
51 return (signed) fOffset > 0 ? -1 + (int) fOffset : -1 - (int) fOffset;
53 bool getArrayValue(const SkDisplayable* displayable, int index, SkOperand* value) const;
54 int getCount() const {
55 return fType == SkType_MemberProperty || fType == SkType_Array ||
56 fType == SkType_MemberFunction ? 1 : fCount;
58 const SkMemberInfo* getInherited() const;
59 size_t getSize(const SkDisplayable* ) const;
60 void getString(const SkDisplayable* , SkString** string) const;
61 SkDisplayTypes getType() const {
62 return fType == SkType_MemberProperty || fType == SkType_Array ||
63 fType == SkType_MemberFunction ? (SkDisplayTypes) fCount : (SkDisplayTypes) fType;
65 void getValue(const SkDisplayable* , SkOperand values[], int count) const;
67 const char* mapEnums(const char* match, int* value) const;
68 void* memberData(const SkDisplayable* displayable) const {
69 SkASSERT(fType != SkType_MemberProperty && fType != SkType_MemberFunction);
70 return (void*) ((const char*) displayable + fOffset);
72 int propertyIndex() const {
73 SkASSERT(fType == SkType_MemberProperty);
74 return (signed) fOffset > 0 ? -1 + (int) fOffset : -1 - (int) fOffset;
76 SkDisplayTypes propertyType() const {
77 SkASSERT(fType == SkType_MemberProperty || fType == SkType_Array);
78 return (SkDisplayTypes) fCount; // hack, but worth it?
80 void setMemberData(SkDisplayable* displayable, const void* child, size_t size) const {
81 SkASSERT(fType != SkType_MemberProperty && fType != SkType_MemberFunction);
82 memcpy((char*) displayable + fOffset, child, size);
84 void setString(SkDisplayable* , SkString* ) const;
85 void setValue(SkDisplayable* , const SkOperand values[], int count) const;
86 bool setValue(SkAnimateMaker& , SkTDOperandArray* storage,
87 int storageOffset, int maxStorage, SkDisplayable* ,
88 SkDisplayTypes outType, const char value[], size_t len) const;
89 bool setValue(SkAnimateMaker& , SkTDOperandArray* storage,
90 int storageOffset, int maxStorage, SkDisplayable* ,
91 SkDisplayTypes outType, SkString& str) const;
92 // void setValue(SkDisplayable* , const char value[], const char name[]) const;
93 bool writeValue(SkDisplayable* displayable, SkTDOperandArray* arrayStorage,
94 int storageOffset, int maxStorage, void* untypedStorage, SkDisplayTypes outType,
95 SkScriptValue& scriptValue) const;
96 #if SK_USE_CONDENSED_INFO == 0
97 static const SkMemberInfo* Find(const SkMemberInfo [], int count, int* index);
98 static const SkMemberInfo* Find(const SkMemberInfo [], int count, const char** name);
100 static const SkMemberInfo* Find(SkDisplayTypes type, int* index);
101 static const SkMemberInfo* Find(SkDisplayTypes type, const char** name);
103 static size_t GetSize(SkDisplayTypes type); // size of simple types only
104 // static bool SetValue(void* value, const char* name, SkDisplayTypes , int count);
107 #define SK_MEMBER(_member, _type) \
108 { #_member, SK_OFFSETOF(BASE_CLASS, _member), SkType_##_type, \
109 sizeof(((BASE_CLASS*) 1)->_member) / sizeof(SkScalar) }
111 #define SK_MEMBER_ALIAS(_member, _alias, _type) \
112 { #_member, SK_OFFSETOF(BASE_CLASS, _alias), SkType_##_type, \
113 sizeof(((BASE_CLASS*) 1)->_alias) / sizeof(SkScalar) }
115 #define SK_MEMBER_ARRAY(_member, _type) \
116 { #_member, SK_OFFSETOF(BASE_CLASS, _member), SkType_Array, \
117 (int) SkType_##_type }
119 #define SK_MEMBER_INHERITED \
120 { (const char*) INHERITED::fInfo, 0, SkType_BaseClassInfo, INHERITED::fInfoCount }
122 // #define SK_MEMBER_KEY_TYPE(_member, _type)
123 // {#_member, (size_t) -1, SkType_##_type, 0}
125 #define SK_FUNCTION(_member) \
126 k_##_member##Function
128 #define SK_PROPERTY(_member) \
129 k_##_member##Property
131 #define SK_MEMBER_DYNAMIC_FUNCTION(_member, _type) \
132 {#_member, (size_t) (+1 + SK_FUNCTION(_member)), SkType_MemberFunction, \
133 (int) SkType_##_type }
135 #define SK_MEMBER_DYNAMIC_PROPERTY(_member, _type) \
136 {#_member, (size_t) (1 + SK_PROPERTY(_member)), SkType_MemberProperty, \
137 (int) SkType_##_type }
139 #define SK_MEMBER_FUNCTION(_member, _type) \
140 {#_member, (size_t) (-1 - SK_FUNCTION(_member)), SkType_MemberFunction, \
141 (int) SkType_##_type }
143 #define SK_MEMBER_PROPERTY(_member, _type) \
144 {#_member, (size_t) (-1 - SK_PROPERTY(_member)), SkType_MemberProperty, \
145 (int) SkType_##_type }
147 #if SK_USE_CONDENSED_INFO == 0
149 #define DECLARE_PRIVATE_MEMBER_INFO(_type) \
151 static const SkMemberInfo fInfo[]; \
152 static const int fInfoCount; \
153 const SkMemberInfo* getMember(int index) SK_OVERRIDE; \
154 const SkMemberInfo* getMember(const char name[]) SK_OVERRIDE; \
155 typedef Sk##_type BASE_CLASS
157 #define DECLARE_MEMBER_INFO(_type) \
159 static const SkMemberInfo fInfo[]; \
160 static const int fInfoCount; \
161 const SkMemberInfo* getMember(int index) SK_OVERRIDE; \
162 const SkMemberInfo* getMember(const char name[]) SK_OVERRIDE; \
163 SkDisplayTypes getType() const SK_OVERRIDE { return SkType_##_type; } \
164 typedef Sk##_type BASE_CLASS
166 #define DECLARE_DRAW_MEMBER_INFO(_type) \
168 static const SkMemberInfo fInfo[]; \
169 static const int fInfoCount; \
170 const SkMemberInfo* getMember(int index) SK_OVERRIDE; \
171 const SkMemberInfo* getMember(const char name[]) SK_OVERRIDE; \
172 SkDisplayTypes getType() const SK_OVERRIDE { return SkType_##_type; } \
173 typedef SkDraw##_type BASE_CLASS
175 #define DECLARE_DISPLAY_MEMBER_INFO(_type) \
177 static const SkMemberInfo fInfo[]; \
178 static const int fInfoCount; \
179 const SkMemberInfo* getMember(int index) SK_OVERRIDE; \
180 const SkMemberInfo* getMember(const char name[]) SK_OVERRIDE; \
181 SkDisplayTypes getType() const SK_OVERRIDE { return SkType_##_type; } \
182 typedef SkDisplay##_type BASE_CLASS
184 #define DECLARE_EMPTY_MEMBER_INFO(_type) \
186 SkDisplayTypes getType() const SK_OVERRIDE { return SkType_##_type; }
188 #define DECLARE_EXTRAS_MEMBER_INFO(_type) \
190 static const SkMemberInfo fInfo[]; \
191 static const int fInfoCount; \
192 const SkMemberInfo* getMember(int index) SK_OVERRIDE; \
193 const SkMemberInfo* getMember(const char name[]) SK_OVERRIDE; \
194 SkDisplayTypes fType; \
195 SkDisplayTypes getType() const SK_OVERRIDE { return fType; } \
196 typedef _type BASE_CLASS
198 #define DECLARE_NO_VIRTUALS_MEMBER_INFO(_type) \
200 static const SkMemberInfo fInfo[]; \
201 static const int fInfoCount; \
202 typedef Sk##_type BASE_CLASS
204 #define DEFINE_GET_MEMBER(_class) \
205 const SkMemberInfo* _class::getMember(int index) { \
206 const SkMemberInfo* result = SkMemberInfo::Find(fInfo, SK_ARRAY_COUNT(fInfo), &index); \
209 const SkMemberInfo* _class::getMember(const char name[]) { \
210 const SkMemberInfo* result = SkMemberInfo::Find(fInfo, SK_ARRAY_COUNT(fInfo), &name); \
213 const int _class::fInfoCount = SK_ARRAY_COUNT(fInfo)
215 #define DEFINE_NO_VIRTUALS_GET_MEMBER(_class) \
216 const int _class::fInfoCount = SK_ARRAY_COUNT(fInfo)
220 #define DECLARE_PRIVATE_MEMBER_INFO(_type) \
222 typedef Sk##_type BASE_CLASS
224 #define DECLARE_MEMBER_INFO(_type) \
226 virtual const SkMemberInfo* getMember(int index) { \
227 return SkDisplayType::GetMember(NULL, SkType_##_type, &index); } \
228 virtual const SkMemberInfo* getMember(const char name[]) { \
229 return SkDisplayType::GetMember(NULL, SkType_##_type, &name); } \
230 virtual SkDisplayTypes getType() const { return SkType_##_type; } \
231 typedef Sk##_type BASE_CLASS
233 #define DECLARE_DRAW_MEMBER_INFO(_type) \
235 virtual const SkMemberInfo* getMember(int index) { \
236 return SkDisplayType::GetMember(NULL, SkType_##_type, &index); } \
237 virtual const SkMemberInfo* getMember(const char name[]) { \
238 return SkDisplayType::GetMember(NULL, SkType_##_type, &name); } \
239 virtual SkDisplayTypes getType() const { return SkType_##_type; } \
240 typedef SkDraw##_type BASE_CLASS
242 #define DECLARE_DISPLAY_MEMBER_INFO(_type) \
244 virtual const SkMemberInfo* getMember(int index) { \
245 return SkDisplayType::GetMember(NULL, SkType_##_type, &index); } \
246 virtual const SkMemberInfo* getMember(const char name[]) { \
247 return SkDisplayType::GetMember(NULL, SkType_##_type, &name); } \
248 virtual SkDisplayTypes getType() const { return SkType_##_type; } \
249 typedef SkDisplay##_type BASE_CLASS
251 #define DECLARE_EXTRAS_MEMBER_INFO(_type) \
253 virtual const SkMemberInfo* getMember(int index) { \
254 return SkDisplayType::GetMember(NULL, SkType_##_type, &index); } \
255 virtual const SkMemberInfo* getMember(const char name[]) { \
256 return SkDisplayType::GetMember(NULL, fType, &name); } \
257 SkDisplayTypes fType; \
258 virtual SkDisplayTypes getType() const { return fType; } \
259 typedef _type BASE_CLASS
261 #define DECLARE_NO_VIRTUALS_MEMBER_INFO(_type) \
263 typedef Sk##_type BASE_CLASS
265 #define DEFINE_GET_MEMBER(_class)
266 #define DEFINE_NO_VIRTUALS_GET_MEMBER(_class)
270 #endif // SkMemberInfo_DEFINED