00001 /**************************************************************************** 00002 ** 00003 ** Copyright (C) Qxt Foundation. Some rights reserved. 00004 ** 00005 ** This file is part of the QxtCore module of the Qxt library. 00006 ** 00007 ** This library is free software; you can redistribute it and/or modify it 00008 ** under the terms of the Common Public License, version 1.0, as published 00009 ** by IBM, and/or under the terms of the GNU Lesser General Public License, 00010 ** version 2.1, as published by the Free Software Foundation. 00011 ** 00012 ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY 00013 ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY 00014 ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR 00015 ** FITNESS FOR A PARTICULAR PURPOSE. 00016 ** 00017 ** You should have received a copy of the CPL and the LGPL along with this 00018 ** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files 00019 ** included with the source distribution for more information. 00020 ** If you did not receive a copy of the licenses, contact the Qxt Foundation. 00021 ** 00022 ** <http://libqxt.org> <foundation@libqxt.org> 00023 ** 00024 ****************************************************************************/ 00025 00026 /**************************************************************************** 00027 ** This file is derived from code bearing the following notice: 00028 ** The sole author of this file, Adam Higerd, has explicitly disclaimed all 00029 ** copyright interest and protection for the content within. This file has 00030 ** been placed in the public domain according to United States copyright 00031 ** statute and case law. In jurisdictions where this public domain dedication 00032 ** is not legally recognized, anyone who receives a copy of this file is 00033 ** permitted to use, modify, duplicate, and redistribute this file, in whole 00034 ** or in part, with no restrictions or conditions. In these jurisdictions, 00035 ** this file shall be copyright (C) 2006-2008 by Adam Higerd. 00036 ****************************************************************************/ 00037 00121 #ifndef QXTPIMPL_H 00122 #define QXTPIMPL_H 00123 00129 #define QXT_DECLARE_PRIVATE(PUB) friend class PUB##Private; QxtPrivateInterface<PUB, PUB##Private> qxt_d; 00130 00135 #define QXT_DECLARE_PUBLIC(PUB) friend class PUB; 00136 00142 #define QXT_INIT_PRIVATE(PUB) qxt_d.setPublic(this); 00143 00148 #define QXT_D(PUB) PUB##Private& d = qxt_d() 00149 00154 #define QXT_P(PUB) PUB& p = qxt_p() 00155 00156 #ifdef QXT_DOXYGEN_RUN 00157 00162 QxtPrivate<PUB>& qxt_d(); 00163 00170 const QxtPrivate<PUB>& qxt_d(); 00171 00177 PUB& qxt_p(); 00178 00185 const PUB& qxt_p(); 00186 #endif 00187 00188 #ifndef QXT_DOXYGEN_RUN 00189 template <typename PUB> 00190 class QxtPrivate 00191 { 00192 public: 00193 virtual ~QxtPrivate() 00194 {} 00195 inline void QXT_setPublic(PUB* pub) 00196 { 00197 qxt_p_ptr = pub; 00198 } 00199 00200 protected: 00201 inline PUB& qxt_p() 00202 { 00203 return *qxt_p_ptr; 00204 } 00205 inline const PUB& qxt_p() const 00206 { 00207 return *qxt_p_ptr; 00208 } 00209 00210 private: 00211 PUB* qxt_p_ptr; 00212 }; 00213 00214 template <typename PUB, typename PVT> 00215 class QxtPrivateInterface 00216 { 00217 friend class QxtPrivate<PUB>; 00218 public: 00219 QxtPrivateInterface() 00220 { 00221 pvt = new PVT; 00222 } 00223 ~QxtPrivateInterface() 00224 { 00225 delete pvt; 00226 } 00227 00228 inline void setPublic(PUB* pub) 00229 { 00230 pvt->QXT_setPublic(pub); 00231 } 00232 inline PVT& operator()() 00233 { 00234 return *static_cast<PVT*>(pvt); 00235 } 00236 inline const PVT& operator()() const 00237 { 00238 return *static_cast<PVT*>(pvt); 00239 } 00240 private: 00241 QxtPrivate<PUB>* pvt; 00242 }; 00243 #endif 00244 00245 #endif