qxtglobal.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /****************************************************************************
  2. ** Copyright (c) 2006 - 2011, the LibQxt project.
  3. ** See the Qxt AUTHORS file for a list of authors and copyright holders.
  4. ** All rights reserved.
  5. **
  6. ** Redistribution and use in source and binary forms, with or without
  7. ** modification, are permitted provided that the following conditions are met:
  8. ** * Redistributions of source code must retain the above copyright
  9. ** notice, this list of conditions and the following disclaimer.
  10. ** * Redistributions in binary form must reproduce the above copyright
  11. ** notice, this list of conditions and the following disclaimer in the
  12. ** documentation and/or other materials provided with the distribution.
  13. ** * Neither the name of the LibQxt project nor the
  14. ** names of its contributors may be used to endorse or promote products
  15. ** derived from this software without specific prior written permission.
  16. **
  17. ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. ** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  21. ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. **
  28. ** <http://libqxt.org> <foundation@libqxt.org>
  29. *****************************************************************************/
  30. #ifndef QXTGLOBAL_H
  31. #define QXTGLOBAL_H
  32. #include <QtGlobal>
  33. #define QXT_VERSION 0x000700
  34. #define QXT_VERSION_STR "0.7.0"
  35. //--------------------------global macros------------------------------
  36. #ifndef QXT_NO_MACROS
  37. #ifndef _countof
  38. #define _countof(x) (sizeof(x)/sizeof(*x))
  39. #endif
  40. #endif // QXT_NO_MACROS
  41. //--------------------------export macros------------------------------
  42. #define QXT_DLLEXPORT DO_NOT_USE_THIS_ANYMORE
  43. #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
  44. # if defined(BUILD_QXT_CORE)
  45. # define QXT_CORE_EXPORT Q_DECL_EXPORT
  46. # else
  47. # define QXT_CORE_EXPORT Q_DECL_IMPORT
  48. # endif
  49. #else
  50. # define QXT_CORE_EXPORT
  51. #endif // BUILD_QXT_CORE
  52. #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
  53. # if defined(BUILD_QXT_GUI)
  54. # define QXT_GUI_EXPORT Q_DECL_EXPORT
  55. # else
  56. # define QXT_GUI_EXPORT Q_DECL_IMPORT
  57. # endif
  58. #else
  59. # define QXT_GUI_EXPORT
  60. #endif // BUILD_QXT_GUI
  61. #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
  62. # if defined(BUILD_QXT_NETWORK)
  63. # define QXT_NETWORK_EXPORT Q_DECL_EXPORT
  64. # else
  65. # define QXT_NETWORK_EXPORT Q_DECL_IMPORT
  66. # endif
  67. #else
  68. # define QXT_NETWORK_EXPORT
  69. #endif // BUILD_QXT_NETWORK
  70. #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
  71. # if defined(BUILD_QXT_SQL)
  72. # define QXT_SQL_EXPORT Q_DECL_EXPORT
  73. # else
  74. # define QXT_SQL_EXPORT Q_DECL_IMPORT
  75. # endif
  76. #else
  77. # define QXT_SQL_EXPORT
  78. #endif // BUILD_QXT_SQL
  79. #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
  80. # if defined(BUILD_QXT_WEB)
  81. # define QXT_WEB_EXPORT Q_DECL_EXPORT
  82. # else
  83. # define QXT_WEB_EXPORT Q_DECL_IMPORT
  84. # endif
  85. #else
  86. # define QXT_WEB_EXPORT
  87. #endif // BUILD_QXT_WEB
  88. #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
  89. # if defined(BUILD_QXT_BERKELEY)
  90. # define QXT_BERKELEY_EXPORT Q_DECL_EXPORT
  91. # else
  92. # define QXT_BERKELEY_EXPORT Q_DECL_IMPORT
  93. # endif
  94. #else
  95. # define QXT_BERKELEY_EXPORT
  96. #endif // BUILD_QXT_BERKELEY
  97. #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
  98. # if defined(BUILD_QXT_ZEROCONF)
  99. # define QXT_ZEROCONF_EXPORT Q_DECL_EXPORT
  100. # else
  101. # define QXT_ZEROCONF_EXPORT Q_DECL_IMPORT
  102. # endif
  103. #else
  104. # define QXT_ZEROCONF_EXPORT
  105. #endif // QXT_ZEROCONF_EXPORT
  106. #if defined(BUILD_QXT_CORE) || defined(BUILD_QXT_GUI) || defined(BUILD_QXT_SQL) || defined(BUILD_QXT_NETWORK) || defined(BUILD_QXT_WEB) || defined(BUILD_QXT_BERKELEY) || defined(BUILD_QXT_ZEROCONF)
  107. # define BUILD_QXT
  108. #endif
  109. QXT_CORE_EXPORT const char* qxtVersion();
  110. #ifndef QT_BEGIN_NAMESPACE
  111. #define QT_BEGIN_NAMESPACE
  112. #endif
  113. #ifndef QT_END_NAMESPACE
  114. #define QT_END_NAMESPACE
  115. #endif
  116. #ifndef QT_FORWARD_DECLARE_CLASS
  117. #define QT_FORWARD_DECLARE_CLASS(Class) class Class;
  118. #endif
  119. /****************************************************************************
  120. ** This file is derived from code bearing the following notice:
  121. ** The sole author of this file, Adam Higerd, has explicitly disclaimed all
  122. ** copyright interest and protection for the content within. This file has
  123. ** been placed in the public domain according to United States copyright
  124. ** statute and case law. In jurisdictions where this public domain dedication
  125. ** is not legally recognized, anyone who receives a copy of this file is
  126. ** permitted to use, modify, duplicate, and redistribute this file, in whole
  127. ** or in part, with no restrictions or conditions. In these jurisdictions,
  128. ** this file shall be copyright (C) 2006-2008 by Adam Higerd.
  129. ****************************************************************************/
  130. #define QXT_DECLARE_PRIVATE(PUB) friend class PUB##Private; QxtPrivateInterface<PUB, PUB##Private> qxt_d;
  131. #define QXT_DECLARE_PUBLIC(PUB) friend class PUB;
  132. #define QXT_INIT_PRIVATE(PUB) qxt_d.setPublic(this);
  133. #define QXT_D(PUB) PUB##Private& d = qxt_d()
  134. #define QXT_P(PUB) PUB& p = qxt_p()
  135. template <typename PUB>
  136. class QxtPrivate
  137. {
  138. public:
  139. virtual ~QxtPrivate()
  140. {}
  141. inline void QXT_setPublic(PUB* pub)
  142. {
  143. qxt_p_ptr = pub;
  144. }
  145. protected:
  146. inline PUB& qxt_p()
  147. {
  148. return *qxt_p_ptr;
  149. }
  150. inline const PUB& qxt_p() const
  151. {
  152. return *qxt_p_ptr;
  153. }
  154. inline PUB* qxt_ptr()
  155. {
  156. return qxt_p_ptr;
  157. }
  158. inline const PUB* qxt_ptr() const
  159. {
  160. return qxt_p_ptr;
  161. }
  162. private:
  163. PUB* qxt_p_ptr;
  164. };
  165. template <typename PUB, typename PVT>
  166. class QxtPrivateInterface
  167. {
  168. friend class QxtPrivate<PUB>;
  169. public:
  170. QxtPrivateInterface()
  171. {
  172. pvt = new PVT;
  173. }
  174. ~QxtPrivateInterface()
  175. {
  176. delete pvt;
  177. }
  178. inline void setPublic(PUB* pub)
  179. {
  180. pvt->QXT_setPublic(pub);
  181. }
  182. inline PVT& operator()()
  183. {
  184. return *static_cast<PVT*>(pvt);
  185. }
  186. inline const PVT& operator()() const
  187. {
  188. return *static_cast<PVT*>(pvt);
  189. }
  190. inline PVT * operator->()
  191. {
  192. return static_cast<PVT*>(pvt);
  193. }
  194. inline const PVT * operator->() const
  195. {
  196. return static_cast<PVT*>(pvt);
  197. }
  198. private:
  199. QxtPrivateInterface(const QxtPrivateInterface&) { }
  200. QxtPrivateInterface& operator=(const QxtPrivateInterface&) { }
  201. QxtPrivate<PUB>* pvt;
  202. };
  203. #endif // QXT_GLOBAL