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

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

Issue 23453031: Rewrite SkTRegistry to take any trivially-copyable type. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: reed+scroggo Created 7 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 | Annotate | Revision Log
« no previous file with comments | « include/core/SkImageEncoder.h ('k') | src/images/SkImageDecoder_FactoryDefault.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 2009 The Android Open Source Project 3 * Copyright 2009 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 SkTRegistry_DEFINED 10 #ifndef SkTRegistry_DEFINED
11 #define SkTRegistry_DEFINED 11 #define SkTRegistry_DEFINED
12 12
13 #include "SkTypes.h" 13 #include "SkTypes.h"
14 14
15 /** Template class that registers itself (in the constructor) into a linked-list 15 /** Template class that registers itself (in the constructor) into a linked-list
16 and provides a function-pointer. This can be used to auto-register a set of 16 and provides a function-pointer. This can be used to auto-register a set of
17 services, e.g. a set of image codecs. 17 services, e.g. a set of image codecs.
18 */ 18 */
19 template <typename T, typename P> class SkTRegistry : SkNoncopyable { 19 template <typename T> class SkTRegistry : SkNoncopyable {
20 public: 20 public:
21 typedef T (*Factory)(P); 21 typedef T Factory;
22 22
23 SkTRegistry(Factory fact) { 23 explicit SkTRegistry(T fact) : fFact(fact) {
24 #ifdef SK_BUILD_FOR_ANDROID 24 #ifdef SK_BUILD_FOR_ANDROID
25 // work-around for double-initialization bug 25 // work-around for double-initialization bug
26 { 26 {
27 SkTRegistry* reg = gHead; 27 SkTRegistry* reg = gHead;
28 while (reg) { 28 while (reg) {
29 if (reg == this) { 29 if (reg == this) {
30 return; 30 return;
31 } 31 }
32 reg = reg->fChain; 32 reg = reg->fChain;
33 } 33 }
34 } 34 }
35 #endif 35 #endif
36 fFact = fact;
37 fChain = gHead; 36 fChain = gHead;
38 gHead = this; 37 gHead = this;
39 } 38 }
40 39
41 static const SkTRegistry* Head() { return gHead; } 40 static const SkTRegistry* Head() { return gHead; }
42 41
43 const SkTRegistry* next() const { return fChain; } 42 const SkTRegistry* next() const { return fChain; }
44 Factory factory() const { return fFact; } 43 const Factory& factory() const { return fFact; }
45 44
46 private: 45 private:
47 Factory fFact; 46 Factory fFact;
48 SkTRegistry* fChain; 47 SkTRegistry* fChain;
49 48
50 static SkTRegistry* gHead; 49 static SkTRegistry* gHead;
51 }; 50 };
52 51
53 // The caller still needs to declare an instance of this somewhere 52 // The caller still needs to declare an instance of this somewhere
54 template <typename T, typename P> SkTRegistry<T, P>* SkTRegistry<T, P>::gHead; 53 template <typename T> SkTRegistry<T>* SkTRegistry<T>::gHead;
55 54
56 #endif 55 #endif
OLDNEW
« no previous file with comments | « include/core/SkImageEncoder.h ('k') | src/images/SkImageDecoder_FactoryDefault.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698