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

Side by Side Diff: include/core/SkTDArray.h

Issue 12315131: Make SkTDArray accessors const-friendly (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | include/core/SkTDict.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 #ifndef SkTDArray_DEFINED 10 #ifndef SkTDArray_DEFINED
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 /** 95 /**
96 * Return the number of elements in the array 96 * Return the number of elements in the array
97 */ 97 */
98 int count() const { return (int)fCount; } 98 int count() const { return (int)fCount; }
99 99
100 /** 100 /**
101 * return the number of bytes in the array: count * sizeof(T) 101 * return the number of bytes in the array: count * sizeof(T)
102 */ 102 */
103 size_t bytes() const { return fCount * sizeof(T); } 103 size_t bytes() const { return fCount * sizeof(T); }
104 104
105 T* begin() const { return fArray; } 105 T* begin() { return fArray; }
106 T* end() const { return fArray ? fArray + fCount : NULL; } 106 const T* begin() const { return fArray; }
107 T& operator[](int index) const { 107 T* end() { return fArray ? fArray + fCount : NULL; }
108 const T* end() const { return fArray ? fArray + fCount : NULL; }
109
110 T& operator[](int index) {
111 SkASSERT((unsigned)index < fCount);
112 return fArray[index];
113 }
114 const T& operator[](int index) const {
108 SkASSERT((unsigned)index < fCount); 115 SkASSERT((unsigned)index < fCount);
109 return fArray[index]; 116 return fArray[index];
110 } 117 }
111 118
112 T& getAt(int index) const { 119 T& getAt(int index) {
120 return (*this)[index];
121 }
122 const T& getAt(int index) const {
113 return (*this)[index]; 123 return (*this)[index];
114 } 124 }
115 125
116 void reset() { 126 void reset() {
117 if (fArray) { 127 if (fArray) {
118 sk_free(fArray); 128 sk_free(fArray);
119 fArray = NULL; 129 fArray = NULL;
120 #ifdef SK_DEBUG 130 #ifdef SK_DEBUG
121 fData = NULL; 131 fData = NULL;
122 #endif 132 #endif
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 void safeUnrefAll() { 309 void safeUnrefAll() {
300 T* iter = fArray; 310 T* iter = fArray;
301 T* stop = fArray + fCount; 311 T* stop = fArray + fCount;
302 while (iter < stop) { 312 while (iter < stop) {
303 SkSafeUnref(*iter); 313 SkSafeUnref(*iter);
304 iter += 1; 314 iter += 1;
305 } 315 }
306 this->reset(); 316 this->reset();
307 } 317 }
308 318
309 void visitAll(void visitor(T&)) const { 319 void visitAll(void visitor(T&)) {
310 T* stop = this->end(); 320 T* stop = this->end();
311 for (T* curr = this->begin(); curr < stop; curr++) { 321 for (T* curr = this->begin(); curr < stop; curr++) {
312 if (*curr) { 322 if (*curr) {
313 visitor(*curr); 323 visitor(*curr);
314 } 324 }
315 } 325 }
316 } 326 }
317 327
318 #ifdef SK_DEBUG 328 #ifdef SK_DEBUG
319 void validate() const { 329 void validate() const {
(...skipping 26 matching lines...) Expand all
346 #ifdef SK_DEBUG 356 #ifdef SK_DEBUG
347 fData = (ArrayT*)fArray; 357 fData = (ArrayT*)fArray;
348 #endif 358 #endif
349 fReserve = size; 359 fReserve = size;
350 } 360 }
351 fCount += extra; 361 fCount += extra;
352 } 362 }
353 }; 363 };
354 364
355 #endif 365 #endif
OLDNEW
« no previous file with comments | « no previous file | include/core/SkTDict.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698