author | simon <simon> | 2002-12-11 17:18:17 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-11 17:18:17 (UTC) |
commit | 75f0ed4978579eb4b27cdece64c597741ed24b79 (patch) (unidiff) | |
tree | 6443323e08a9639ad0db7b5b1852d3804172e70a /noncore/multimedia/opieplayer2/singleton.h | |
parent | 94461696cfdcf8cdbaabec1400300e546edc447e (diff) | |
download | opie-75f0ed4978579eb4b27cdece64c597741ed24b79.zip opie-75f0ed4978579eb4b27cdece64c597741ed24b79.tar.gz opie-75f0ed4978579eb4b27cdece64c597741ed24b79.tar.bz2 |
- added a skin cache and a threaded skin loader. looks like the latter
we have to disable though, because pure image loading with qt is
anything but threadsafe :(
Diffstat (limited to 'noncore/multimedia/opieplayer2/singleton.h') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/singleton.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/noncore/multimedia/opieplayer2/singleton.h b/noncore/multimedia/opieplayer2/singleton.h new file mode 100644 index 0000000..35b3dff --- a/dev/null +++ b/noncore/multimedia/opieplayer2/singleton.h | |||
@@ -0,0 +1,49 @@ | |||
1 | #ifndef SINGLETON_H | ||
2 | #define SINGLETON_H | ||
3 | |||
4 | template <class Product> | ||
5 | struct DefaultSingletonCreator | ||
6 | { | ||
7 | static Product *create() { return new Product; } | ||
8 | }; | ||
9 | |||
10 | template <class Product> | ||
11 | struct NullSingletonCreator | ||
12 | { | ||
13 | static Product *create() { return 0; } | ||
14 | }; | ||
15 | |||
16 | template | ||
17 | < | ||
18 | class T, | ||
19 | template <class> class Creator = DefaultSingletonCreator | ||
20 | > | ||
21 | class Singleton | ||
22 | { | ||
23 | public: | ||
24 | static T &self() | ||
25 | { | ||
26 | if ( !s_self ) | ||
27 | s_self = Creator<T>::create(); | ||
28 | return *s_self; | ||
29 | } | ||
30 | |||
31 | protected: | ||
32 | Singleton() | ||
33 | { s_self = static_cast<T *>( this ); } | ||
34 | ~Singleton() | ||
35 | { s_self = 0; } | ||
36 | |||
37 | private: | ||
38 | Singleton( const Singleton<T, Creator> &rhs ); | ||
39 | Singleton<T, Creator> &operator=( const Singleton<T, Creator> &rhs ); | ||
40 | |||
41 | static T *s_self; | ||
42 | }; | ||
43 | |||
44 | template <class T, template <class> class Creator> | ||
45 | T *Singleton<T, Creator>::s_self = 0; | ||
46 | |||
47 | #endif // SINGLETON_H | ||
48 | /* vim: et sw=4 ts=4 | ||
49 | */ | ||