1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
/*!
* a simple singleton template for std c++ 11 or later.
*
* example:
*
* class ExampleSingleton : public QObject, public Dtk::DSingleton<ExampleSingleton>
* {
* Q_OBJECT
* friend class DSingleton<ExampleSingleton>;
* };
*
* Warning: for Qt, "public DSingleton<LyricService>" must be after QObject.
*/
template <class T>
class DSingleton
{
public:
static inline T *instance()
{
static T *_instance = new T;
return _instance;
}
protected:
DSingleton(void) {}
~DSingleton(void) {}
DSingleton(const DSingleton &) {}
DSingleton &operator= (const DSingleton &) {}
};
|