TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
ttksingleton.h
Go to the documentation of this file.
1 #ifndef TTKSINGLETON_H
2 #define TTKSINGLETON_H
3 
4 /***************************************************************************
5  * This file is part of the TTK Library Module project
6  * Copyright (C) 2015 - 2024 Greedysky Studio
7 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17 
18  * You should have received a copy of the GNU Lesser General Public License along
19  * with this program; If not, see <http://www.gnu.org/licenses/>.
20  ***************************************************************************/
21 
22 #include <QMutex>
23 #include <QScopedPointer>
24 #include "ttkmoduleexport.h"
25 
26 template <typename T>
31 {
32 public:
36  static T* createInstance();
37 
38 private:
42  TTKSingleton() = default;
46  ~TTKSingleton() = default;
47 
48  static QMutex m_mutex;
49  static QScopedPointer<T> m_instance;
51 
52 };
53 
59 
60 template <typename T> QMutex TTKSingleton<T>::m_mutex;
61 template <typename T> QScopedPointer<T> TTKSingleton<T>::m_instance;
62 
63 template <typename T>
65 {
66  if(m_instance.isNull())
67  {
68  m_mutex.lock();
69  if(m_instance.isNull())
70  {
71  m_instance.reset(new T());
72  }
73  m_mutex.unlock();
74  }
75  return m_instance.data();
76 }
77 
83 
86 #define TTK_DECLARE_SINGLETON_CLASS(Class) \
87  friend class TTKSingleton<Class>; \
88  friend struct QScopedPointerDeleter<Class>;
89 
90 #endif // TTKSINGLETON_H
#define TTK_MODULE_EXPORT
#define T(v)
Definition: http_parser.c:237
The class of the singleton base.
Definition: ttksingleton.h:30
static T * createInstance()
Definition: ttksingleton.h:64
static QMutex m_mutex
// Singleton Implementation // //
Definition: ttksingleton.h:48
static QScopedPointer< T > m_instance
Definition: ttksingleton.h:49
#define TTK_DISABLE_COPY(Class)
Definition: ttkqtglobal.h:141