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

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

Issue 396143004: Add a working SkFontMgr_fontconfig. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Remove T& operator* from SkAutoTCallVProc. Created 6 years, 4 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
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 Call a function when this goes out of scope. The template uses two 70 Call a function when this goes out of scope. The template uses two
71 parameters, the object, and a function that is to be called in the destructo r. 71 parameters, the object, and a function that is to be called in the destructo r.
72 If detach() is called, the object reference is set to null. If the object 72 If detach() is called, the object reference is set to null. If the object
73 reference is null when the destructor is called, we do not call the 73 reference is null when the destructor is called, we do not call the
74 function. 74 function.
75 */ 75 */
76 template <typename T, void (*P)(T*)> class SkAutoTCallVProc : SkNoncopyable { 76 template <typename T, void (*P)(T*)> class SkAutoTCallVProc : SkNoncopyable {
77 public: 77 public:
78 SkAutoTCallVProc(T* obj): fObj(obj) {} 78 SkAutoTCallVProc(T* obj): fObj(obj) {}
79 ~SkAutoTCallVProc() { if (fObj) P(fObj); } 79 ~SkAutoTCallVProc() { if (fObj) P(fObj); }
80
81 operator T*() const { return fObj; }
82 T* operator->() const { SkASSERT(fObj); return fObj; }
83
80 T* detach() { T* obj = fObj; fObj = NULL; return obj; } 84 T* detach() { T* obj = fObj; fObj = NULL; return obj; }
85 void reset(T* obj = NULL) {
86 if (fObj != obj) {
87 if (fObj) {
88 P(fObj);
89 }
90 fObj = obj;
91 }
92 }
81 private: 93 private:
82 T* fObj; 94 T* fObj;
83 }; 95 };
84 96
85 /** \class SkAutoTCallIProc 97 /** \class SkAutoTCallIProc
86 98
87 Call a function when this goes out of scope. The template uses two 99 Call a function when this goes out of scope. The template uses two
88 parameters, the object, and a function that is to be called in the destructor. 100 parameters, the object, and a function that is to be called in the destructor.
89 If detach() is called, the object reference is set to null. If the object 101 If detach() is called, the object reference is set to null. If the object
90 reference is null when the destructor is called, we do not call the 102 reference is null when the destructor is called, we do not call the
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 /** 482 /**
471 * Returns void* because this object does not initialize the 483 * Returns void* because this object does not initialize the
472 * memory. Use placement new for types that require a cons. 484 * memory. Use placement new for types that require a cons.
473 */ 485 */
474 void* get() { return fStorage.get(); } 486 void* get() { return fStorage.get(); }
475 private: 487 private:
476 SkAlignedSStorage<sizeof(T)*N> fStorage; 488 SkAlignedSStorage<sizeof(T)*N> fStorage;
477 }; 489 };
478 490
479 #endif 491 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698