Miam-Player  0.8.0
A nice music player
qxtglobal.h
Go to the documentation of this file.
1 
2 /****************************************************************************
3 ** Copyright (c) 2006 - 2011, the LibQxt project.
4 ** See the Qxt AUTHORS file for a list of authors and copyright holders.
5 ** All rights reserved.
6 **
7 ** Redistribution and use in source and binary forms, with or without
8 ** modification, are permitted provided that the following conditions are met:
9 ** * Redistributions of source code must retain the above copyright
10 ** notice, this list of conditions and the following disclaimer.
11 ** * Redistributions in binary form must reproduce the above copyright
12 ** notice, this list of conditions and the following disclaimer in the
13 ** documentation and/or other materials provided with the distribution.
14 ** * Neither the name of the LibQxt project nor the
15 ** names of its contributors may be used to endorse or promote products
16 ** derived from this software without specific prior written permission.
17 **
18 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 ** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
22 ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 **
29 ** <http://libqxt.org> <foundation@libqxt.org>
30 *****************************************************************************/
31 
32 #ifndef QXTGLOBAL_H
33 #define QXTGLOBAL_H
34 
35 #include <QtGlobal>
36 
37 /****************************************************************************
38 ** This file is derived from code bearing the following notice:
39 ** The sole author of this file, Adam Higerd, has explicitly disclaimed all
40 ** copyright interest and protection for the content within. This file has
41 ** been placed in the public domain according to United States copyright
42 ** statute and case law. In jurisdictions where this public domain dedication
43 ** is not legally recognized, anyone who receives a copy of this file is
44 ** permitted to use, modify, duplicate, and redistribute this file, in whole
45 ** or in part, with no restrictions or conditions. In these jurisdictions,
46 ** this file shall be copyright (C) 2006-2008 by Adam Higerd.
47 ****************************************************************************/
48 
49 #define QXT_DECLARE_PRIVATE(PUB) friend class PUB##Private; QxtPrivateInterface<PUB, PUB##Private> qxt_d;
50 #define QXT_DECLARE_PUBLIC(PUB) friend class PUB;
51 #define QXT_INIT_PRIVATE(PUB) qxt_d.setPublic(this);
52 #define QXT_D(PUB) PUB##Private& d = qxt_d()
53 
54 template <typename PUB>
56 {
57 public:
58  virtual ~QxtPrivate()
59  {}
60  inline void QXT_setPublic(PUB* pub)
61  {
62  qxt_p_ptr = pub;
63  }
64 
65 protected:
66  inline PUB& qxt_p()
67  {
68  return *qxt_p_ptr;
69  }
70  inline const PUB& qxt_p() const
71  {
72  return *qxt_p_ptr;
73  }
74  inline PUB* qxt_ptr()
75  {
76  return qxt_p_ptr;
77  }
78  inline const PUB* qxt_ptr() const
79  {
80  return qxt_p_ptr;
81  }
82 
83 private:
84  PUB* qxt_p_ptr;
85 };
86 
87 template <typename PUB, typename PVT>
89 {
90  friend class QxtPrivate<PUB>;
91 public:
93  {
94  pvt = new PVT;
95  }
97  {
98  delete pvt;
99  }
100 
101  inline void setPublic(PUB* pub)
102  {
103  pvt->QXT_setPublic(pub);
104  }
105  inline PVT& operator()()
106  {
107  return *static_cast<PVT*>(pvt);
108  }
109  inline const PVT& operator()() const
110  {
111  return *static_cast<PVT*>(pvt);
112  }
113  inline PVT * operator->()
114  {
115  return static_cast<PVT*>(pvt);
116  }
117  inline const PVT * operator->() const
118  {
119  return static_cast<PVT*>(pvt);
120  }
121 private:
123  QxtPrivateInterface& operator=(const QxtPrivateInterface&) { }
124  QxtPrivate<PUB>* pvt;
125 };
126 
127 #endif // QXT_GLOBAL
Definition: qxtglobal.h:88
QxtPrivateInterface()
Definition: qxtglobal.h:92
PVT * operator->()
Definition: qxtglobal.h:113
void QXT_setPublic(PUB *pub)
Definition: qxtglobal.h:60
const PVT & operator()() const
Definition: qxtglobal.h:109
Definition: qxtglobal.h:55
const PUB * qxt_ptr() const
Definition: qxtglobal.h:78
PUB * qxt_ptr()
Definition: qxtglobal.h:74
const PUB & qxt_p() const
Definition: qxtglobal.h:70
virtual ~QxtPrivate()
Definition: qxtglobal.h:58
void setPublic(PUB *pub)
Definition: qxtglobal.h:101
const PVT * operator->() const
Definition: qxtglobal.h:117
~QxtPrivateInterface()
Definition: qxtglobal.h:96
PUB & qxt_p()
Definition: qxtglobal.h:66
PVT & operator()()
Definition: qxtglobal.h:105