You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
195 lines
9.0 KiB
195 lines
9.0 KiB
13 years ago
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||
|
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/kernel/qguardedptr.cpp:40 -->
|
||
|
<html>
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||
|
<title>TQGuardedPtr Class</title>
|
||
|
<style type="text/css"><!--
|
||
|
fn { margin-left: 1cm; text-indent: -1cm; }
|
||
|
a:link { color: #004faf; text-decoration: none }
|
||
|
a:visited { color: #672967; text-decoration: none }
|
||
|
body { background: #ffffff; color: black; }
|
||
|
--></style>
|
||
|
</head>
|
||
|
<body>
|
||
|
|
||
|
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
||
|
<tr bgcolor="#E5E5E5">
|
||
|
<td valign=center>
|
||
|
<a href="index.html">
|
||
|
<font color="#004faf">Home</font></a>
|
||
|
| <a href="classes.html">
|
||
|
<font color="#004faf">All Classes</font></a>
|
||
|
| <a href="mainclasses.html">
|
||
|
<font color="#004faf">Main Classes</font></a>
|
||
|
| <a href="annotated.html">
|
||
|
<font color="#004faf">Annotated</font></a>
|
||
|
| <a href="groups.html">
|
||
|
<font color="#004faf">Grouped Classes</font></a>
|
||
|
| <a href="functions.html">
|
||
|
<font color="#004faf">Functions</font></a>
|
||
|
</td>
|
||
|
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>TQGuardedPtr Class Reference</h1>
|
||
|
|
||
|
<p>The TQGuardedPtr class is a template class that provides guarded pointers to TQObjects.
|
||
|
<a href="#details">More...</a>
|
||
13 years ago
|
<p><tt>#include <<a href="qguardedptr-h.html">ntqguardedptr.h</a>></tt>
|
||
13 years ago
|
<p><a href="qguardedptr-members.html">List of all member functions.</a>
|
||
|
<h2>Public Members</h2>
|
||
|
<ul>
|
||
|
<li class=fn><a href="#TQGuardedPtr"><b>TQGuardedPtr</b></a> ()</li>
|
||
|
<li class=fn><a href="#TQGuardedPtr-2"><b>TQGuardedPtr</b></a> ( T * p )</li>
|
||
|
<li class=fn><a href="#TQGuardedPtr-3"><b>TQGuardedPtr</b></a> ( const TQGuardedPtr<T> & p )</li>
|
||
|
<li class=fn><a href="#~TQGuardedPtr"><b>~TQGuardedPtr</b></a> ()</li>
|
||
|
<li class=fn>TQGuardedPtr<T> & <a href="#operator-eq"><b>operator=</b></a> ( const TQGuardedPtr<T> & p )</li>
|
||
|
<li class=fn>TQGuardedPtr<T> & <a href="#operator-eq-2"><b>operator=</b></a> ( T * p )</li>
|
||
|
<li class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const TQGuardedPtr<T> & p ) const</li>
|
||
|
<li class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const TQGuardedPtr<T> & p ) const</li>
|
||
|
<li class=fn>bool <a href="#isNull"><b>isNull</b></a> () const</li>
|
||
|
<li class=fn>T * <a href="#operator--gt"><b>operator-></b></a> () const</li>
|
||
|
<li class=fn>T & <a href="#operator*"><b>operator*</b></a> () const</li>
|
||
|
<li class=fn><a href="#operator-T-*"><b>operator T *</b></a> () const</li>
|
||
|
</ul>
|
||
|
<hr><a name="details"></a><h2>Detailed Description</h2>
|
||
|
|
||
|
|
||
|
The TQGuardedPtr class is a template class that provides guarded pointers to TQObjects.
|
||
|
<p>
|
||
|
|
||
|
<p> A guarded pointer, <tt>TQGuardedPtr<X></tt>, behaves like a normal C++
|
||
|
pointer <tt>X*</tt>, except that it is automatically set to 0 when
|
||
|
the referenced object is destroyed (unlike normal C++ pointers,
|
||
|
which become "dangling pointers" in such cases). <tt>X</tt> must be a
|
||
13 years ago
|
subclass of <a href="ntqobject.html">TQObject</a>.
|
||
13 years ago
|
<p> Guarded pointers are useful whenever you need to store a pointer
|
||
|
to a TQObject that is owned by someone else and therefore might be
|
||
|
destroyed while you still hold a reference to it. You can safely
|
||
|
test the pointer for validity.
|
||
|
<p> Example:
|
||
|
<pre>
|
||
13 years ago
|
TQGuardedPtr<TQLabel> label = new <a href="ntqlabel.html">TQLabel</a>( 0, "label" );
|
||
13 years ago
|
label->setText( "I like guarded pointers" );
|
||
|
|
||
|
delete (TQLabel*) label; // simulate somebody destroying the label
|
||
|
|
||
|
if ( label)
|
||
|
label->show();
|
||
|
else
|
||
13 years ago
|
<a href="ntqapplication.html#qDebug">qDebug</a>("The label has been destroyed");
|
||
13 years ago
|
</pre>
|
||
|
|
||
|
<p> The program will output <tt>The label has been destroyed</tt> rather
|
||
|
than dereferencing an invalid address in <tt>label->show()</tt>.
|
||
|
<p> The functions and operators available with a TQGuardedPtr are the
|
||
|
same as those available with a normal unguarded pointer, except
|
||
|
the pointer arithmetic operators (++, --, -, and +), which are
|
||
|
normally used only with arrays of objects. Use them like normal
|
||
|
pointers and you will not need to read this class documentation.
|
||
|
<p> For creating guarded pointers, you can construct or assign to them
|
||
|
from an X* or from another guarded pointer of the same type. You
|
||
|
can compare them with each other using <a href="#operator-eq-eq">operator==</a>() and
|
||
|
<a href="#operator!-eq">operator!=</a>(), or test for 0 with <a href="#isNull">isNull</a>(). And you can dereference
|
||
|
them using either the <tt>*x</tt> or the <tt>x->member</tt> notation.
|
||
|
<p> A guarded pointer will automatically cast to an X*, so you can
|
||
|
freely mix guarded and unguarded pointers. This means that if you
|
||
|
have a TQGuardedPtr<TQWidget>, you can pass it to a function that
|
||
13 years ago
|
requires a <a href="ntqwidget.html">TQWidget</a>*. For this reason, it is of little value to
|
||
13 years ago
|
declare functions to take a TQGuardedPtr as a parameter; just use
|
||
|
normal pointers. Use a TQGuardedPtr when you are storing a pointer
|
||
|
over time.
|
||
13 years ago
|
<p> Note again that class <em>X</em> must inherit <a href="ntqobject.html">TQObject</a>, or a compilation
|
||
13 years ago
|
or link error will result.
|
||
|
<p>See also <a href="objectmodel.html">Object Model</a>.
|
||
|
|
||
|
<hr><h2>Member Function Documentation</h2>
|
||
|
<h3 class=fn><a name="TQGuardedPtr"></a>TQGuardedPtr::TQGuardedPtr ()
|
||
|
</h3>
|
||
|
|
||
|
<p> Constructs a 0 guarded pointer.
|
||
|
<p> <p>See also <a href="#isNull">isNull</a>().
|
||
|
|
||
|
<h3 class=fn><a name="TQGuardedPtr-2"></a>TQGuardedPtr::TQGuardedPtr ( T * p )
|
||
|
</h3>
|
||
|
|
||
|
<p> Constructs a guarded pointer that points to same object as <em>p</em>
|
||
|
points to.
|
||
|
|
||
13 years ago
|
<h3 class=fn><a name="TQGuardedPtr-3"></a>TQGuardedPtr::TQGuardedPtr ( const <a href="ntqguardedptr.html">TQGuardedPtr</a><T> & p )
|
||
13 years ago
|
</h3>
|
||
|
|
||
|
<p> Copy one guarded pointer from another. The constructed guarded
|
||
|
pointer points to the same object that <em>p</em> points to (which may
|
||
|
be 0).
|
||
|
|
||
|
<h3 class=fn><a name="~TQGuardedPtr"></a>TQGuardedPtr::~TQGuardedPtr ()
|
||
|
</h3>
|
||
|
|
||
|
<p> Destroys the guarded pointer. Just like a normal pointer,
|
||
|
destroying a guarded pointer does <em>not</em> destroy the object being
|
||
|
pointed to.
|
||
|
|
||
|
<h3 class=fn>bool <a name="isNull"></a>TQGuardedPtr::isNull () const
|
||
|
</h3>
|
||
|
|
||
|
<p> Returns <tt>TRUE</tt> if the referenced object has been destroyed or if
|
||
|
there is no referenced object; otherwise returns FALSE.
|
||
|
|
||
|
<h3 class=fn><a name="operator-T-*"></a>TQGuardedPtr::operator T * () const
|
||
|
</h3>
|
||
|
|
||
|
<p> Cast operator; implements pointer semantics. Because of this
|
||
|
function you can pass a TQGuardedPtr<X> to a function where an X*
|
||
13 years ago
|
is required.
|
||
13 years ago
|
|
||
13 years ago
|
<h3 class=fn>bool <a name="operator!-eq"></a>TQGuardedPtr::operator!= ( const <a href="ntqguardedptr.html">TQGuardedPtr</a><T> & p ) const
|
||
13 years ago
|
</h3>
|
||
|
|
||
|
<p> Inequality operator; implements pointer semantics, the negation of
|
||
|
<a href="#operator-eq-eq">operator==</a>(). Returns TRUE if <em>p</em> and this guarded pointer are
|
||
|
not pointing to the same object; otherwise returns FALSE.
|
||
|
|
||
|
<h3 class=fn>T & <a name="operator*"></a>TQGuardedPtr::operator* () const
|
||
|
</h3>
|
||
|
|
||
|
<p> Dereference operator; implements pointer semantics. Just use this
|
||
|
operator as you would with a normal C++ pointer.
|
||
|
|
||
|
<h3 class=fn>T * <a name="operator--gt"></a>TQGuardedPtr::operator-> () const
|
||
|
</h3>
|
||
|
|
||
|
<p> Overloaded arrow operator; implements pointer semantics. Just use
|
||
|
this operator as you would with a normal C++ pointer.
|
||
|
|
||
13 years ago
|
<h3 class=fn><a href="ntqguardedptr.html">TQGuardedPtr</a><T> & <a name="operator-eq"></a>TQGuardedPtr::operator= ( const <a href="ntqguardedptr.html">TQGuardedPtr</a><T> & p )
|
||
13 years ago
|
</h3>
|
||
|
|
||
|
<p> Assignment operator. This guarded pointer then points to the same
|
||
|
object as <em>p</em> points to.
|
||
|
|
||
13 years ago
|
<h3 class=fn><a href="ntqguardedptr.html">TQGuardedPtr</a><T> & <a name="operator-eq-2"></a>TQGuardedPtr::operator= ( T * p )
|
||
13 years ago
|
</h3>
|
||
|
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
||
|
<p> Assignment operator. This guarded pointer then points to the same
|
||
|
object as <em>p</em> points to.
|
||
|
|
||
13 years ago
|
<h3 class=fn>bool <a name="operator-eq-eq"></a>TQGuardedPtr::operator== ( const <a href="ntqguardedptr.html">TQGuardedPtr</a><T> & p ) const
|
||
13 years ago
|
</h3>
|
||
|
|
||
|
<p> Equality operator; implements traditional pointer semantics.
|
||
|
Returns TRUE if both <em>p</em> and this guarded pointer are 0, or if
|
||
|
both <em>p</em> and this pointer point to the same object; otherwise
|
||
|
returns FALSE.
|
||
|
<p> <p>See also <a href="#operator!-eq">operator!=</a>().
|
||
|
|
||
|
<!-- eof -->
|
||
|
<hr><p>
|
||
|
This file is part of the <a href="index.html">TQt toolkit</a>.
|
||
|
Copyright © 1995-2007
|
||
|
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
|
||
|
<table width=100% cellspacing=0 border=0><tr>
|
||
|
<td>Copyright © 2007
|
||
|
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
||
|
<td align=right><div align=right>TQt 3.3.8</div>
|
||
|
</table></div></address></body>
|
||
|
</html>
|