2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
35 Object(const Object&);
39 * Create a new slot with the specified name and value. The name
40 * parameter is copied, but ownership of the Object parameter is
41 * transferred. The Object parameter may be null, but the name must
44 void addObject(const char name[], Object* value);
47 * Create a new slot with the specified name and value. The name
48 * parameter is copied, but ownership of the Array parameter is
49 * transferred. The Array parameter may be null, but the name must
52 void addArray(const char name[], Array* value);
55 * Create a new slot with the specified name and value. Both parameters
56 * are copied. The value parameter may be null, but the name must
59 void addString(const char name[], const char value[]);
62 * Create a new slot with the specified name and value. The name
63 * parameter is copied, and must not be null.
65 void addInt(const char name[], int32_t value);
68 * Create a new slot with the specified name and value. The name
69 * parameter is copied, and must not be null.
71 void addFloat(const char name[], float value);
74 * Create a new slot with the specified name and value. The name
75 * parameter is copied, and must not be null.
77 void addBool(const char name[], bool value);
80 * Return the number of slots/fields in this object. These can be
81 * iterated using Iter.
86 * Returns true if a slot matching the name and Type is found.
88 bool find(const char name[], Type) const;
89 bool findObject(const char name[], Object** = NULL) const;
90 bool findArray(const char name[], Array** = NULL) const;
91 bool findString(const char name[], SkString* = NULL) const;
92 bool findInt(const char name[], int32_t* = NULL) const;
93 bool findFloat(const char name[], float* = NULL) const;
94 bool findBool(const char name[], bool* = NULL) const;
97 * Finds the first slot matching the name and Type and removes it.
98 * Returns true if found, false if not.
100 bool remove(const char name[], Type);
102 void toDebugf() const;
105 * Iterator class which returns all of the fields/slots in an Object,
106 * in the order that they were added.
113 * Returns true when there are no more entries in the iterator.
114 * In this case, no other methods should be called.
119 * Moves the iterator to the next element. Should only be called
120 * if done() returns false.
125 * Returns the type of the current element. Should only be called
126 * if done() returns false.
131 * Returns the name of the current element. Should only be called
132 * if done() returns false.
134 const char* name() const;
137 * Returns the type of the current element. Should only be called
138 * if done() returns false and type() returns kObject.
140 Object* objectValue() const;
143 * Returns the type of the current element. Should only be called
144 * if done() returns false and type() returns kArray.
146 Array* arrayValue() const;
149 * Returns the type of the current element. Should only be called
150 * if done() returns false and type() returns kString.
152 const char* stringValue() const;
155 * Returns the type of the current element. Should only be called
156 * if done() returns false and type() returns kInt.
158 int32_t intValue() const;
161 * Returns the type of the current element. Should only be called
162 * if done() returns false and type() returns kFloat.
164 float floatValue() const;
167 * Returns the type of the current element. Should only be called
168 * if done() returns false and type() returns kBool.
170 bool boolValue() const;
180 const Slot* findSlot(const char name[], Type) const;
181 Slot* addSlot(Slot*);
182 void dumpLevel(int level) const;
190 * Creates an array with the specified Type and element count. All
191 * entries are initialized to NULL/0/false.
193 Array(Type, int count);
196 * Creates an array of ints, initialized by copying the specified
199 Array(const int32_t values[], int count);
202 * Creates an array of floats, initialized by copying the specified
205 Array(const float values[], int count);
208 * Creates an array of bools, initialized by copying the specified
211 Array(const bool values[], int count);
216 int count() const { return fCount; }
217 Type type() const { return fType; }
220 * Replace the element at the specified index with the specified
221 * Object (which may be null). Ownership of the Object is transferred.
222 * Should only be called if the Array's type is kObject.
224 void setObject(int index, Object*);
227 * Replace the element at the specified index with the specified
228 * Array (which may be null). Ownership of the Array is transferred.
229 * Should only be called if the Array's type is kArray.
231 void setArray(int index, Array*);
234 * Replace the element at the specified index with a copy of the
235 * specified string (which may be null). Should only be called if the
236 * Array's type is kString.
238 void setString(int index, const char str[]);
240 Object* const* objects() const {
241 SkASSERT(kObject == fType);
242 return fArray.fObjects;
244 Array* const* arrays() const {
245 SkASSERT(kObject == fType);
246 return fArray.fArrays;
248 const char* const* strings() const {
249 SkASSERT(kString == fType);
250 return fArray.fStrings;
252 int32_t* ints() const {
253 SkASSERT(kInt == fType);
256 float* floats() const {
257 SkASSERT(kFloat == fType);
258 return fArray.fFloats;
260 bool* bools() const {
261 SkASSERT(kBool == fType);
262 return fArray.fBools;
278 void init(Type, int count, const void* src);
279 void dumpLevel(int level) const;