Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: src/core/SkMetaData.cpp

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkMatrixImageFilter.cpp ('k') | src/core/SkMipMap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkMetaData.h" 10 #include "SkMetaData.h"
11 #include "SkRefCnt.h" 11 #include "SkRefCnt.h"
12 12
13 struct PtrPair { 13 struct PtrPair {
14 void* fPtr; 14 void* fPtr;
15 SkMetaData::PtrProc fProc; 15 SkMetaData::PtrProc fProc;
16 }; 16 };
17 17
18 void* SkMetaData::RefCntProc(void* ptr, bool doRef) { 18 void* SkMetaData::RefCntProc(void* ptr, bool doRef) {
19 SkASSERT(ptr); 19 SkASSERT(ptr);
20 SkRefCnt* refcnt = reinterpret_cast<SkRefCnt*>(ptr); 20 SkRefCnt* refcnt = reinterpret_cast<SkRefCnt*>(ptr);
21 21
22 if (doRef) { 22 if (doRef) {
23 refcnt->ref(); 23 refcnt->ref();
24 } else { 24 } else {
25 refcnt->unref(); 25 refcnt->unref();
26 } 26 }
27 return ptr; 27 return ptr;
28 } 28 }
29 29
30 SkMetaData::SkMetaData() : fRec(NULL) 30 SkMetaData::SkMetaData() : fRec(nullptr)
31 { 31 {
32 } 32 }
33 33
34 SkMetaData::SkMetaData(const SkMetaData& src) : fRec(NULL) 34 SkMetaData::SkMetaData(const SkMetaData& src) : fRec(nullptr)
35 { 35 {
36 *this = src; 36 *this = src;
37 } 37 }
38 38
39 SkMetaData::~SkMetaData() 39 SkMetaData::~SkMetaData()
40 { 40 {
41 this->reset(); 41 this->reset();
42 } 42 }
43 43
44 void SkMetaData::reset() 44 void SkMetaData::reset()
45 { 45 {
46 Rec* rec = fRec; 46 Rec* rec = fRec;
47 while (rec) { 47 while (rec) {
48 if (kPtr_Type == rec->fType) { 48 if (kPtr_Type == rec->fType) {
49 PtrPair* pair = (PtrPair*)rec->data(); 49 PtrPair* pair = (PtrPair*)rec->data();
50 if (pair->fProc && pair->fPtr) { 50 if (pair->fProc && pair->fPtr) {
51 pair->fPtr = pair->fProc(pair->fPtr, false); 51 pair->fPtr = pair->fProc(pair->fPtr, false);
52 } 52 }
53 } 53 }
54 Rec* next = rec->fNext; 54 Rec* next = rec->fNext;
55 Rec::Free(rec); 55 Rec::Free(rec);
56 rec = next; 56 rec = next;
57 } 57 }
58 fRec = NULL; 58 fRec = nullptr;
59 } 59 }
60 60
61 SkMetaData& SkMetaData::operator=(const SkMetaData& src) 61 SkMetaData& SkMetaData::operator=(const SkMetaData& src)
62 { 62 {
63 this->reset(); 63 this->reset();
64 64
65 const Rec* rec = src.fRec; 65 const Rec* rec = src.fRec;
66 while (rec) 66 while (rec)
67 { 67 {
68 this->set(rec->name(), rec->data(), rec->fDataLen, (Type)rec->fType, rec ->fDataCount); 68 this->set(rec->name(), rec->data(), rec->fDataLen, (Type)rec->fType, rec ->fDataCount);
(...skipping 10 matching lines...) Expand all
79 void SkMetaData::setScalar(const char name[], SkScalar value) 79 void SkMetaData::setScalar(const char name[], SkScalar value)
80 { 80 {
81 (void)this->set(name, &value, sizeof(SkScalar), kScalar_Type, 1); 81 (void)this->set(name, &value, sizeof(SkScalar), kScalar_Type, 1);
82 } 82 }
83 83
84 SkScalar* SkMetaData::setScalars(const char name[], int count, const SkScalar va lues[]) 84 SkScalar* SkMetaData::setScalars(const char name[], int count, const SkScalar va lues[])
85 { 85 {
86 SkASSERT(count > 0); 86 SkASSERT(count > 0);
87 if (count > 0) 87 if (count > 0)
88 return (SkScalar*)this->set(name, values, sizeof(SkScalar), kScalar_Type , count); 88 return (SkScalar*)this->set(name, values, sizeof(SkScalar), kScalar_Type , count);
89 return NULL; 89 return nullptr;
90 } 90 }
91 91
92 void SkMetaData::setString(const char name[], const char value[]) 92 void SkMetaData::setString(const char name[], const char value[])
93 { 93 {
94 (void)this->set(name, value, sizeof(char), kString_Type, SkToInt(strlen(valu e) + 1)); 94 (void)this->set(name, value, sizeof(char), kString_Type, SkToInt(strlen(valu e) + 1));
95 } 95 }
96 96
97 void SkMetaData::setPtr(const char name[], void* ptr, PtrProc proc) { 97 void SkMetaData::setPtr(const char name[], void* ptr, PtrProc proc) {
98 PtrPair pair = { ptr, proc }; 98 PtrPair pair = { ptr, proc };
99 (void)this->set(name, &pair, sizeof(PtrPair), kPtr_Type, 1); 99 (void)this->set(name, &pair, sizeof(PtrPair), kPtr_Type, 1);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 { 172 {
173 const Rec* rec = this->find(name, kScalar_Type); 173 const Rec* rec = this->find(name, kScalar_Type);
174 if (rec) 174 if (rec)
175 { 175 {
176 if (count) 176 if (count)
177 *count = rec->fDataCount; 177 *count = rec->fDataCount;
178 if (values) 178 if (values)
179 memcpy(values, rec->data(), rec->fDataCount * rec->fDataLen); 179 memcpy(values, rec->data(), rec->fDataCount * rec->fDataLen);
180 return (const SkScalar*)rec->data(); 180 return (const SkScalar*)rec->data();
181 } 181 }
182 return NULL; 182 return nullptr;
183 } 183 }
184 184
185 bool SkMetaData::findPtr(const char name[], void** ptr, PtrProc* proc) const { 185 bool SkMetaData::findPtr(const char name[], void** ptr, PtrProc* proc) const {
186 const Rec* rec = this->find(name, kPtr_Type); 186 const Rec* rec = this->find(name, kPtr_Type);
187 if (rec) { 187 if (rec) {
188 SkASSERT(rec->fDataCount == 1); 188 SkASSERT(rec->fDataCount == 1);
189 const PtrPair* pair = (const PtrPair*)rec->data(); 189 const PtrPair* pair = (const PtrPair*)rec->data();
190 if (ptr) { 190 if (ptr) {
191 *ptr = pair->fPtr; 191 *ptr = pair->fPtr;
192 } 192 }
193 if (proc) { 193 if (proc) {
194 *proc = pair->fProc; 194 *proc = pair->fProc;
195 } 195 }
196 return true; 196 return true;
197 } 197 }
198 return false; 198 return false;
199 } 199 }
200 200
201 const char* SkMetaData::findString(const char name[]) const 201 const char* SkMetaData::findString(const char name[]) const
202 { 202 {
203 const Rec* rec = this->find(name, kString_Type); 203 const Rec* rec = this->find(name, kString_Type);
204 SkASSERT(rec == NULL || rec->fDataLen == sizeof(char)); 204 SkASSERT(rec == nullptr || rec->fDataLen == sizeof(char));
205 return rec ? (const char*)rec->data() : NULL; 205 return rec ? (const char*)rec->data() : nullptr;
206 } 206 }
207 207
208 bool SkMetaData::findBool(const char name[], bool* value) const 208 bool SkMetaData::findBool(const char name[], bool* value) const
209 { 209 {
210 const Rec* rec = this->find(name, kBool_Type); 210 const Rec* rec = this->find(name, kBool_Type);
211 if (rec) 211 if (rec)
212 { 212 {
213 SkASSERT(rec->fDataCount == 1); 213 SkASSERT(rec->fDataCount == 1);
214 if (value) 214 if (value)
215 *value = *(const bool*)rec->data(); 215 *value = *(const bool*)rec->data();
216 return true; 216 return true;
217 } 217 }
218 return false; 218 return false;
219 } 219 }
220 220
221 const void* SkMetaData::findData(const char name[], size_t* length) const { 221 const void* SkMetaData::findData(const char name[], size_t* length) const {
222 const Rec* rec = this->find(name, kData_Type); 222 const Rec* rec = this->find(name, kData_Type);
223 if (rec) { 223 if (rec) {
224 SkASSERT(rec->fDataLen == sizeof(char)); 224 SkASSERT(rec->fDataLen == sizeof(char));
225 if (length) { 225 if (length) {
226 *length = rec->fDataCount; 226 *length = rec->fDataCount;
227 } 227 }
228 return rec->data(); 228 return rec->data();
229 } 229 }
230 return NULL; 230 return nullptr;
231 } 231 }
232 232
233 const SkMetaData::Rec* SkMetaData::find(const char name[], Type type) const 233 const SkMetaData::Rec* SkMetaData::find(const char name[], Type type) const
234 { 234 {
235 const Rec* rec = fRec; 235 const Rec* rec = fRec;
236 while (rec) 236 while (rec)
237 { 237 {
238 if (rec->fType == type && !strcmp(rec->name(), name)) 238 if (rec->fType == type && !strcmp(rec->name(), name))
239 return rec; 239 return rec;
240 rec = rec->fNext; 240 rec = rec->fNext;
241 } 241 }
242 return NULL; 242 return nullptr;
243 } 243 }
244 244
245 bool SkMetaData::remove(const char name[], Type type) { 245 bool SkMetaData::remove(const char name[], Type type) {
246 Rec* rec = fRec; 246 Rec* rec = fRec;
247 Rec* prev = NULL; 247 Rec* prev = nullptr;
248 while (rec) { 248 while (rec) {
249 Rec* next = rec->fNext; 249 Rec* next = rec->fNext;
250 if (rec->fType == type && !strcmp(rec->name(), name)) { 250 if (rec->fType == type && !strcmp(rec->name(), name)) {
251 if (prev) { 251 if (prev) {
252 prev->fNext = next; 252 prev->fNext = next;
253 } else { 253 } else {
254 fRec = next; 254 fRec = next;
255 } 255 }
256 256
257 if (kPtr_Type == type) { 257 if (kPtr_Type == type) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 302
303 SkMetaData::Iter::Iter(const SkMetaData& metadata) { 303 SkMetaData::Iter::Iter(const SkMetaData& metadata) {
304 fRec = metadata.fRec; 304 fRec = metadata.fRec;
305 } 305 }
306 306
307 void SkMetaData::Iter::reset(const SkMetaData& metadata) { 307 void SkMetaData::Iter::reset(const SkMetaData& metadata) {
308 fRec = metadata.fRec; 308 fRec = metadata.fRec;
309 } 309 }
310 310
311 const char* SkMetaData::Iter::next(SkMetaData::Type* t, int* count) { 311 const char* SkMetaData::Iter::next(SkMetaData::Type* t, int* count) {
312 const char* name = NULL; 312 const char* name = nullptr;
313 313
314 if (fRec) { 314 if (fRec) {
315 if (t) { 315 if (t) {
316 *t = (SkMetaData::Type)fRec->fType; 316 *t = (SkMetaData::Type)fRec->fType;
317 } 317 }
318 if (count) { 318 if (count) {
319 *count = fRec->fDataCount; 319 *count = fRec->fDataCount;
320 } 320 }
321 name = fRec->name(); 321 name = fRec->name();
322 322
323 fRec = fRec->fNext; 323 fRec = fRec->fNext;
324 } 324 }
325 return name; 325 return name;
326 } 326 }
327 327
328 /////////////////////////////////////////////////////////////////////////////// 328 ///////////////////////////////////////////////////////////////////////////////
329 329
330 SkMetaData::Rec* SkMetaData::Rec::Alloc(size_t size) { 330 SkMetaData::Rec* SkMetaData::Rec::Alloc(size_t size) {
331 return (Rec*)sk_malloc_throw(size); 331 return (Rec*)sk_malloc_throw(size);
332 } 332 }
333 333
334 void SkMetaData::Rec::Free(Rec* rec) { 334 void SkMetaData::Rec::Free(Rec* rec) {
335 sk_free(rec); 335 sk_free(rec);
336 } 336 }
OLDNEW
« no previous file with comments | « src/core/SkMatrixImageFilter.cpp ('k') | src/core/SkMipMap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698