| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 | 
|---|
| 2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/include/qguardedptr.h:1 -->
 | 
|---|
| 3 | <html>
 | 
|---|
| 4 | <head>
 | 
|---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
 | 
|---|
| 6 | <title>qguardedptr.h Include File</title>
 | 
|---|
| 7 | <style type="text/css"><!--
 | 
|---|
| 8 | fn { margin-left: 1cm; text-indent: -1cm; }
 | 
|---|
| 9 | a:link { color: #004faf; text-decoration: none }
 | 
|---|
| 10 | a:visited { color: #672967; text-decoration: none }
 | 
|---|
| 11 | body { background: #ffffff; color: black; }
 | 
|---|
| 12 | --></style>
 | 
|---|
| 13 | </head>
 | 
|---|
| 14 | <body>
 | 
|---|
| 15 | 
 | 
|---|
| 16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
 | 
|---|
| 17 | <tr bgcolor="#E5E5E5">
 | 
|---|
| 18 | <td valign=center>
 | 
|---|
| 19 |  <a href="index.html">
 | 
|---|
| 20 | <font color="#004faf">Home</font></a>
 | 
|---|
| 21 |  | <a href="classes.html">
 | 
|---|
| 22 | <font color="#004faf">All Classes</font></a>
 | 
|---|
| 23 |  | <a href="mainclasses.html">
 | 
|---|
| 24 | <font color="#004faf">Main Classes</font></a>
 | 
|---|
| 25 |  | <a href="annotated.html">
 | 
|---|
| 26 | <font color="#004faf">Annotated</font></a>
 | 
|---|
| 27 |  | <a href="groups.html">
 | 
|---|
| 28 | <font color="#004faf">Grouped Classes</font></a>
 | 
|---|
| 29 |  | <a href="functions.html">
 | 
|---|
| 30 | <font color="#004faf">Functions</font></a>
 | 
|---|
| 31 | </td>
 | 
|---|
| 32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>qguardedptr.h</h1>
 | 
|---|
| 33 | 
 | 
|---|
| 34 | <p>This is the verbatim text of the qguardedptr.h include file. It is provided only for illustration; the copyright remains with Trolltech.
 | 
|---|
| 35 | <hr>
 | 
|---|
| 36 | <pre>
 | 
|---|
| 37 | /****************************************************************************
 | 
|---|
| 38 | ** $Id: qguardedptr-h.html 2051 2007-02-21 10:04:20Z chehrlic $
 | 
|---|
| 39 | **
 | 
|---|
| 40 | ** Definition of QGuardedPtr class
 | 
|---|
| 41 | **
 | 
|---|
| 42 | ** Created : 990929
 | 
|---|
| 43 | **
 | 
|---|
| 44 | ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
 | 
|---|
| 45 | **
 | 
|---|
| 46 | ** This file is part of the kernel module of the Qt GUI Toolkit.
 | 
|---|
| 47 | **
 | 
|---|
| 48 | ** This file may be distributed under the terms of the Q Public License
 | 
|---|
| 49 | ** as defined by Trolltech ASA of Norway and appearing in the file
 | 
|---|
| 50 | ** LICENSE.QPL included in the packaging of this file.
 | 
|---|
| 51 | **
 | 
|---|
| 52 | ** This file may be distributed and/or modified under the terms of the
 | 
|---|
| 53 | ** GNU General Public License version 2 as published by the Free Software
 | 
|---|
| 54 | ** Foundation and appearing in the file LICENSE.GPL included in the
 | 
|---|
| 55 | ** packaging of this file.
 | 
|---|
| 56 | **
 | 
|---|
| 57 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
 | 
|---|
| 58 | ** licenses may use this file in accordance with the Qt Commercial License
 | 
|---|
| 59 | ** Agreement provided with the Software.
 | 
|---|
| 60 | **
 | 
|---|
| 61 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 | 
|---|
| 62 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 | 
|---|
| 63 | **
 | 
|---|
| 64 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 | 
|---|
| 65 | **   information about Qt Commercial License Agreements.
 | 
|---|
| 66 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
 | 
|---|
| 67 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
 | 
|---|
| 68 | **
 | 
|---|
| 69 | ** Contact info@trolltech.com if any conditions of this licensing are
 | 
|---|
| 70 | ** not clear to you.
 | 
|---|
| 71 | **
 | 
|---|
| 72 | **********************************************************************/
 | 
|---|
| 73 | 
 | 
|---|
| 74 | #ifndef QGUARDEDPTR_H
 | 
|---|
| 75 | #define QGUARDEDPTR_H
 | 
|---|
| 76 | 
 | 
|---|
| 77 | #ifndef QT_H
 | 
|---|
| 78 | #include "qobject.h"
 | 
|---|
| 79 | #endif // QT_H
 | 
|---|
| 80 | 
 | 
|---|
| 81 | // ### 4.0: rename to something without Private in it. Not really internal.
 | 
|---|
| 82 | class Q_EXPORT QGuardedPtrPrivate : public QObject, public QShared
 | 
|---|
| 83 | {
 | 
|---|
| 84 |     Q_OBJECT
 | 
|---|
| 85 | public:
 | 
|---|
| 86 |     QGuardedPtrPrivate( QObject* );
 | 
|---|
| 87 |     ~QGuardedPtrPrivate();
 | 
|---|
| 88 | 
 | 
|---|
| 89 |     QObject* object() const;
 | 
|---|
| 90 |     void reconnect( QObject* );
 | 
|---|
| 91 | 
 | 
|---|
| 92 | private slots:
 | 
|---|
| 93 |     void objectDestroyed();
 | 
|---|
| 94 | 
 | 
|---|
| 95 | private:
 | 
|---|
| 96 |     QObject* obj;
 | 
|---|
| 97 | #if defined(Q_DISABLE_COPY) // Disabled copy constructor and operator=
 | 
|---|
| 98 |     QGuardedPtrPrivate( const QGuardedPtrPrivate & );
 | 
|---|
| 99 |     QGuardedPtrPrivate &operator=( const QGuardedPtrPrivate & );
 | 
|---|
| 100 | #endif
 | 
|---|
| 101 | };
 | 
|---|
| 102 | 
 | 
|---|
| 103 | template <class T>
 | 
|---|
| 104 | class QGuardedPtr
 | 
|---|
| 105 | {
 | 
|---|
| 106 | public:
 | 
|---|
| 107 |     QGuardedPtr() : priv( new QGuardedPtrPrivate( 0 ) ) {}
 | 
|---|
| 108 | 
 | 
|---|
| 109 |     QGuardedPtr( T* o) {
 | 
|---|
| 110 |         priv = new QGuardedPtrPrivate( (QObject*)o );
 | 
|---|
| 111 |     }
 | 
|---|
| 112 | 
 | 
|---|
| 113 |     QGuardedPtr(const QGuardedPtr<T> &p) {
 | 
|---|
| 114 |         priv = p.priv;
 | 
|---|
| 115 |         ref();
 | 
|---|
| 116 |     }
 | 
|---|
| 117 | 
 | 
|---|
| 118 |     ~QGuardedPtr() { deref(); }
 | 
|---|
| 119 | 
 | 
|---|
| 120 |     QGuardedPtr<T> &operator=(const QGuardedPtr<T> &p) {
 | 
|---|
| 121 |         if ( priv != p.priv ) {
 | 
|---|
| 122 |             deref();
 | 
|---|
| 123 |             priv = p.priv;
 | 
|---|
| 124 |             ref();
 | 
|---|
| 125 |         }
 | 
|---|
| 126 |         return *this;
 | 
|---|
| 127 |     }
 | 
|---|
| 128 | 
 | 
|---|
| 129 |     QGuardedPtr<T> &operator=(T* o) {
 | 
|---|
| 130 |         if ( priv && priv->count == 1 ) {
 | 
|---|
| 131 |             priv->reconnect( (QObject*)o );
 | 
|---|
| 132 |         } else {
 | 
|---|
| 133 |             deref();
 | 
|---|
| 134 |             priv = new QGuardedPtrPrivate( (QObject*)o );
 | 
|---|
| 135 |         }
 | 
|---|
| 136 |         return *this;
 | 
|---|
| 137 |     }
 | 
|---|
| 138 | 
 | 
|---|
| 139 |     bool operator==( const QGuardedPtr<T> &p ) const {
 | 
|---|
| 140 |         return (T*)(*this) == (T*) p;
 | 
|---|
| 141 |     }
 | 
|---|
| 142 | 
 | 
|---|
| 143 |     bool operator!= ( const QGuardedPtr<T>& p ) const {
 | 
|---|
| 144 |         return !( *this == p );
 | 
|---|
| 145 |     }
 | 
|---|
| 146 | 
 | 
|---|
| 147 |     bool isNull() const { return !priv || !priv->object(); }
 | 
|---|
| 148 | 
 | 
|---|
| 149 |     T* operator->() const { return (T*)(priv?priv->object():0); }
 | 
|---|
| 150 | 
 | 
|---|
| 151 |     T& operator*() const { return *((T*)(priv?priv->object():0)); }
 | 
|---|
| 152 | 
 | 
|---|
| 153 |     operator T*() const { return (T*)(priv?priv->object():0); }
 | 
|---|
| 154 | 
 | 
|---|
| 155 | private:
 | 
|---|
| 156 | 
 | 
|---|
| 157 |     void ref() { if (priv) priv->ref(); }
 | 
|---|
| 158 | 
 | 
|---|
| 159 |     void deref() {
 | 
|---|
| 160 |         if ( priv && priv->deref() )
 | 
|---|
| 161 |             delete priv;
 | 
|---|
| 162 |     }
 | 
|---|
| 163 | 
 | 
|---|
| 164 |     QGuardedPtrPrivate* priv;
 | 
|---|
| 165 | };
 | 
|---|
| 166 | 
 | 
|---|
| 167 | 
 | 
|---|
| 168 | 
 | 
|---|
| 169 | 
 | 
|---|
| 170 | inline QObject* QGuardedPtrPrivate::object() const
 | 
|---|
| 171 | {
 | 
|---|
| 172 |     return obj;
 | 
|---|
| 173 | }
 | 
|---|
| 174 | 
 | 
|---|
| 175 | #define Q_DEFINED_QGUARDEDPTR
 | 
|---|
| 176 | #include "qwinexport.h"
 | 
|---|
| 177 | #endif
 | 
|---|
| 178 | </pre>
 | 
|---|
| 179 | <!-- eof -->
 | 
|---|
| 180 | <p><address><hr><div align=center>
 | 
|---|
| 181 | <table width=100% cellspacing=0 border=0><tr>
 | 
|---|
| 182 | <td>Copyright © 2007
 | 
|---|
| 183 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
 | 
|---|
| 184 | <td align=right><div align=right>Qt 3.3.8</div>
 | 
|---|
| 185 | </table></div></address></body>
 | 
|---|
| 186 | </html>
 | 
|---|