forked from Greedysky/TTKMusicPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmusicprivate.h
60 lines (44 loc) · 1.44 KB
/
musicprivate.h
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef MUSICPRIVATE_H
#define MUSICPRIVATE_H
/* =================================================
* This file is part of the TTK Music Player project
* Copyright (c) 2015 - 2017 Greedysky Studio
* All rights reserved!
* Redistribution and use of the source code or any derivative
* works are strictly forbiden.
=================================================*/
#define TTK_DECLARE_PRIVATE(Class) \
friend class Class##Private; \
TTKPrivateInterface<Class, Class##Private> ttk_d;
#define TTK_DECLARE_PUBLIC(Class) \
friend class Class;
#define TTK_INIT_PRIVATE \
ttk_d.setPublic(this);
#define TTK_D(Class) Class##Private *const d = ttk_d()
#define TTK_Q(Class) Class *const q = ttk_q()
template <typename PUB>
class TTKPrivate
{
public:
virtual ~TTKPrivate() { }
inline void setPublic(PUB* pub) { ttk_q_ptr = pub; }
protected:
inline PUB *ttk_q() const { return ttk_q_ptr; }
private:
PUB* ttk_q_ptr;
};
template <typename PUB, typename PVT>
class TTKPrivateInterface
{
friend class TTKPrivate<PUB>;
public:
TTKPrivateInterface() { pvt = new PVT; }
~TTKPrivateInterface() { delete pvt; }
inline void setPublic(PUB* pub) { pvt->setPublic(pub); }
inline PVT *operator()() const { return static_cast<PVT*>(pvt); }
private:
TTKPrivateInterface(const TTKPrivateInterface&) { }
TTKPrivateInterface& operator=(const TTKPrivateInterface&) { }
TTKPrivate<PUB>* pvt;
};
#endif // MUSICPRIVATE_H