TTKMusicPlayer  4.2.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 - 2025 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> _d;
29 
30 #define TTK_DECLARE_PUBLIC(Class) \
31  friend class Class;
32 
33 #define TTK_INIT_PRIVATE(Class) \
34  _d.setPrivate(new Class##Private); \
35  _d.setPublic(this);
36 
37 #define TTK_INIT_PRIVATE_OBJECT(PVT) \
38  _d.setPrivate(&PVT); \
39  _d.setPublic(this);
40 
41 #define TTK_D(Class) Class##Private *const d = TTKStaticCast(Class##Private*, _d())
42 #define TTK_Q(Class) Class *const q = TTKStaticCast(Class*, _q())
43 
47 template <typename PUB>
49 {
50 public:
54  TTKPrivate() noexcept
55  : m_qptr(nullptr)
56  {
57 
58  }
59 
63  virtual ~TTKPrivate() = default;
64 
68  inline void setPublic(PUB* pub) noexcept
69  {
70  m_qptr = pub;
71  }
72 
73 protected:
77  inline PUB *_q() const noexcept
78  {
79  return m_qptr;
80  }
81 
82 private:
83  PUB *m_qptr;
84 
85 };
86 
87 
91 template <typename PUB, typename PVT>
93 {
94  friend class TTKPrivate<PUB>;
96 public:
101  : m_dptr(nullptr)
102  {
103 
104  }
105 
106  TTKPrivateInterface(PVT* pvt) noexcept
107  : m_dptr(pvt)
108  {
109 
110  }
111 
112  TTKPrivateInterface(PVT* pvt, PUB* pub) noexcept
113  : m_dptr(pvt)
114  {
115  setPublic(pub);
116  }
117 
122  {
123  delete m_dptr;
124  }
125 
129  inline void setPrivate(PVT* pvt) noexcept
130  {
131  delete m_dptr;
132  m_dptr = pvt;
133  }
134 
138  inline void setPublic(PUB* pub) noexcept
139  {
140  m_dptr->setPublic(pub);
141  }
142 
146  inline PVT *operator()() const noexcept
147  {
148  return TTKStaticCast(PVT*, m_dptr);
149  }
150 
151 private:
153 
154 };
155 
156 #endif // TTKPRIVATE_H
#define TTKStaticCast(x, y)
Definition: ttkglobal.h:231
#define TTK_MODULE_EXPORT
TTKPrivateInterface(PVT *pvt) noexcept
Definition: ttkprivate.h:106
~TTKPrivateInterface() noexcept
Definition: ttkprivate.h:121
void setPublic(PUB *pub) noexcept
Definition: ttkprivate.h:68
TTKPrivate< PUB > * m_dptr
Definition: ttkprivate.h:152
void setPrivate(PVT *pvt) noexcept
Definition: ttkprivate.h:129
TTKPrivateInterface(PVT *pvt, PUB *pub) noexcept
Definition: ttkprivate.h:112
void setPublic(PUB *pub) noexcept
Definition: ttkprivate.h:138
TTKPrivate() noexcept
Definition: ttkprivate.h:54
PUB * _q() const noexcept
Definition: ttkprivate.h:77
PUB * m_qptr
Definition: ttkprivate.h:83
The class of the ttk private interface.
Definition: ttkprivate.h:92
PVT * operator()() const noexcept
Definition: ttkprivate.h:146
#define const
Definition: zconf.h:233
#define TTK_DISABLE_COPY(Class)
Definition: ttkqtglobal.h:153
The class of the ttk private base.
Definition: ttkprivate.h:48