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

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

Issue 13831011: use SkAutoTDelete instead of SkTScopedPtr (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 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 | « bench/GrMemoryPoolBench.cpp ('k') | tests/GrMemoryPoolTest.cpp » ('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 SkTemplates_DEFINED 10 #ifndef SkTemplates_DEFINED
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 */ 73 */
74 template <typename T, int (*P)(T*)> class SkAutoTCallIProc : SkNoncopyable { 74 template <typename T, int (*P)(T*)> class SkAutoTCallIProc : SkNoncopyable {
75 public: 75 public:
76 SkAutoTCallIProc(T* obj): fObj(obj) {} 76 SkAutoTCallIProc(T* obj): fObj(obj) {}
77 ~SkAutoTCallIProc() { if (fObj) P(fObj); } 77 ~SkAutoTCallIProc() { if (fObj) P(fObj); }
78 T* detach() { T* obj = fObj; fObj = NULL; return obj; } 78 T* detach() { T* obj = fObj; fObj = NULL; return obj; }
79 private: 79 private:
80 T* fObj; 80 T* fObj;
81 }; 81 };
82 82
83 // See also SkTScopedPtr.
84 template <typename T> class SkAutoTDelete : SkNoncopyable { 83 template <typename T> class SkAutoTDelete : SkNoncopyable {
85 public: 84 public:
86 SkAutoTDelete(T* obj) : fObj(obj) {} 85 SkAutoTDelete(T* obj = NULL) : fObj(obj) {}
87 ~SkAutoTDelete() { delete fObj; } 86 ~SkAutoTDelete() { delete fObj; }
88 87
89 T* get() const { return fObj; } 88 T* get() const { return fObj; }
90 T& operator*() const { SkASSERT(fObj); return *fObj; } 89 T& operator*() const { SkASSERT(fObj); return *fObj; }
91 T* operator->() const { SkASSERT(fObj); return fObj; } 90 T* operator->() const { SkASSERT(fObj); return fObj; }
92 91
92 void reset(T* obj) {
93 if (fObj != obj) {
94 delete fObj;
95 fObj = obj;
96 }
97 }
98
93 /** 99 /**
94 * Delete the owned object, setting the internal pointer to NULL. 100 * Delete the owned object, setting the internal pointer to NULL.
95 */ 101 */
96 void free() { 102 void free() {
97 delete fObj; 103 delete fObj;
98 fObj = NULL; 104 fObj = NULL;
99 } 105 }
100 106
101 /** 107 /**
102 * Transfer ownership of the object to the caller, setting the internal 108 * Transfer ownership of the object to the caller, setting the internal
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 /** 355 /**
350 * Returns void* because this object does not initialize the 356 * Returns void* because this object does not initialize the
351 * memory. Use placement new for types that require a cons. 357 * memory. Use placement new for types that require a cons.
352 */ 358 */
353 void* get() { return fStorage.get(); } 359 void* get() { return fStorage.get(); }
354 private: 360 private:
355 SkAlignedSStorage<sizeof(T)*N> fStorage; 361 SkAlignedSStorage<sizeof(T)*N> fStorage;
356 }; 362 };
357 363
358 #endif 364 #endif
OLDNEW
« no previous file with comments | « bench/GrMemoryPoolBench.cpp ('k') | tests/GrMemoryPoolTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698