summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opieplayer2/singleton.h
authorsimon <simon>2002-12-11 17:18:17 (UTC)
committer simon <simon>2002-12-11 17:18:17 (UTC)
commit75f0ed4978579eb4b27cdece64c597741ed24b79 (patch) (side-by-side diff)
tree6443323e08a9639ad0db7b5b1852d3804172e70a /noncore/multimedia/opieplayer2/singleton.h
parent94461696cfdcf8cdbaabec1400300e546edc447e (diff)
downloadopie-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) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/singleton.h49
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 @@
+#ifndef SINGLETON_H
+#define SINGLETON_H
+
+template <class Product>
+struct DefaultSingletonCreator
+{
+ static Product *create() { return new Product; }
+};
+
+template <class Product>
+struct NullSingletonCreator
+{
+ static Product *create() { return 0; }
+};
+
+template
+<
+ class T,
+ template <class> class Creator = DefaultSingletonCreator
+>
+class Singleton
+{
+public:
+ static T &self()
+ {
+ if ( !s_self )
+ s_self = Creator<T>::create();
+ return *s_self;
+ }
+
+protected:
+ Singleton()
+ { s_self = static_cast<T *>( this ); }
+ ~Singleton()
+ { s_self = 0; }
+
+private:
+ Singleton( const Singleton<T, Creator> &rhs );
+ Singleton<T, Creator> &operator=( const Singleton<T, Creator> &rhs );
+
+ static T *s_self;
+};
+
+template <class T, template <class> class Creator>
+T *Singleton<T, Creator>::s_self = 0;
+
+#endif // SINGLETON_H
+/* vim: et sw=4 ts=4
+ */