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/doc/qmap.doc:41 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>QMap Class</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>QMap Class Reference</h1>
|
---|
33 |
|
---|
34 | <p>The QMap class is a value-based template class that
|
---|
35 | provides a dictionary.
|
---|
36 | <a href="#details">More...</a>
|
---|
37 | <p><tt>#include <<a href="qmap-h.html">qmap.h</a>></tt>
|
---|
38 | <p><a href="qmap-members.html">List of all member functions.</a>
|
---|
39 | <h2>Public Members</h2>
|
---|
40 | <ul>
|
---|
41 | <li class=fn>typedef Key <a href="#key_type"><b>key_type</b></a></li>
|
---|
42 | <li class=fn>typedef T <a href="#mapped_type"><b>mapped_type</b></a></li>
|
---|
43 | <li class=fn>typedef QPair<const key_type, mapped_type> <a href="#value_type"><b>value_type</b></a></li>
|
---|
44 | <li class=fn>typedef value_type * <a href="#pointer"><b>pointer</b></a></li>
|
---|
45 | <li class=fn>typedef const value_type * <a href="#const_pointer"><b>const_pointer</b></a></li>
|
---|
46 | <li class=fn>typedef value_type & <a href="#reference"><b>reference</b></a></li>
|
---|
47 | <li class=fn>typedef const value_type & <a href="#const_reference"><b>const_reference</b></a></li>
|
---|
48 | <li class=fn>typedef size_t <a href="#size_type"><b>size_type</b></a></li>
|
---|
49 | <li class=fn>typedef QMapIterator<Key, T> <a href="#iterator"><b>iterator</b></a></li>
|
---|
50 | <li class=fn>typedef QMapConstIterator<Key, T> <a href="#const_iterator"><b>const_iterator</b></a></li>
|
---|
51 | <li class=fn>typedef QPair<iterator, bool> <b>insert_pair</b></li>
|
---|
52 | <li class=fn>typedef QMapIterator<Key, T> <a href="#Iterator"><b>Iterator</b></a></li>
|
---|
53 | <li class=fn>typedef QMapConstIterator<Key, T> <a href="#ConstIterator"><b>ConstIterator</b></a></li>
|
---|
54 | <li class=fn>typedef T <a href="#ValueType"><b>ValueType</b></a></li>
|
---|
55 | <li class=fn><a href="#QMap"><b>QMap</b></a> ()</li>
|
---|
56 | <li class=fn><a href="#QMap-2"><b>QMap</b></a> ( const QMap<Key, T> & m )</li>
|
---|
57 | <li class=fn><a href="#QMap-3"><b>QMap</b></a> ( const std::map<Key, T> & m )</li>
|
---|
58 | <li class=fn><a href="#~QMap"><b>~QMap</b></a> ()</li>
|
---|
59 | <li class=fn>QMap<Key, T> & <a href="#operator-eq"><b>operator=</b></a> ( const QMap<Key, T> & m )</li>
|
---|
60 | <li class=fn>QMap<Key, T> & <a href="#operator-eq-2"><b>operator=</b></a> ( const std::map<Key, T> & m )</li>
|
---|
61 | <li class=fn>iterator <a href="#begin"><b>begin</b></a> ()</li>
|
---|
62 | <li class=fn>iterator <a href="#end"><b>end</b></a> ()</li>
|
---|
63 | <li class=fn>const_iterator <a href="#begin-2"><b>begin</b></a> () const</li>
|
---|
64 | <li class=fn>const_iterator <a href="#end-2"><b>end</b></a> () const</li>
|
---|
65 | <li class=fn>const_iterator <a href="#constBegin"><b>constBegin</b></a> () const</li>
|
---|
66 | <li class=fn>const_iterator <a href="#constEnd"><b>constEnd</b></a> () const</li>
|
---|
67 | <li class=fn>iterator <a href="#replace"><b>replace</b></a> ( const Key & k, const T & v )</li>
|
---|
68 | <li class=fn>size_type <a href="#size"><b>size</b></a> () const</li>
|
---|
69 | <li class=fn>bool <a href="#empty"><b>empty</b></a> () const</li>
|
---|
70 | <li class=fn>QPair<iterator, bool> <a href="#insert-2"><b>insert</b></a> ( const value_type & x )</li>
|
---|
71 | <li class=fn>void <a href="#erase"><b>erase</b></a> ( iterator it )</li>
|
---|
72 | <li class=fn>void <a href="#erase-2"><b>erase</b></a> ( const key_type & k )</li>
|
---|
73 | <li class=fn>size_type <a href="#count"><b>count</b></a> ( const key_type & k ) const</li>
|
---|
74 | <li class=fn>T & <a href="#operator[]"><b>operator[]</b></a> ( const Key & k )</li>
|
---|
75 | <li class=fn>void <a href="#clear"><b>clear</b></a> ()</li>
|
---|
76 | <li class=fn>iterator <a href="#find"><b>find</b></a> ( const Key & k )</li>
|
---|
77 | <li class=fn>const_iterator <a href="#find-2"><b>find</b></a> ( const Key & k ) const</li>
|
---|
78 | <li class=fn>const T & <a href="#operator[]-2"><b>operator[]</b></a> ( const Key & k ) const</li>
|
---|
79 | <li class=fn>bool <a href="#contains"><b>contains</b></a> ( const Key & k ) const</li>
|
---|
80 | <li class=fn>size_type <a href="#count-2"><b>count</b></a> () const</li>
|
---|
81 | <li class=fn>QValueList<Key> <a href="#keys"><b>keys</b></a> () const</li>
|
---|
82 | <li class=fn>QValueList<T> <a href="#values"><b>values</b></a> () const</li>
|
---|
83 | <li class=fn>bool <a href="#isEmpty"><b>isEmpty</b></a> () const</li>
|
---|
84 | <li class=fn>iterator <a href="#insert"><b>insert</b></a> ( const Key & key, const T & value, bool overwrite = TRUE )</li>
|
---|
85 | <li class=fn>void <a href="#remove"><b>remove</b></a> ( iterator it )</li>
|
---|
86 | <li class=fn>void <a href="#remove-2"><b>remove</b></a> ( const Key & k )</li>
|
---|
87 | </ul>
|
---|
88 | <h2>Protected Members</h2>
|
---|
89 | <ul>
|
---|
90 | <li class=fn>void <a href="#detach"><b>detach</b></a> ()</li>
|
---|
91 | </ul>
|
---|
92 | <h2>Related Functions</h2>
|
---|
93 | <ul>
|
---|
94 | <li class=fn>QDataStream & <a href="#operator-gt-gt"><b>operator>></b></a> ( QDataStream & s, QMap<Key, T> & m )</li>
|
---|
95 | <li class=fn>QDataStream & <a href="#operator-lt-lt"><b>operator<<</b></a> ( QDataStream & s, const QMap<Key, T> & m )</li>
|
---|
96 | </ul>
|
---|
97 | <hr><a name="details"></a><h2>Detailed Description</h2>
|
---|
98 |
|
---|
99 |
|
---|
100 | The QMap class is a value-based template class that
|
---|
101 | provides a dictionary.
|
---|
102 | <p>
|
---|
103 |
|
---|
104 |
|
---|
105 |
|
---|
106 | <p> QMap is a Qt implementation of an STL-like map container. It can
|
---|
107 | be used in your application if the standard <tt>map</tt> is not
|
---|
108 | available on all your target platforms. QMap is part of the <a href="qtl.html">Qt Template Library</a>.
|
---|
109 | <p> QMap<Key, Data> defines a template instance to create a
|
---|
110 | dictionary with keys of type Key and values of type Data. QMap
|
---|
111 | does not store pointers to the members of the map; instead, it
|
---|
112 | holds a copy of every member. For this reason, QMap is
|
---|
113 | value-based, whereas <a href="qptrlist.html">QPtrList</a> and <a href="qdict.html">QDict</a> are pointer-based.
|
---|
114 | <p> QMap contains and manages a collection of objects of type Data
|
---|
115 | with associated key values of type Key and provides iterators that
|
---|
116 | allow the contained objects to be addressed. QMap owns the
|
---|
117 | contained items.
|
---|
118 | <p> Some classes cannot be used within a QMap. For example everything
|
---|
119 | derived from <a href="qobject.html">QObject</a> and thus all classes that implement widgets.
|
---|
120 | Only values can be used in a QMap. To qualify as a value, the
|
---|
121 | class must provide
|
---|
122 | <p> <ul>
|
---|
123 | <li> A copy constructor
|
---|
124 | <li> An assignment operator
|
---|
125 | <li> A default constructor, i.e. a constructor that does not take
|
---|
126 | any arguments.
|
---|
127 | </ul>
|
---|
128 | <p> Note that C++ defaults to field-by-field assignment operators and
|
---|
129 | copy constructors if no explicit version is supplied. In many
|
---|
130 | cases, this is sufficient.
|
---|
131 | <p> The class used for the key requires that the <tt>operator<</tt> is
|
---|
132 | implemented to define ordering of the keys.
|
---|
133 | <p> QMap's function naming is consistent with the other Qt classes
|
---|
134 | (e.g., <a href="#count">count</a>(), <a href="#isEmpty">isEmpty</a>()). QMap also provides extra functions for
|
---|
135 | compatibility with STL algorithms, such as <a href="#size">size</a>() and <a href="#empty">empty</a>().
|
---|
136 | Programmers already familiar with the STL <tt>map</tt> can use these
|
---|
137 | the STL-like functions if preferred.
|
---|
138 | <p> Example:
|
---|
139 | <a name="qmap-eg"></a>
|
---|
140 | <pre>
|
---|
141 | #include <<a href="qstring-h.html">qstring.h</a>>
|
---|
142 | #include <<a href="qmap-h.html">qmap.h</a>>
|
---|
143 | #include <<a href="qstring-h.html">qstring.h</a>>
|
---|
144 |
|
---|
145 | class Employee
|
---|
146 | {
|
---|
147 | public:
|
---|
148 | Employee(): sn(0) {}
|
---|
149 | Employee( const <a href="qstring.html">QString</a>& forename, const <a href="qstring.html">QString</a>& surname, int salary )
|
---|
150 | : fn(forename), sn(surname), sal(salary)
|
---|
151 | { }
|
---|
152 |
|
---|
153 | <a href="qstring.html">QString</a> forename() const { return fn; }
|
---|
154 | <a href="qstring.html">QString</a> surname() const { return sn; }
|
---|
155 | int salary() const { return sal; }
|
---|
156 | void setSalary( int salary ) { sal = salary; }
|
---|
157 |
|
---|
158 | private:
|
---|
159 | <a href="qstring.html">QString</a> fn;
|
---|
160 | <a href="qstring.html">QString</a> sn;
|
---|
161 | int sal;
|
---|
162 | };
|
---|
163 |
|
---|
164 | int main(int argc, char **argv)
|
---|
165 | {
|
---|
166 | <a href="qapplication.html">QApplication</a> app( argc, argv );
|
---|
167 |
|
---|
168 | typedef QMap<QString, Employee> EmployeeMap;
|
---|
169 | EmployeeMap map;
|
---|
170 |
|
---|
171 | map["JD001"] = Employee("John", "Doe", 50000);
|
---|
172 | map["JW002"] = Employee("Jane", "Williams", 80000);
|
---|
173 | map["TJ001"] = Employee("Tom", "Jones", 60000);
|
---|
174 |
|
---|
175 | Employee sasha( "Sasha", "Hind", 50000 );
|
---|
176 | map["SH001"] = sasha;
|
---|
177 | sasha.setSalary( 40000 );
|
---|
178 |
|
---|
179 | EmployeeMap::<a href="#Iterator">Iterator</a> it;
|
---|
180 | for ( it = map.begin(); it != map.end(); ++it ) {
|
---|
181 | printf( "%s: %s, %s earns %d\n",
|
---|
182 | it.key().latin1(),
|
---|
183 | it.data().surname().latin1(),
|
---|
184 | it.data().forename().latin1(),
|
---|
185 | it.data().salary() );
|
---|
186 | }
|
---|
187 | return 0;
|
---|
188 | }
|
---|
189 | </pre>
|
---|
190 |
|
---|
191 | <p> Program output:
|
---|
192 | <pre>
|
---|
193 | JD001: Doe, John earns 50000
|
---|
194 | JW002: Williams, Jane earns 80000
|
---|
195 | SH001: Hind, Sasha earns 50000
|
---|
196 | TJ001: Jones, Tom earns 60000
|
---|
197 | </pre>
|
---|
198 |
|
---|
199 | <p> The latest changes to Sasha's salary did not affect the value in
|
---|
200 | the list because the map created a copy of Sasha's entry. In
|
---|
201 | addition, notice that the items are sorted alphabetically (by key)
|
---|
202 | when iterating over the map.
|
---|
203 | <p> There are several ways to find items in a map. The <a href="#begin">begin</a>() and
|
---|
204 | <a href="#end">end</a>() functions return iterators to the beginning and end of the
|
---|
205 | map. The advantage of using an iterator is that you can move
|
---|
206 | forward or backward by incrementing/decrementing the iterator.
|
---|
207 | The iterator returned by end() points to the element which is one
|
---|
208 | past the last element in the container. The past-the-end iterator
|
---|
209 | is still associated with the map it belongs to, however it is <em>not</em> dereferenceable; <a href="qsize.html#operator*-4">operator*</a>() will not return a well-defined
|
---|
210 | value. If the map is empty, the iterator returned by begin() will
|
---|
211 | equal the iterator returned by end().
|
---|
212 | <p> Another way to find an element in the map is by using the <a href="#find">find</a>()
|
---|
213 | function. This returns an iterator pointing to the desired item or
|
---|
214 | to the end() iterator if no such element exists.
|
---|
215 | <p> Another approach uses the operator[]. But be warned: if the map
|
---|
216 | does not contain an entry for the element you are looking for,
|
---|
217 | operator[] inserts a default value. If you do not know that the
|
---|
218 | element you are searching for is really in the list, you should
|
---|
219 | not use operator[]. The following example illustrates this:
|
---|
220 | <p> <pre>
|
---|
221 | QMap<QString,QString> map;
|
---|
222 | map["Clinton"] = "Bill";
|
---|
223 | str << map["Clinton"] << map["Bush"] << endl;
|
---|
224 | </pre>
|
---|
225 |
|
---|
226 | <p> The code fragment will print out "Clinton", "". Since the value
|
---|
227 | associated with the "Bush" key did not exist, the map inserted a
|
---|
228 | default value (in this case, an empty string). If you are not
|
---|
229 | sure whether a certain element is in the map, you should use
|
---|
230 | find() and iterators instead.
|
---|
231 | <p> If you just want to know whether a certain key is contained in the
|
---|
232 | map, use the <a href="#contains">contains</a>() function. In addition, <a href="#count">count</a>() tells you
|
---|
233 | how many keys are in the map.
|
---|
234 | <p> It is safe to have multiple iterators at the same time. If some
|
---|
235 | member of the map is removed, only iterators pointing to the
|
---|
236 | removed member become invalid; inserting in the map does not
|
---|
237 | invalidate any iterators.
|
---|
238 | <p> Since QMap is value-based, there is no need to be concerned about
|
---|
239 | deleting items in the map. The map holds its own copies and will
|
---|
240 | free them if the corresponding member or the map itself is
|
---|
241 | deleted.
|
---|
242 | <p> QMap is <a href="shclass.html#implicitly-shared">implicitly shared</a>. This means you can just make copies of
|
---|
243 | the map in time O(1). If multiple QMap instances share the same
|
---|
244 | data and one is modifying the map's data, this modifying instance
|
---|
245 | makes a copy and modifies its private copy: so it does not affect
|
---|
246 | other instances. If a QMap is being used in a multi-threaded
|
---|
247 | program, you must protect all access to the map. See <a href="qmutex.html">QMutex</a>.
|
---|
248 | <p> There are a couple of ways of inserting new items into the map.
|
---|
249 | One uses the <a href="#insert">insert</a>() method; the other uses operator[]:
|
---|
250 | <pre>
|
---|
251 | QMap<QString, QString> map;
|
---|
252 | map["Clinton"] = "Bill";
|
---|
253 | map.<a href="#insert">insert</a>( "Bush", "George" );
|
---|
254 | </pre>
|
---|
255 |
|
---|
256 | <p> Items can also be removed from the map in several ways. One way is
|
---|
257 | to pass an iterator to <a href="#remove">remove</a>(). Another way is to pass a key
|
---|
258 | value to remove(), which will delete the entry with the requested
|
---|
259 | key. In addition you can clear the entire map using the <a href="#clear">clear</a>()
|
---|
260 | method.
|
---|
261 | <p> <p>See also <a href="qmapiterator.html">QMapIterator</a>, <a href="qtl.html">Qt Template Library Classes</a>, <a href="shared.html">Implicitly and Explicitly Shared Classes</a>, and <a href="tools.html">Non-GUI Classes</a>.
|
---|
262 |
|
---|
263 | <hr><h2>Member Type Documentation</h2>
|
---|
264 | <h3 class=fn><a name="ConstIterator"></a>QMap::ConstIterator</h3>
|
---|
265 | The map's const iterator type, Qt style.
|
---|
266 | <h3 class=fn><a name="Iterator"></a>QMap::Iterator</h3>
|
---|
267 | The map's iterator type, Qt style.
|
---|
268 | <h3 class=fn><a name="ValueType"></a>QMap::ValueType</h3>
|
---|
269 | Corresponds to <a href="qpair.html">QPair</a><key_type, mapped_type>, Qt style.
|
---|
270 | <h3 class=fn><a name="const_iterator"></a>QMap::const_iterator</h3>
|
---|
271 | The map's const iterator type.
|
---|
272 | <h3 class=fn><a name="const_pointer"></a>QMap::const_pointer</h3>
|
---|
273 | Const pointer to value_type.
|
---|
274 | <h3 class=fn><a name="const_reference"></a>QMap::const_reference</h3>
|
---|
275 | Const reference to value_type.
|
---|
276 | <h3 class=fn><a name="iterator"></a>QMap::iterator</h3>
|
---|
277 | The map's iterator type.
|
---|
278 | <h3 class=fn><a name="key_type"></a>QMap::key_type</h3>
|
---|
279 | The map's key type.
|
---|
280 | <h3 class=fn><a name="mapped_type"></a>QMap::mapped_type</h3>
|
---|
281 | The map's data type.
|
---|
282 | <h3 class=fn><a name="pointer"></a>QMap::pointer</h3>
|
---|
283 | Pointer to value_type.
|
---|
284 | <h3 class=fn><a name="reference"></a>QMap::reference</h3>
|
---|
285 | Reference to value_type.
|
---|
286 | <h3 class=fn><a name="size_type"></a>QMap::size_type</h3>
|
---|
287 | An unsigned integral type, used to represent various sizes.
|
---|
288 | <h3 class=fn><a name="value_type"></a>QMap::value_type</h3>
|
---|
289 | Corresponds to <a href="qpair.html">QPair</a><key_type, mapped_type>.
|
---|
290 | <hr><h2>Member Function Documentation</h2>
|
---|
291 | <h3 class=fn><a name="QMap"></a>QMap::QMap ()
|
---|
292 | </h3>
|
---|
293 |
|
---|
294 | <p> Constructs an empty map.
|
---|
295 |
|
---|
296 | <h3 class=fn><a name="QMap-2"></a>QMap::QMap ( const <a href="qmap.html">QMap</a><Key, T> & m )
|
---|
297 | </h3>
|
---|
298 |
|
---|
299 | <p> Constructs a copy of <em>m</em>.
|
---|
300 | <p> This operation costs O(1) time because QMap is <a href="shclass.html#implicitly-shared">implicitly shared</a>.
|
---|
301 | This makes returning a QMap from a function very fast. If a shared
|
---|
302 | instance is modified, it will be copied (copy-on-write), and this
|
---|
303 | takes O(n) time.
|
---|
304 |
|
---|
305 | <h3 class=fn><a name="QMap-3"></a>QMap::QMap ( const std::map<Key, T> & m )
|
---|
306 | </h3>
|
---|
307 |
|
---|
308 | <p> Constructs a copy of <em>m</em>.
|
---|
309 |
|
---|
310 | <h3 class=fn><a name="~QMap"></a>QMap::~QMap ()
|
---|
311 | </h3>
|
---|
312 |
|
---|
313 | <p> Destroys the map. References to the values in the map and all
|
---|
314 | iterators of this map become invalidated. Since QMap is highly
|
---|
315 | tuned for performance you won't see warnings if you use invalid
|
---|
316 | iterators, because it is not possible for an iterator to check
|
---|
317 | whether it is valid or not.
|
---|
318 |
|
---|
319 | <h3 class=fn><a href="qmap.html#iterator">iterator</a> <a name="begin"></a>QMap::begin ()
|
---|
320 | </h3>
|
---|
321 |
|
---|
322 | <p> Returns an iterator pointing to the first element in the map. This
|
---|
323 | iterator equals <a href="#end">end</a>() if the map is empty.
|
---|
324 | <p> The items in the map are traversed in the order defined by
|
---|
325 | operator<(Key, Key).
|
---|
326 | <p> <p>See also <a href="#end">end</a>() and <a href="qmapiterator.html">QMapIterator</a>.
|
---|
327 |
|
---|
328 | <h3 class=fn><a href="qmap.html#const_iterator">const_iterator</a> <a name="begin-2"></a>QMap::begin () const
|
---|
329 | </h3>
|
---|
330 |
|
---|
331 | <p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
332 | <p> <p>See also <a href="#end">end</a>() and <a href="qmapconstiterator.html">QMapConstIterator</a>.
|
---|
333 |
|
---|
334 | <h3 class=fn>void <a name="clear"></a>QMap::clear ()
|
---|
335 | </h3>
|
---|
336 |
|
---|
337 | <p> Removes all items from the map.
|
---|
338 | <p> <p>See also <a href="#remove">remove</a>().
|
---|
339 |
|
---|
340 | <h3 class=fn><a href="qmap.html#const_iterator">const_iterator</a> <a name="constBegin"></a>QMap::constBegin () const
|
---|
341 | </h3>
|
---|
342 |
|
---|
343 | <p> Returns an iterator pointing to the first element in the map. This
|
---|
344 | iterator equals <a href="#end">end</a>() if the map is empty.
|
---|
345 | <p> The items in the map are traversed in the order defined by
|
---|
346 | operator<(Key, Key).
|
---|
347 | <p> <p>See also <a href="#constEnd">constEnd</a>() and <a href="qmapconstiterator.html">QMapConstIterator</a>.
|
---|
348 |
|
---|
349 | <h3 class=fn><a href="qmap.html#const_iterator">const_iterator</a> <a name="constEnd"></a>QMap::constEnd () const
|
---|
350 | </h3>
|
---|
351 |
|
---|
352 | <p> The iterator returned by <a href="#end">end</a>() points to the element which is one
|
---|
353 | past the last element in the container. The past-the-end iterator
|
---|
354 | is still associated with the map it belongs to, but it is <em>not</em>
|
---|
355 | dereferenceable; <a href="qsize.html#operator*-4">operator*</a>() will not return a well-defined value.
|
---|
356 | <p> This iterator equals <a href="#constBegin">constBegin</a>() if the map is empty.
|
---|
357 | <p> <p>See also <a href="#constBegin">constBegin</a>() and <a href="qmapconstiterator.html">QMapConstIterator</a>.
|
---|
358 |
|
---|
359 | <h3 class=fn>bool <a name="contains"></a>QMap::contains ( const Key & k ) const
|
---|
360 | </h3>
|
---|
361 |
|
---|
362 | <p> Returns TRUE if the map contains an item with key <em>k</em>; otherwise
|
---|
363 | returns FALSE.
|
---|
364 |
|
---|
365 | <h3 class=fn><a href="qmap.html#size_type">size_type</a> <a name="count"></a>QMap::count ( const <a href="qmap.html#key_type">key_type</a> & k ) const
|
---|
366 | </h3>
|
---|
367 |
|
---|
368 | <p> Returns the number of items whose key is <em>k</em>. Since QMap does not
|
---|
369 | allow duplicate keys, the return value is always 0 or 1.
|
---|
370 | <p> This function is provided for STL compatibility.
|
---|
371 |
|
---|
372 | <h3 class=fn><a href="qmap.html#size_type">size_type</a> <a name="count-2"></a>QMap::count () const
|
---|
373 | </h3>
|
---|
374 |
|
---|
375 | <p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
376 | <p> Returns the number of items in the map.
|
---|
377 | <p> <p>See also <a href="#isEmpty">isEmpty</a>().
|
---|
378 |
|
---|
379 | <h3 class=fn>void <a name="detach"></a>QMap::detach ()<tt> [protected]</tt>
|
---|
380 | </h3>
|
---|
381 |
|
---|
382 | <p> If the map does not share its data with another QMap instance,
|
---|
383 | nothing happens; otherwise the function creates a new copy of this
|
---|
384 | map and detaches from the shared one. This function is called
|
---|
385 | whenever the map is modified. The <a href="shclass.html#implicit-sharing">implicit sharing</a> mechanism is
|
---|
386 | implemented this way.
|
---|
387 |
|
---|
388 | <h3 class=fn>bool <a name="empty"></a>QMap::empty () const
|
---|
389 | </h3>
|
---|
390 |
|
---|
391 | <p> Returns TRUE if the map contains no items; otherwise returns
|
---|
392 | FALSE.
|
---|
393 | <p> This function is provided for STL compatibility. It is equivalent
|
---|
394 | to <a href="#isEmpty">isEmpty</a>().
|
---|
395 | <p> <p>See also <a href="#size">size</a>().
|
---|
396 |
|
---|
397 | <h3 class=fn><a href="qmap.html#iterator">iterator</a> <a name="end"></a>QMap::end ()
|
---|
398 | </h3>
|
---|
399 |
|
---|
400 | <p> The iterator returned by <a href="#end">end</a>() points to the element which is one
|
---|
401 | past the last element in the container. The past-the-end iterator
|
---|
402 | is still associated with the map it belongs to, but it is <em>not</em>
|
---|
403 | dereferenceable; <a href="qsize.html#operator*-4">operator*</a>() will not return a well-defined value.
|
---|
404 | <p> This iterator equals <a href="#begin">begin</a>() if the map is empty.
|
---|
405 | <p> <p>See also <a href="#begin">begin</a>() and <a href="qmapiterator.html">QMapIterator</a>.
|
---|
406 |
|
---|
407 | <h3 class=fn><a href="qmap.html#const_iterator">const_iterator</a> <a name="end-2"></a>QMap::end () const
|
---|
408 | </h3>
|
---|
409 |
|
---|
410 | <p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
411 | <p>
|
---|
412 | <h3 class=fn>void <a name="erase"></a>QMap::erase ( <a href="qmap.html#iterator">iterator</a> it )
|
---|
413 | </h3>
|
---|
414 |
|
---|
415 | <p> Removes the item associated with the iterator <em>it</em> from the map.
|
---|
416 | <p> This function is provided for STL compatibility. It is equivalent
|
---|
417 | to <a href="#remove">remove</a>().
|
---|
418 | <p> <p>See also <a href="#clear">clear</a>().
|
---|
419 |
|
---|
420 | <h3 class=fn>void <a name="erase-2"></a>QMap::erase ( const <a href="qmap.html#key_type">key_type</a> & k )
|
---|
421 | </h3>
|
---|
422 |
|
---|
423 | <p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
424 | <p> Removes the item with the key <em>k</em> from the map.
|
---|
425 |
|
---|
426 | <h3 class=fn><a href="qmap.html#iterator">iterator</a> <a name="find"></a>QMap::find ( const Key & k )
|
---|
427 | </h3>
|
---|
428 |
|
---|
429 | <p> Returns an iterator pointing to the element with key <em>k</em> in the
|
---|
430 | map.
|
---|
431 | <p> Returns <a href="#end">end</a>() if no key matched.
|
---|
432 | <p> <p>See also <a href="qmapiterator.html">QMapIterator</a>.
|
---|
433 |
|
---|
434 | <h3 class=fn><a href="qmap.html#const_iterator">const_iterator</a> <a name="find-2"></a>QMap::find ( const Key & k ) const
|
---|
435 | </h3>
|
---|
436 |
|
---|
437 | <p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
438 | <p> Returns an iterator pointing to the element with key <em>k</em> in the
|
---|
439 | map.
|
---|
440 | <p> Returns <a href="#end">end</a>() if no key matched.
|
---|
441 | <p> <p>See also <a href="qmapconstiterator.html">QMapConstIterator</a>.
|
---|
442 |
|
---|
443 | <h3 class=fn><a href="qmap.html#iterator">iterator</a> <a name="insert"></a>QMap::insert ( const Key & key, const T & value, bool overwrite = TRUE )
|
---|
444 | </h3>
|
---|
445 |
|
---|
446 | <p> Inserts a new item with the key, <em>key</em>, and a value of <em>value</em>.
|
---|
447 | If there is already an item whose key is <em>key</em>, that item's value
|
---|
448 | is replaced with <em>value</em>, unless <em>overwrite</em> is FALSE (it is
|
---|
449 | TRUE by default). In this case an iterator to this item is
|
---|
450 | returned, else an iterator to the new item is returned.
|
---|
451 | <p>
|
---|
452 | <h3 class=fn><a href="qpair.html">QPair</a><iterator, bool> <a name="insert-2"></a>QMap::insert ( const <a href="qmap.html#value_type">value_type</a> & x )
|
---|
453 | </h3>
|
---|
454 |
|
---|
455 | <p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
456 | <p> Inserts the (key, value) pair <em>x</em> into the map. <em>x</em> is a <a href="qpair.html">QPair</a>
|
---|
457 | whose <tt>first</tt> element is a key to be inserted and whose <tt>second</tt>
|
---|
458 | element is the associated value to be inserted. Returns a pair
|
---|
459 | whose <tt>first</tt> element is an iterator pointing to the inserted
|
---|
460 | item and whose <tt>second</tt> element is a bool indicating TRUE if <em>x</em>
|
---|
461 | was inserted and FALSE if it was not inserted, e.g. because it was
|
---|
462 | already present.
|
---|
463 | <p> <p>See also <a href="#replace">replace</a>().
|
---|
464 |
|
---|
465 | <h3 class=fn>bool <a name="isEmpty"></a>QMap::isEmpty () const
|
---|
466 | </h3>
|
---|
467 |
|
---|
468 | <p> Returns TRUE if the map contains no items; otherwise returns
|
---|
469 | FALSE.
|
---|
470 | <p> <p>See also <a href="#count">count</a>().
|
---|
471 |
|
---|
472 | <h3 class=fn><a href="qvaluelist.html">QValueList</a><Key> <a name="keys"></a>QMap::keys () const
|
---|
473 | </h3>
|
---|
474 |
|
---|
475 | <p> Returns a list of all the keys in the map, in order.
|
---|
476 |
|
---|
477 | <h3 class=fn><a href="qmap.html">QMap</a><Key, T> & <a name="operator-eq"></a>QMap::operator= ( const <a href="qmap.html">QMap</a><Key, T> & m )
|
---|
478 | </h3>
|
---|
479 |
|
---|
480 | <p> Assigns <em>m</em> to this map and returns a reference to this map.
|
---|
481 | <p> All iterators of the current map become invalidated by this
|
---|
482 | operation. The cost of such an assignment is O(1), because QMap is
|
---|
483 | <a href="shclass.html#implicitly-shared">implicitly shared</a>.
|
---|
484 |
|
---|
485 | <h3 class=fn><a href="qmap.html">QMap</a><Key, T> & <a name="operator-eq-2"></a>QMap::operator= ( const std::map<Key, T> & m )
|
---|
486 | </h3>
|
---|
487 |
|
---|
488 | <p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
489 | <p> Assigns <em>m</em> to this map and returns a reference to this map.
|
---|
490 | <p> All iterators of the current map become invalidated by this
|
---|
491 | operation.
|
---|
492 |
|
---|
493 | <h3 class=fn>T & <a name="operator[]"></a>QMap::operator[] ( const Key & k )
|
---|
494 | </h3>
|
---|
495 |
|
---|
496 | <p> Returns the value associated with the key <em>k</em>. If no such key is
|
---|
497 | present, an empty item is inserted with this key and a reference
|
---|
498 | to the empty item is returned.
|
---|
499 | <p> You can use this operator both for reading and writing:
|
---|
500 | <pre>
|
---|
501 | QMap<QString, QString> map;
|
---|
502 | map["Clinton"] = "Bill";
|
---|
503 | stream << map["Clinton"];
|
---|
504 | </pre>
|
---|
505 |
|
---|
506 |
|
---|
507 | <h3 class=fn>const T & <a name="operator[]-2"></a>QMap::operator[] ( const Key & k ) const
|
---|
508 | </h3>
|
---|
509 |
|
---|
510 | <p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
511 | <p> <b>Warning:</b> This function differs from the non-const version of the
|
---|
512 | same function. It will <em>not</em> insert an empty value if the key <em>k</em> does not exist. This may lead to logic errors in your program.
|
---|
513 | You should check if the element exists before calling this
|
---|
514 | function.
|
---|
515 | <p> Returns the value associated with the key <em>k</em>. If no such key is
|
---|
516 | present, a reference to an empty item is returned.
|
---|
517 |
|
---|
518 | <h3 class=fn>void <a name="remove"></a>QMap::remove ( <a href="qmap.html#iterator">iterator</a> it )
|
---|
519 | </h3>
|
---|
520 |
|
---|
521 | <p> Removes the item associated with the iterator <em>it</em> from the map.
|
---|
522 | <p> <p>See also <a href="#clear">clear</a>().
|
---|
523 |
|
---|
524 | <h3 class=fn>void <a name="remove-2"></a>QMap::remove ( const Key & k )
|
---|
525 | </h3>
|
---|
526 |
|
---|
527 | <p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
528 | <p> Removes the item with the key <em>k</em> from the map.
|
---|
529 |
|
---|
530 | <h3 class=fn><a href="qmap.html#iterator">iterator</a> <a name="replace"></a>QMap::replace ( const Key & k, const T & v )
|
---|
531 | </h3>
|
---|
532 |
|
---|
533 | <p> Replaces the value of the element with key <em>k</em>, with the value <em>v</em>.
|
---|
534 | <p> <p>See also <a href="#insert">insert</a>() and <a href="#remove">remove</a>().
|
---|
535 |
|
---|
536 | <h3 class=fn><a href="qmap.html#size_type">size_type</a> <a name="size"></a>QMap::size () const
|
---|
537 | </h3>
|
---|
538 |
|
---|
539 | <p> Returns the number of items in the map.
|
---|
540 | <p> This function is provided for STL compatibility. It is equivalent
|
---|
541 | to <a href="#count">count</a>().
|
---|
542 | <p> <p>See also <a href="#empty">empty</a>().
|
---|
543 |
|
---|
544 | <h3 class=fn><a href="qvaluelist.html">QValueList</a><T> <a name="values"></a>QMap::values () const
|
---|
545 | </h3>
|
---|
546 |
|
---|
547 | <p> Returns a list of all the values in the map, in key order.
|
---|
548 |
|
---|
549 | <hr><h2>Related Functions</h2>
|
---|
550 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-lt-lt"></a>operator<< ( <a href="qdatastream.html">QDataStream</a> & s, const <a href="qmap.html">QMap</a><Key, T> & m )
|
---|
551 | </h3>
|
---|
552 |
|
---|
553 | <p>
|
---|
554 | <p> Writes the map <em>m</em> to the stream <em>s</em>. The types <em>Key</em> and <em>T</em>
|
---|
555 | must implement the streaming operator as well.
|
---|
556 |
|
---|
557 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-gt-gt"></a>operator>> ( <a href="qdatastream.html">QDataStream</a> & s, <a href="qmap.html">QMap</a><Key, T> & m )
|
---|
558 | </h3>
|
---|
559 |
|
---|
560 | <p>
|
---|
561 | <p> Reads the map <em>m</em> from the stream <em>s</em>. The types <em>Key</em> and <em>T</em>
|
---|
562 | must implement the streaming operator as well.
|
---|
563 |
|
---|
564 | <!-- eof -->
|
---|
565 | <hr><p>
|
---|
566 | This file is part of the <a href="index.html">Qt toolkit</a>.
|
---|
567 | Copyright © 1995-2007
|
---|
568 | <a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
|
---|
569 | <table width=100% cellspacing=0 border=0><tr>
|
---|
570 | <td>Copyright © 2007
|
---|
571 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
572 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
573 | </table></div></address></body>
|
---|
574 | </html>
|
---|