TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
ttkprivate.h
Go to the documentation of this file.
1 #ifndef TTKPRIVATE_H
2 #define TTKPRIVATE_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 "ttkmoduleexport.h"
23 
24 #define TTK_CREATE_PRIVATE(Class) (*new Class##Private)
25 
26 #define TTK_DECLARE_PRIVATE(Class) \
27  friend class Class##Private; \
28  TTKPrivateInterface<Class, Class##Private> ttk_d;
29 
30 #define TTK_DECLARE_PUBLIC(Class) \
31  friend class Class;
32 
33 #define TTK_INIT_PRIVATE(Class) \
34  ttk_d.setPrivate(new Class##Private); \
35  ttk_d.setPublic(this);
36 
37 #define TTK_INIT_PRIVATE_D(PVT) \
38  ttk_d.setPrivate(&PVT); \
39  ttk_d.setPublic(this);
40 
41 #define TTK_D(Class) Class##Private *const d = TTKStaticCast(Class##Private*, ttk_d())
42 #define TTK_Q(Class) Class *const q = TTKStaticCast(Class*, ttk_q())
43 
44 template <typename PUB>
49 {
50 public:
55  : m_qptr(nullptr)
56  {
57 
58  }
59 
63  virtual ~TTKPrivate() = default;
64 
68  inline void setPublic(PUB* pub)
69  {
70  m_qptr = pub;
71  }
72 
73 protected:
77  inline PUB *ttk_q() const
78  {
79  return m_qptr;
80  }
81 
82 private:
83  PUB *m_qptr;
84 
85 };
86 
87 
88 template <typename PUB, typename PVT>
93 {
94  friend class TTKPrivate<PUB>;
95 public:
100  : m_dptr(nullptr)
101  {
102 
103  }
104 
106  : m_dptr(pvt)
107  {
108 
109  }
110 
115  {
116  delete m_dptr;
117  }
118 
122  inline void setPrivate(PVT* pvt)
123  {
124  delete m_dptr;
125  m_dptr = pvt;
126  }
127 
131  inline void setPublic(PUB* pub)
132  {
133  m_dptr->setPublic(pub);
134  }
135 
139  inline PVT *operator()() const
140  {
141  return TTKStaticCast(PVT*, m_dptr);
142  }
143 
144 private:
147 
148 };
149 
150 #endif // TTKPRIVATE_H
#define TTKStaticCast(x, y)
Definition: ttkglobal.h:159
#define TTK_MODULE_EXPORT
PUB * ttk_q() const
Definition: ttkprivate.h:77
void setPrivate(PVT *pvt)
Definition: ttkprivate.h:122
TTKPrivate< PUB > * m_dptr
Definition: ttkprivate.h:145
void setPublic(PUB *pub)
Definition: ttkprivate.h:68
PUB * m_qptr
Definition: ttkprivate.h:83
TTKPrivateInterface(PVT *pvt)
Definition: ttkprivate.h:105
PVT * operator()() const
Definition: ttkprivate.h:139
The class of the ttk private interface.
Definition: ttkprivate.h:92
#define TTK_DISABLE_COPY(Class)
Definition: ttkqtglobal.h:141
void setPublic(PUB *pub)
Definition: ttkprivate.h:131
The class of the ttk private base.
Definition: ttkprivate.h:48