summaryrefslogtreecommitdiffstats
path: root/doc/html/qptrcollection.html
blob: a828e4908eaaa6384722960c31582955ab8ff293 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!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/tools/qptrcollection.cpp:40 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QPtrCollection 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&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;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>QPtrCollection Class Reference</h1>

<p>The QPtrCollection class is the base class of most pointer-based Qt collections.
<a href="#details">More...</a>
<p>All the functions in this class are <a href="threads.html#reentrant">reentrant</a> when Qt is built with thread support.</p>
<p><tt>#include &lt;<a href="qptrcollection-h.html">qptrcollection.h</a>&gt;</tt>
<p>Inherited by <a href="qasciicache.html">QAsciiCache</a>, <a href="qasciidict.html">QAsciiDict</a>, <a href="qcache.html">QCache</a>, <a href="qdict.html">QDict</a>, <a href="qintcache.html">QIntCache</a>, <a href="qintdict.html">QIntDict</a>, <a href="qptrlist.html">QPtrList</a>, <a href="qptrdict.html">QPtrDict</a>, and <a href="qptrvector.html">QPtrVector</a>.
<p><a href="qptrcollection-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn>bool <a href="#autoDelete"><b>autoDelete</b></a> () const</li>
<li class=fn>void <a href="#setAutoDelete"><b>setAutoDelete</b></a> ( bool&nbsp;enable )</li>
<li class=fn>virtual uint <a href="#count"><b>count</b></a> () const = 0</li>
<li class=fn>virtual void <a href="#clear"><b>clear</b></a> () = 0</li>
<li class=fn>typedef void&nbsp;*&nbsp;<a href="#Item"><b>Item</b></a></li>
</ul>
<h2>Protected Members</h2>
<ul>
<li class=fn><a href="#QPtrCollection"><b>QPtrCollection</b></a> ()</li>
<li class=fn><a href="#QPtrCollection-2"><b>QPtrCollection</b></a> ( const&nbsp;QPtrCollection&nbsp;&amp;&nbsp;source )</li>
<li class=fn>virtual <a href="#~QPtrCollection"><b>~QPtrCollection</b></a> ()</li>
<li class=fn>virtual Item <a href="#newItem"><b>newItem</b></a> ( Item&nbsp;d )</li>
<li class=fn>virtual void <a href="#deleteItem"><b>deleteItem</b></a> ( Item&nbsp;d ) = 0</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>



The QPtrCollection class is the base class of most pointer-based Qt collections.
<p> 

<p> The QPtrCollection class is an abstract base class for the Qt
<a href="collection.html">collection classes</a> <a href="qdict.html">QDict</a>, <a href="qptrlist.html">QPtrList</a>,
etc. Qt also includes value based collections, e.g. <a href="qvaluelist.html">QValueList</a>,
<a href="qmap.html">QMap</a>, etc.
<p> A QPtrCollection only knows about the number of objects in the
collection and the deletion strategy (see <a href="#setAutoDelete">setAutoDelete</a>()).
<p> A collection is implemented using the <a href="#Item">Item</a> (generic collection
item) type, which is a <tt>void*</tt>. The template classes that create
the real collections cast the <a href="#Item">Item</a> to the required type.
<p>See also <a href="collection.html">Collection Classes</a> and <a href="tools.html">Non-GUI Classes</a>.

<hr><h2>Member Type Documentation</h2>
<h3 class=fn><a name="Item"></a>QPtrCollection::Item</h3>

<p> This type is the generic "item" in a QPtrCollection.

<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="QPtrCollection"></a>QPtrCollection::QPtrCollection ()<tt> [protected]</tt>
</h3>

<p> Constructs a collection. The constructor is protected because
QPtrCollection is an abstract class.

<h3 class=fn><a name="QPtrCollection-2"></a>QPtrCollection::QPtrCollection ( const&nbsp;<a href="qptrcollection.html">QPtrCollection</a>&nbsp;&amp;&nbsp;source )<tt> [protected]</tt>
</h3>

<p> Constructs a copy of <em>source</em> with <a href="#autoDelete">autoDelete</a>() set to FALSE. The
constructor is protected because QPtrCollection is an abstract
class.
<p> Note that if <em>source</em> has autoDelete turned on, copying it will
risk memory leaks, reading freed memory, or both.

<h3 class=fn><a name="~QPtrCollection"></a>QPtrCollection::~QPtrCollection ()<tt> [virtual protected]</tt>
</h3>

<p> Destroys the collection. The destructor is protected because
QPtrCollection is an abstract class.

<h3 class=fn>bool <a name="autoDelete"></a>QPtrCollection::autoDelete () const
</h3>

<p> Returns the setting of the auto-delete option. The default is FALSE.
<p> <p>See also <a href="#setAutoDelete">setAutoDelete</a>().

<h3 class=fn>void <a name="clear"></a>QPtrCollection::clear ()<tt> [pure virtual]</tt>
</h3>

<p> Removes all objects from the collection. The objects will be
deleted if auto-delete has been enabled.
<p> <p>See also <a href="#setAutoDelete">setAutoDelete</a>().

<p>Reimplemented in <a href="qasciicache.html#clear">QAsciiCache</a>, <a href="qasciidict.html#clear">QAsciiDict</a>, <a href="qcache.html#clear">QCache</a>, <a href="qdict.html#clear">QDict</a>, <a href="qintcache.html#clear">QIntCache</a>, <a href="qintdict.html#clear">QIntDict</a>, <a href="qptrlist.html#clear">QPtrList</a>, <a href="qptrdict.html#clear">QPtrDict</a>, and <a href="qptrvector.html#clear">QPtrVector</a>.
<h3 class=fn>uint <a name="count"></a>QPtrCollection::count () const<tt> [pure virtual]</tt>
</h3>

<p> Returns the number of objects in the collection.

<p>Reimplemented in <a href="qasciicache.html#count">QAsciiCache</a>, <a href="qasciidict.html#count">QAsciiDict</a>, <a href="qcache.html#count">QCache</a>, <a href="qdict.html#count">QDict</a>, <a href="qintcache.html#count">QIntCache</a>, <a href="qintdict.html#count">QIntDict</a>, <a href="qptrlist.html#count">QPtrList</a>, <a href="qptrdict.html#count">QPtrDict</a>, and <a href="qptrvector.html#count">QPtrVector</a>.
<h3 class=fn>void <a name="deleteItem"></a>QPtrCollection::deleteItem ( <a href="qptrcollection.html#Item">Item</a>&nbsp;d )<tt> [pure virtual protected]</tt>
</h3>

<p> Reimplement this function if you want to be able to delete items.
<p> Deletes an item that is about to be removed from the collection.
<p> This function has to reimplemented in the collection template
classes, and should <em>only</em> delete item <em>d</em> if auto-delete has
been enabled.
<p> <b>Warning:</b> If you reimplement this function you must also
reimplement the destructor and call the virtual function <a href="#clear">clear</a>()
from your destructor. This is due to the way virtual functions and
destructors work in C++: Virtual functions in derived classes
cannot be called from a destructor. If you do not do this, your
<a href="#deleteItem">deleteItem</a>() function will not be called when the container is
destroyed.
<p> <p>See also <a href="#newItem">newItem</a>() and <a href="#setAutoDelete">setAutoDelete</a>().

<h3 class=fn><a href="qptrcollection.html#Item">Item</a> <a name="newItem"></a>QPtrCollection::newItem ( <a href="qptrcollection.html#Item">Item</a>&nbsp;d )<tt> [virtual protected]</tt>
</h3>
Virtual function that creates a copy of an object that is about to
be inserted into the collection.
<p> The default implementation returns the <em>d</em> pointer, i.e. no copy
is made.
<p> This function is seldom reimplemented in the collection template
classes. It is not common practice to make a copy of something
that is being inserted.
<p> <p>See also <a href="#deleteItem">deleteItem</a>().

<h3 class=fn>void <a name="setAutoDelete"></a>QPtrCollection::setAutoDelete ( bool&nbsp;enable )
</h3>

<p> Sets the collection to auto-delete its contents if <em>enable</em> is
TRUE and to never delete them if <em>enable</em> is FALSE.
<p> If auto-deleting is turned on, all the items in a collection are
deleted when the collection itself is deleted. This is convenient
if the collection has the only pointer to the items.
<p> The default setting is FALSE, for safety. If you turn it on, be
careful about copying the collection - you might find yourself
with two collections deleting the same items.
<p> Note that the auto-delete setting may also affect other functions
in subclasses. For example, a subclass that has a remove()
function will remove the item from its data structure, and if
auto-delete is enabled, will also delete the item.
<p> <p>See also <a href="#autoDelete">autoDelete</a>().

<p>Examples: <a href="grapher-nsplugin-example.html#x2769">grapher/grapher.cpp</a>, <a href="scribble-example.html#x924">scribble/scribble.cpp</a>, and <a href="bigtable-example.html#x1291">table/bigtable/main.cpp</a>.
<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>.
Copyright &copy; 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 &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt 3.3.8</div>
</table></div></address></body>
</html>