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

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: Fix ttc index and descriptor. Created 6 years, 5 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; }
mtklein 2014/07/22 15:48:42 Is there any chance, given that we get to start fr
bungeman-skia 2014/07/22 22:09:57 Not sure what you mean here. If you create an SkAu
82 T& operator*() const { SkASSERT(fObj); return *fObj; }
83 T* operator->() const { SkASSERT(fObj); return fObj; }
84 T** operator&() { return &fObj; }
mtklein 2014/07/22 15:48:42 Can we avoid this one? Seems really easy to write
bungeman-skia 2014/07/22 22:09:57 It is, but it makes certain things easier when dea
85
80 T* detach() { T* obj = fObj; fObj = NULL; return obj; } 86 T* detach() { T* obj = fObj; fObj = NULL; return obj; }
87 void reset(T* obj = NULL) {
88 if (fObj != obj) {
89 if (fObj) {
90 P(fObj);
91 }
92 fObj = obj;
93 }
94 }
81 private: 95 private:
82 T* fObj; 96 T* fObj;
83 }; 97 };
84 98
85 /** \class SkAutoTCallIProc 99 /** \class SkAutoTCallIProc
86 100
87 Call a function when this goes out of scope. The template uses two 101 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. 102 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 103 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 104 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 /** 484 /**
471 * Returns void* because this object does not initialize the 485 * Returns void* because this object does not initialize the
472 * memory. Use placement new for types that require a cons. 486 * memory. Use placement new for types that require a cons.
473 */ 487 */
474 void* get() { return fStorage.get(); } 488 void* get() { return fStorage.get(); }
475 private: 489 private:
476 SkAlignedSStorage<sizeof(T)*N> fStorage; 490 SkAlignedSStorage<sizeof(T)*N> fStorage;
477 }; 491 };
478 492
479 #endif 493 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698