| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the documentation of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:FDL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in a
|
|---|
| 14 | ** written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Free Documentation License
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Free
|
|---|
| 18 | ** Documentation License version 1.3 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file included in the packaging of this
|
|---|
| 20 | ** file.
|
|---|
| 21 | **
|
|---|
| 22 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 23 | ** Nokia at [email protected].
|
|---|
| 24 | ** $QT_END_LICENSE$
|
|---|
| 25 | **
|
|---|
| 26 | ****************************************************************************/
|
|---|
| 27 |
|
|---|
| 28 | /*!
|
|---|
| 29 | \class Q3PtrList
|
|---|
| 30 | \brief The Q3PtrList class is a template class that provides a list.
|
|---|
| 31 | \compat
|
|---|
| 32 |
|
|---|
| 33 | Q3ValueList is an STL-compatible alternative to this class.
|
|---|
| 34 |
|
|---|
| 35 | Define a template instance Q3PtrList\<X\> to create a list that
|
|---|
| 36 | operates on pointers to X (X*).
|
|---|
| 37 |
|
|---|
| 38 | The list class is indexable and has a \link at() current
|
|---|
| 39 | index\endlink and a \link current() current item\endlink. The
|
|---|
| 40 | first item corresponds to index position 0. The current index is
|
|---|
| 41 | -1 if the current item is 0.
|
|---|
| 42 |
|
|---|
| 43 | Items are inserted with prepend(), insert() or append(). Items are
|
|---|
| 44 | removed with remove(), removeRef(), removeFirst() and
|
|---|
| 45 | removeLast(). You can search for an item using find(), findNext(),
|
|---|
| 46 | findRef() or findNextRef(). The list can be sorted with sort().
|
|---|
| 47 | You can count the number of occurrences of an item with contains()
|
|---|
| 48 | or containsRef(). You can get a pointer to the current item with
|
|---|
| 49 | current(), to an item at a particular index position in the list
|
|---|
| 50 | with at() or to the first or last item with getFirst() and
|
|---|
| 51 | getLast(). You can also iterate over the list with first(),
|
|---|
| 52 | last(), next() and prev() (which all update current()). The list's
|
|---|
| 53 | deletion property is set with setAutoDelete().
|
|---|
| 54 |
|
|---|
| 55 | \target example
|
|---|
| 56 | Example:
|
|---|
| 57 | \snippet doc/src/snippets/code/doc_src_q3ptrlist.qdoc 0
|
|---|
| 58 |
|
|---|
| 59 | The output is
|
|---|
| 60 | \snippet doc/src/snippets/code/doc_src_q3ptrlist.qdoc 1
|
|---|
| 61 |
|
|---|
| 62 | Q3PtrList has several member functions for traversing the list, but
|
|---|
| 63 | using a Q3PtrListIterator can be more practical. Multiple list
|
|---|
| 64 | iterators may traverse the same list, independently of each other
|
|---|
| 65 | and of the current list item.
|
|---|
| 66 |
|
|---|
| 67 | In the example above we make the call setAutoDelete(true).
|
|---|
| 68 | Enabling auto-deletion tells the list to delete items that are
|
|---|
| 69 | removed. The default is to not delete items when they are removed
|
|---|
| 70 | but this would cause a memory leak in the example because there
|
|---|
| 71 | are no other references to the list items.
|
|---|
| 72 |
|
|---|
| 73 | When inserting an item into a list only the pointer is copied, not
|
|---|
| 74 | the item itself, i.e. a shallow copy. It is possible to make the
|
|---|
| 75 | list copy all of the item's data (deep copy) when an item is
|
|---|
| 76 | inserted. insert(), inSort() and append() call the virtual
|
|---|
| 77 | function Q3PtrCollection::newItem() for the item to be inserted.
|
|---|
| 78 | Inherit a list and reimplement newItem() to have deep copies.
|
|---|
| 79 |
|
|---|
| 80 | When removing an item from a list, the virtual function
|
|---|
| 81 | Q3PtrCollection::deleteItem() is called. Q3PtrList's default
|
|---|
| 82 | implementation is to delete the item if auto-deletion is enabled.
|
|---|
| 83 |
|
|---|
| 84 | The virtual function compareItems() can be reimplemented to
|
|---|
| 85 | compare two list items. This function is called from all list
|
|---|
| 86 | functions that need to compare list items, for instance
|
|---|
| 87 | remove(const type*). If you only want to deal with pointers, there
|
|---|
| 88 | are functions that compare pointers instead, for instance
|
|---|
| 89 | removeRef(const type*). These functions are somewhat faster than
|
|---|
| 90 | those that call compareItems().
|
|---|
| 91 |
|
|---|
| 92 | List items are stored as \c void* in an internal Q3LNode, which
|
|---|
| 93 | also holds pointers to the next and previous list items. The
|
|---|
| 94 | functions currentNode(), removeNode(), and takeNode() operate
|
|---|
| 95 | directly on the Q3LNode, but they should be used with care. The
|
|---|
| 96 | data component of the node is available through Q3LNode::getData().
|
|---|
| 97 |
|
|---|
| 98 | The Q3StrList class is a list of \c char*.
|
|---|
| 99 | It reimplements newItem(), deleteItem() and compareItems(). (But
|
|---|
| 100 | see QStringList for a list of Unicode QStrings.)
|
|---|
| 101 |
|
|---|
| 102 | \sa Q3PtrListIterator
|
|---|
| 103 | */
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 | /*!
|
|---|
| 107 | \fn Q3PtrList::Q3PtrList()
|
|---|
| 108 |
|
|---|
| 109 | Constructs an empty list.
|
|---|
| 110 | */
|
|---|
| 111 |
|
|---|
| 112 | /*!
|
|---|
| 113 | \fn Q3PtrList::Q3PtrList( const Q3PtrList<type> &list )
|
|---|
| 114 |
|
|---|
| 115 | Constructs a copy of \a list.
|
|---|
| 116 |
|
|---|
| 117 | Each item in \a list is \link append() appended\endlink to this
|
|---|
| 118 | list. Only the pointers are copied (shallow copy).
|
|---|
| 119 | */
|
|---|
| 120 |
|
|---|
| 121 | /*!
|
|---|
| 122 | \fn Q3PtrList::~Q3PtrList()
|
|---|
| 123 |
|
|---|
| 124 | Removes all items from the list and destroys the list.
|
|---|
| 125 |
|
|---|
| 126 | All list iterators that access this list will be reset.
|
|---|
| 127 |
|
|---|
| 128 | \sa setAutoDelete()
|
|---|
| 129 | */
|
|---|
| 130 |
|
|---|
| 131 | /*!
|
|---|
| 132 | \fn Q3PtrList<type> &Q3PtrList::operator=(const Q3PtrList<type> &list)
|
|---|
| 133 |
|
|---|
| 134 | Assigns \a list to this list and returns a reference to this list.
|
|---|
| 135 |
|
|---|
| 136 | This list is first cleared and then each item in \a list is \link
|
|---|
| 137 | append() appended\endlink to this list. Only the pointers are
|
|---|
| 138 | copied (shallow copy) unless newItem() has been reimplemented.
|
|---|
| 139 | */
|
|---|
| 140 |
|
|---|
| 141 | /*!
|
|---|
| 142 | \fn bool Q3PtrList::operator==(const Q3PtrList<type> &list ) const
|
|---|
| 143 |
|
|---|
| 144 | Compares this list with \a list. Returns TRUE if the lists contain
|
|---|
| 145 | the same data; otherwise returns FALSE.
|
|---|
| 146 | */
|
|---|
| 147 |
|
|---|
| 148 | /*!
|
|---|
| 149 | \fn uint Q3PtrList::count() const
|
|---|
| 150 |
|
|---|
| 151 | Returns the number of items in the list.
|
|---|
| 152 |
|
|---|
| 153 | \sa isEmpty()
|
|---|
| 154 | */
|
|---|
| 155 |
|
|---|
| 156 | /*!
|
|---|
| 157 | \fn bool Q3PtrList::operator!=(const Q3PtrList<type> &list ) const
|
|---|
| 158 |
|
|---|
| 159 | Compares this list with \a list. Returns TRUE if the lists contain
|
|---|
| 160 | different data; otherwise returns FALSE.
|
|---|
| 161 | */
|
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 | /*!
|
|---|
| 165 | \fn void Q3PtrList::sort()
|
|---|
| 166 |
|
|---|
| 167 | Sorts the list by the result of the virtual compareItems()
|
|---|
| 168 | function.
|
|---|
| 169 |
|
|---|
| 170 | The heap sort algorithm is used for sorting. It sorts n items with
|
|---|
| 171 | O(n*log n) comparisons. This is the asymptotic optimal solution of
|
|---|
| 172 | the sorting problem.
|
|---|
| 173 |
|
|---|
| 174 | If the items in your list support operator<() and operator==(),
|
|---|
| 175 | you might be better off with Q3SortedList because it implements the
|
|---|
| 176 | compareItems() function for you using these two operators.
|
|---|
| 177 |
|
|---|
| 178 | \sa inSort()
|
|---|
| 179 | */
|
|---|
| 180 |
|
|---|
| 181 | /*!
|
|---|
| 182 | \fn bool Q3PtrList::isEmpty() const
|
|---|
| 183 |
|
|---|
| 184 | Returns TRUE if the list is empty; otherwise returns FALSE.
|
|---|
| 185 |
|
|---|
| 186 | \sa count()
|
|---|
| 187 | */
|
|---|
| 188 |
|
|---|
| 189 | /*!
|
|---|
| 190 | \fn bool Q3PtrList::insert( uint index, const type *item )
|
|---|
| 191 |
|
|---|
| 192 | Inserts the \a item at position \a index in the list.
|
|---|
| 193 |
|
|---|
| 194 | Returns TRUE if successful, i.e. if \a index is in range;
|
|---|
| 195 | otherwise returns FALSE. The valid range is 0 to count()
|
|---|
| 196 | (inclusively). The item is appended if \a index == count().
|
|---|
| 197 |
|
|---|
| 198 | The inserted item becomes the current list item.
|
|---|
| 199 |
|
|---|
| 200 | \a item must not be 0.
|
|---|
| 201 |
|
|---|
| 202 | \sa append(), current(), replace()
|
|---|
| 203 | */
|
|---|
| 204 |
|
|---|
| 205 | /*!
|
|---|
| 206 | \fn bool Q3PtrList::replace( uint index, const type *item )
|
|---|
| 207 |
|
|---|
| 208 | Replaces the item at position \a index with the new \a item.
|
|---|
| 209 |
|
|---|
| 210 | Returns TRUE if successful, i.e. \a index is in the range 0 to
|
|---|
| 211 | count()-1.
|
|---|
| 212 |
|
|---|
| 213 | \sa append(), current(), insert()
|
|---|
| 214 | */
|
|---|
| 215 |
|
|---|
| 216 | /*!
|
|---|
| 217 | \fn void Q3PtrList::inSort( const type *item )
|
|---|
| 218 |
|
|---|
| 219 | Inserts the \a item at its sorted position in the list.
|
|---|
| 220 |
|
|---|
| 221 | The sort order depends on the virtual compareItems() function. All
|
|---|
| 222 | items must be inserted with inSort() to maintain the sorting
|
|---|
| 223 | order.
|
|---|
| 224 |
|
|---|
| 225 | The inserted item becomes the current list item.
|
|---|
| 226 |
|
|---|
| 227 | \a item must not be 0.
|
|---|
| 228 |
|
|---|
| 229 | \warning Using inSort() is slow. An alternative, especially if you
|
|---|
| 230 | have lots of items, is to simply append() or insert() them and
|
|---|
| 231 | then use sort(). inSort() takes up to O(n) compares. That means
|
|---|
| 232 | inserting n items in your list will need O(n^2) compares whereas
|
|---|
| 233 | sort() only needs O(n*log n) for the same task. So use inSort()
|
|---|
| 234 | only if you already have a presorted list and want to insert just
|
|---|
| 235 | a few additional items.
|
|---|
| 236 |
|
|---|
| 237 | \sa insert(), compareItems(), current(), sort()
|
|---|
| 238 | */
|
|---|
| 239 |
|
|---|
| 240 | /*!
|
|---|
| 241 | \fn void Q3PtrList::append( const type *item )
|
|---|
| 242 |
|
|---|
| 243 | Inserts the \a item at the end of the list.
|
|---|
| 244 |
|
|---|
| 245 | The inserted item becomes the current list item. This is
|
|---|
| 246 | equivalent to \c{insert( count(), item )}.
|
|---|
| 247 |
|
|---|
| 248 | \a item must not be 0.
|
|---|
| 249 |
|
|---|
| 250 | \sa insert(), current(), prepend()
|
|---|
| 251 | */
|
|---|
| 252 |
|
|---|
| 253 | /*!
|
|---|
| 254 | \fn void Q3PtrList::prepend( const type *item )
|
|---|
| 255 |
|
|---|
| 256 | Inserts the \a item at the start of the list.
|
|---|
| 257 |
|
|---|
| 258 | The inserted item becomes the current list item. This is
|
|---|
| 259 | equivalent to \c{insert( 0, item )}.
|
|---|
| 260 |
|
|---|
| 261 | \a item must not be 0.
|
|---|
| 262 |
|
|---|
| 263 | \sa append(), insert(), current()
|
|---|
| 264 | */
|
|---|
| 265 |
|
|---|
| 266 | /*!
|
|---|
| 267 | \fn bool Q3PtrList::remove( uint index )
|
|---|
| 268 |
|
|---|
| 269 | Removes the item at position \a index in the list.
|
|---|
| 270 |
|
|---|
| 271 | Returns TRUE if successful, i.e. if \a index is in range;
|
|---|
| 272 | otherwise returns FALSE. The valid range is \c{0..(count() - 1)}
|
|---|
| 273 | inclusive.
|
|---|
| 274 |
|
|---|
| 275 | The removed item is deleted if \link setAutoDelete()
|
|---|
| 276 | auto-deletion\endlink is enabled.
|
|---|
| 277 |
|
|---|
| 278 | The item after the removed item becomes the new current list item
|
|---|
| 279 | if the removed item is not the last item in the list. If the last
|
|---|
| 280 | item is removed, the new last item becomes the current item.
|
|---|
| 281 |
|
|---|
| 282 | All list iterators that refer to the removed item will be set to
|
|---|
| 283 | point to the new current item.
|
|---|
| 284 |
|
|---|
| 285 | \sa take(), clear(), setAutoDelete(), current() removeRef()
|
|---|
| 286 | */
|
|---|
| 287 |
|
|---|
| 288 | /*!
|
|---|
| 289 | \fn bool Q3PtrList::remove()
|
|---|
| 290 |
|
|---|
| 291 | \overload
|
|---|
| 292 |
|
|---|
| 293 | Removes the current list item.
|
|---|
| 294 |
|
|---|
| 295 | Returns TRUE if successful, i.e. if the current item isn't 0;
|
|---|
| 296 | otherwise returns FALSE.
|
|---|
| 297 |
|
|---|
| 298 | The removed item is deleted if \link setAutoDelete()
|
|---|
| 299 | auto-deletion\endlink is enabled.
|
|---|
| 300 |
|
|---|
| 301 | The item after the removed item becomes the new current list item
|
|---|
| 302 | if the removed item is not the last item in the list. If the last
|
|---|
| 303 | item is removed, the new last item becomes the current item. The
|
|---|
| 304 | current item is set to 0 if the list becomes empty.
|
|---|
| 305 |
|
|---|
| 306 | All list iterators that refer to the removed item will be set to
|
|---|
| 307 | point to the new current item.
|
|---|
| 308 |
|
|---|
| 309 | \sa take(), clear(), setAutoDelete(), current() removeRef()
|
|---|
| 310 | */
|
|---|
| 311 |
|
|---|
| 312 | /*!
|
|---|
| 313 | \fn bool Q3PtrList::remove( const type *item )
|
|---|
| 314 |
|
|---|
| 315 | \overload
|
|---|
| 316 |
|
|---|
| 317 | Removes the first occurrence of \a item from the list.
|
|---|
| 318 |
|
|---|
| 319 | Returns TRUE if successful, i.e. if \a item is in the list;
|
|---|
| 320 | otherwise returns FALSE.
|
|---|
| 321 |
|
|---|
| 322 | The removed item is deleted if \link setAutoDelete()
|
|---|
| 323 | auto-deletion\endlink is enabled.
|
|---|
| 324 |
|
|---|
| 325 | The compareItems() function is called when searching for the item
|
|---|
| 326 | in the list. If compareItems() is not reimplemented, it is more
|
|---|
| 327 | efficient to call removeRef().
|
|---|
| 328 |
|
|---|
| 329 | If \a item is NULL then the current item is removed from the list.
|
|---|
| 330 |
|
|---|
| 331 | The item after the removed item becomes the new current list item
|
|---|
| 332 | if the removed item is not the last item in the list. If the last
|
|---|
| 333 | item is removed, the new last item becomes the current item. The
|
|---|
| 334 | current item is set to 0 if the list becomes empty.
|
|---|
| 335 |
|
|---|
| 336 | All list iterators that refer to the removed item will be set to
|
|---|
| 337 | point to the new current item.
|
|---|
| 338 |
|
|---|
| 339 | \sa removeRef(), take(), clear(), setAutoDelete(), compareItems(),
|
|---|
| 340 | current()
|
|---|
| 341 | */
|
|---|
| 342 |
|
|---|
| 343 | /*!
|
|---|
| 344 | \fn bool Q3PtrList::removeRef( const type *item )
|
|---|
| 345 |
|
|---|
| 346 | Removes the first occurrence of \a item from the list.
|
|---|
| 347 |
|
|---|
| 348 | Returns TRUE if successful, i.e. if \a item is in the list;
|
|---|
| 349 | otherwise returns FALSE.
|
|---|
| 350 |
|
|---|
| 351 | The removed item is deleted if \link setAutoDelete()
|
|---|
| 352 | auto-deletion\endlink is enabled.
|
|---|
| 353 |
|
|---|
| 354 | Equivalent to:
|
|---|
| 355 | \snippet doc/src/snippets/code/doc_src_q3ptrlist.qdoc 2
|
|---|
| 356 |
|
|---|
| 357 | The item after the removed item becomes the new current list item
|
|---|
| 358 | if the removed item is not the last item in the list. If the last
|
|---|
| 359 | item is removed, the new last item becomes the current item. The
|
|---|
| 360 | current item is set to 0 if the list becomes empty.
|
|---|
| 361 |
|
|---|
| 362 | All list iterators that refer to the removed item will be set to
|
|---|
| 363 | point to the new current item.
|
|---|
| 364 |
|
|---|
| 365 | \sa remove(), clear(), setAutoDelete(), current()
|
|---|
| 366 | */
|
|---|
| 367 |
|
|---|
| 368 | /*!
|
|---|
| 369 | \fn void Q3PtrList::removeNode( Q3LNode *node )
|
|---|
| 370 |
|
|---|
| 371 | Removes the \a node from the list.
|
|---|
| 372 |
|
|---|
| 373 | This node must exist in the list, otherwise the program may crash.
|
|---|
| 374 |
|
|---|
| 375 | The removed item is deleted if \link setAutoDelete()
|
|---|
| 376 | auto-deletion\endlink is enabled.
|
|---|
| 377 |
|
|---|
| 378 | The first item in the list will become the new current list item.
|
|---|
| 379 | The current item is set to 0 if the list becomes empty.
|
|---|
| 380 |
|
|---|
| 381 | All list iterators that refer to the removed item will be set to
|
|---|
| 382 | point to the item succeeding this item or to the preceding item if
|
|---|
| 383 | the removed item was the last item.
|
|---|
| 384 |
|
|---|
| 385 | \warning Do not call this function unless you are an expert.
|
|---|
| 386 |
|
|---|
| 387 | \sa takeNode(), currentNode() remove() removeRef()
|
|---|
| 388 | */
|
|---|
| 389 |
|
|---|
| 390 | /*!
|
|---|
| 391 | \fn bool Q3PtrList::removeFirst()
|
|---|
| 392 |
|
|---|
| 393 | Removes the first item from the list. Returns TRUE if successful,
|
|---|
| 394 | i.e. if the list isn't empty; otherwise returns FALSE.
|
|---|
| 395 |
|
|---|
| 396 | The removed item is deleted if \link setAutoDelete()
|
|---|
| 397 | auto-deletion\endlink is enabled.
|
|---|
| 398 |
|
|---|
| 399 | The first item in the list becomes the new current list item. The
|
|---|
| 400 | current item is set to 0 if the list becomes empty.
|
|---|
| 401 |
|
|---|
| 402 | All list iterators that refer to the removed item will be set to
|
|---|
| 403 | point to the new current item.
|
|---|
| 404 |
|
|---|
| 405 | \sa removeLast(), setAutoDelete(), current() remove()
|
|---|
| 406 | */
|
|---|
| 407 |
|
|---|
| 408 | /*!
|
|---|
| 409 | \fn bool Q3PtrList::removeLast()
|
|---|
| 410 |
|
|---|
| 411 | Removes the last item from the list. Returns TRUE if successful,
|
|---|
| 412 | i.e. if the list isn't empty; otherwise returns FALSE.
|
|---|
| 413 |
|
|---|
| 414 | The removed item is deleted if \link setAutoDelete()
|
|---|
| 415 | auto-deletion\endlink is enabled.
|
|---|
| 416 |
|
|---|
| 417 | The last item in the list becomes the new current list item. The
|
|---|
| 418 | current item is set to 0 if the list becomes empty.
|
|---|
| 419 |
|
|---|
| 420 | All list iterators that refer to the removed item will be set to
|
|---|
| 421 | point to the new current item.
|
|---|
| 422 |
|
|---|
| 423 | \sa removeFirst(), setAutoDelete(), current()
|
|---|
| 424 | */
|
|---|
| 425 |
|
|---|
| 426 | /*!
|
|---|
| 427 | \fn type *Q3PtrList::take( uint index )
|
|---|
| 428 |
|
|---|
| 429 | Takes the item at position \a index out of the list without
|
|---|
| 430 | deleting it (even if \link setAutoDelete() auto-deletion\endlink
|
|---|
| 431 | is enabled).
|
|---|
| 432 |
|
|---|
| 433 | Returns a pointer to the item taken out of the list, or 0 if the
|
|---|
| 434 | index is out of range. The valid range is \c{0..(count() - 1)}
|
|---|
| 435 | inclusive.
|
|---|
| 436 |
|
|---|
| 437 | The item after the removed item becomes the new current list item
|
|---|
| 438 | if the removed item is not the last item in the list. If the last
|
|---|
| 439 | item is removed, the new last item becomes the current item. The
|
|---|
| 440 | current item is set to 0 if the list becomes empty.
|
|---|
| 441 |
|
|---|
| 442 | All list iterators that refer to the taken item will be set to
|
|---|
| 443 | point to the new current item.
|
|---|
| 444 |
|
|---|
| 445 | \sa remove(), clear(), current()
|
|---|
| 446 | */
|
|---|
| 447 |
|
|---|
| 448 | /*!
|
|---|
| 449 | \fn type *Q3PtrList::take()
|
|---|
| 450 |
|
|---|
| 451 | \overload
|
|---|
| 452 |
|
|---|
| 453 | Takes the current item out of the list without deleting it (even
|
|---|
| 454 | if \link setAutoDelete() auto-deletion\endlink is enabled).
|
|---|
| 455 |
|
|---|
| 456 | Returns a pointer to the item taken out of the list, or 0 if
|
|---|
| 457 | the current item is 0.
|
|---|
| 458 |
|
|---|
| 459 | The item after the removed item becomes the new current list item
|
|---|
| 460 | if the removed item is not the last item in the list. If the last
|
|---|
| 461 | item is removed, the new last item becomes the current item. The
|
|---|
| 462 | current item is set to 0 if the list becomes empty.
|
|---|
| 463 |
|
|---|
| 464 | All list iterators that refer to the taken item will be set to
|
|---|
| 465 | point to the new current item.
|
|---|
| 466 |
|
|---|
| 467 | \sa remove(), clear(), current()
|
|---|
| 468 | */
|
|---|
| 469 |
|
|---|
| 470 | /*!
|
|---|
| 471 | \fn type *Q3PtrList::takeNode( Q3LNode *node )
|
|---|
| 472 |
|
|---|
| 473 | Takes the \a node out of the list without deleting its item (even
|
|---|
| 474 | if \link setAutoDelete() auto-deletion\endlink is enabled).
|
|---|
| 475 | Returns a pointer to the item taken out of the list.
|
|---|
| 476 |
|
|---|
| 477 | This node must exist in the list, otherwise the program may crash.
|
|---|
| 478 |
|
|---|
| 479 | The first item in the list becomes the new current list item.
|
|---|
| 480 |
|
|---|
| 481 | All list iterators that refer to the taken item will be set to
|
|---|
| 482 | point to the item succeeding this item or to the preceding item if
|
|---|
| 483 | the taken item was the last item.
|
|---|
| 484 |
|
|---|
| 485 | \warning Do not call this function unless you are an expert.
|
|---|
| 486 |
|
|---|
| 487 | \sa removeNode(), currentNode()
|
|---|
| 488 | */
|
|---|
| 489 |
|
|---|
| 490 | /*!
|
|---|
| 491 | \fn void Q3PtrList::clear()
|
|---|
| 492 |
|
|---|
| 493 | Removes all items from the list.
|
|---|
| 494 |
|
|---|
| 495 | The removed items are deleted if \link setAutoDelete()
|
|---|
| 496 | auto-deletion\endlink is enabled.
|
|---|
| 497 |
|
|---|
| 498 | All list iterators that access this list will be reset.
|
|---|
| 499 |
|
|---|
| 500 | \sa remove(), take(), setAutoDelete()
|
|---|
| 501 | */
|
|---|
| 502 |
|
|---|
| 503 | /*!
|
|---|
| 504 | \fn int Q3PtrList::find( const type *item )
|
|---|
| 505 |
|
|---|
| 506 | Finds the first occurrence of \a item in the list.
|
|---|
| 507 |
|
|---|
| 508 | If the item is found, the list sets the current item to point to
|
|---|
| 509 | the found item and returns the index of this item. If the item is
|
|---|
| 510 | not found, the list sets the current item to 0, the current
|
|---|
| 511 | index to -1, and returns -1.
|
|---|
| 512 |
|
|---|
| 513 | The compareItems() function is called when searching for the item
|
|---|
| 514 | in the list. If compareItems() is not reimplemented, it is more
|
|---|
| 515 | efficient to call findRef().
|
|---|
| 516 |
|
|---|
| 517 | \sa findNext(), findRef(), compareItems(), current()
|
|---|
| 518 | */
|
|---|
| 519 |
|
|---|
| 520 | /*!
|
|---|
| 521 | \fn int Q3PtrList::findNext( const type *item )
|
|---|
| 522 |
|
|---|
| 523 | Finds the next occurrence of \a item in the list, starting from
|
|---|
| 524 | the current list item.
|
|---|
| 525 |
|
|---|
| 526 | If the item is found, the list sets the current item to point to
|
|---|
| 527 | the found item and returns the index of this item. If the item is
|
|---|
| 528 | not found, the list sets the current item to 0, the current
|
|---|
| 529 | index to -1, and returns -1.
|
|---|
| 530 |
|
|---|
| 531 | The compareItems() function is called when searching for the item
|
|---|
| 532 | in the list. If compareItems() is not reimplemented, it is more
|
|---|
| 533 | efficient to call findNextRef().
|
|---|
| 534 |
|
|---|
| 535 | \sa find(), findNextRef(), compareItems(), current()
|
|---|
| 536 | */
|
|---|
| 537 |
|
|---|
| 538 | /*!
|
|---|
| 539 | \fn int Q3PtrList::findRef( const type *item )
|
|---|
| 540 |
|
|---|
| 541 | Finds the first occurrence of \a item in the list.
|
|---|
| 542 |
|
|---|
| 543 | If the item is found, the list sets the current item to point to
|
|---|
| 544 | the found item and returns the index of this item. If the item is
|
|---|
| 545 | not found, the list sets the current item to 0, the current
|
|---|
| 546 | index to -1, and returns -1.
|
|---|
| 547 |
|
|---|
| 548 | Calling this function is much faster than find() because find()
|
|---|
| 549 | compares \a item with each list item using compareItems(), whereas
|
|---|
| 550 | this function only compares the pointers.
|
|---|
| 551 |
|
|---|
| 552 | \sa findNextRef(), find(), current()
|
|---|
| 553 | */
|
|---|
| 554 |
|
|---|
| 555 | /*!
|
|---|
| 556 | \fn int Q3PtrList::findNextRef( const type *item )
|
|---|
| 557 |
|
|---|
| 558 | Finds the next occurrence of \a item in the list, starting from
|
|---|
| 559 | the current list item.
|
|---|
| 560 |
|
|---|
| 561 | If the item is found, the list sets the current item to point to
|
|---|
| 562 | the found item and returns the index of this item. If the item is
|
|---|
| 563 | not found, the list sets the current item to 0, the current
|
|---|
| 564 | index to -1, and returns -1.
|
|---|
| 565 |
|
|---|
| 566 | Calling this function is much faster than findNext() because
|
|---|
| 567 | findNext() compares \a item with each list item using
|
|---|
| 568 | compareItems(), whereas this function only compares the pointers.
|
|---|
| 569 |
|
|---|
| 570 | \sa findRef(), findNext(), current()
|
|---|
| 571 | */
|
|---|
| 572 |
|
|---|
| 573 | /*!
|
|---|
| 574 | \fn uint Q3PtrList::contains( const type *item ) const
|
|---|
| 575 |
|
|---|
| 576 | Returns the number of occurrences of \a item in the list.
|
|---|
| 577 |
|
|---|
| 578 | The compareItems() function is called when looking for the \a item
|
|---|
| 579 | in the list. If compareItems() is not reimplemented, it is more
|
|---|
| 580 | efficient to call containsRef().
|
|---|
| 581 |
|
|---|
| 582 | This function does not affect the current list item.
|
|---|
| 583 |
|
|---|
| 584 | \sa containsRef(), compareItems()
|
|---|
| 585 | */
|
|---|
| 586 |
|
|---|
| 587 | /*!
|
|---|
| 588 | \fn uint Q3PtrList::containsRef( const type *item ) const
|
|---|
| 589 |
|
|---|
| 590 | Returns the number of occurrences of \a item in the list.
|
|---|
| 591 |
|
|---|
| 592 | Calling this function is much faster than contains() because
|
|---|
| 593 | contains() compares \a item with each list item using
|
|---|
| 594 | compareItems(), whereas his function only compares the pointers.
|
|---|
| 595 |
|
|---|
| 596 | This function does not affect the current list item.
|
|---|
| 597 |
|
|---|
| 598 | \sa contains()
|
|---|
| 599 | */
|
|---|
| 600 |
|
|---|
| 601 | /*!
|
|---|
| 602 | \fn type *Q3PtrList::at( uint index )
|
|---|
| 603 |
|
|---|
| 604 | Returns a pointer to the item at position \a index in the list, or
|
|---|
| 605 | 0 if the index is out of range.
|
|---|
| 606 |
|
|---|
| 607 | Sets the current list item to this item if \a index is valid. The
|
|---|
| 608 | valid range is \c{0..(count() - 1)} inclusive.
|
|---|
| 609 |
|
|---|
| 610 | This function is very efficient. It starts scanning from the first
|
|---|
| 611 | item, last item, or current item, whichever is closest to \a
|
|---|
| 612 | index.
|
|---|
| 613 |
|
|---|
| 614 | \sa current()
|
|---|
| 615 | */
|
|---|
| 616 |
|
|---|
| 617 | /*!
|
|---|
| 618 | \fn int Q3PtrList::at() const
|
|---|
| 619 |
|
|---|
| 620 | \overload
|
|---|
| 621 |
|
|---|
| 622 | Returns the index of the current list item. The returned value is
|
|---|
| 623 | -1 if the current item is 0.
|
|---|
| 624 |
|
|---|
| 625 | \sa current()
|
|---|
| 626 | */
|
|---|
| 627 |
|
|---|
| 628 | /*!
|
|---|
| 629 | \fn type *Q3PtrList::current() const
|
|---|
| 630 |
|
|---|
| 631 | Returns a pointer to the current list item. The current item may
|
|---|
| 632 | be 0 (implies that the current index is -1).
|
|---|
| 633 |
|
|---|
| 634 | \sa at()
|
|---|
| 635 | */
|
|---|
| 636 |
|
|---|
| 637 | /*!
|
|---|
| 638 | \fn Q3LNode *Q3PtrList::currentNode() const
|
|---|
| 639 |
|
|---|
| 640 | Returns a pointer to the current list node.
|
|---|
| 641 |
|
|---|
| 642 | The node can be kept and removed later using removeNode(). The
|
|---|
| 643 | advantage is that the item can be removed directly without
|
|---|
| 644 | searching the list.
|
|---|
| 645 |
|
|---|
| 646 | \warning Do not call this function unless you are an expert.
|
|---|
| 647 |
|
|---|
| 648 | \sa removeNode(), takeNode(), current()
|
|---|
| 649 | */
|
|---|
| 650 |
|
|---|
| 651 | /*!
|
|---|
| 652 | \fn type *Q3PtrList::getFirst() const
|
|---|
| 653 |
|
|---|
| 654 | Returns a pointer to the first item in the list, or 0 if the list
|
|---|
| 655 | is empty.
|
|---|
| 656 |
|
|---|
| 657 | This function does not affect the current list item.
|
|---|
| 658 |
|
|---|
| 659 | \sa first(), getLast()
|
|---|
| 660 | */
|
|---|
| 661 |
|
|---|
| 662 | /*!
|
|---|
| 663 | \fn type *Q3PtrList::getLast() const
|
|---|
| 664 |
|
|---|
| 665 | Returns a pointer to the last item in the list, or 0 if the list
|
|---|
| 666 | is empty.
|
|---|
| 667 |
|
|---|
| 668 | This function does not affect the current list item.
|
|---|
| 669 |
|
|---|
| 670 | \sa last(), getFirst()
|
|---|
| 671 | */
|
|---|
| 672 |
|
|---|
| 673 | /*!
|
|---|
| 674 | \fn type *Q3PtrList::first()
|
|---|
| 675 |
|
|---|
| 676 | Returns a pointer to the first item in the list and makes this the
|
|---|
| 677 | current list item; returns 0 if the list is empty.
|
|---|
| 678 |
|
|---|
| 679 | \sa getFirst(), last(), next(), prev(), current()
|
|---|
| 680 | */
|
|---|
| 681 |
|
|---|
| 682 | /*!
|
|---|
| 683 | \fn type *Q3PtrList::last()
|
|---|
| 684 |
|
|---|
| 685 | Returns a pointer to the last item in the list and makes this the
|
|---|
| 686 | current list item; returns 0 if the list is empty.
|
|---|
| 687 |
|
|---|
| 688 | \sa getLast(), first(), next(), prev(), current()
|
|---|
| 689 | */
|
|---|
| 690 |
|
|---|
| 691 | /*!
|
|---|
| 692 | \fn type *Q3PtrList::next()
|
|---|
| 693 |
|
|---|
| 694 | Returns a pointer to the item succeeding the current item. Returns
|
|---|
| 695 | 0 if the current item is 0 or equal to the last item.
|
|---|
| 696 |
|
|---|
| 697 | Makes the succeeding item current. If the current item before this
|
|---|
| 698 | function call was the last item, the current item will be set to
|
|---|
| 699 | 0. If the current item was 0, this function does nothing.
|
|---|
| 700 |
|
|---|
| 701 | \sa first(), last(), prev(), current()
|
|---|
| 702 | */
|
|---|
| 703 |
|
|---|
| 704 | /*!
|
|---|
| 705 | \fn type *Q3PtrList::prev()
|
|---|
| 706 |
|
|---|
| 707 | Returns a pointer to the item preceding the current item. Returns
|
|---|
| 708 | 0 if the current item is 0 or equal to the first item.
|
|---|
| 709 |
|
|---|
| 710 | Makes the preceding item current. If the current item before this
|
|---|
| 711 | function call was the first item, the current item will be set to
|
|---|
| 712 | 0. If the current item was 0, this function does nothing.
|
|---|
| 713 |
|
|---|
| 714 | \sa first(), last(), next(), current()
|
|---|
| 715 | */
|
|---|
| 716 |
|
|---|
| 717 | /*!
|
|---|
| 718 | \fn void Q3PtrList::toVector( Q3GVector *vec ) const
|
|---|
| 719 |
|
|---|
| 720 | Stores all list items in the vector \a vec.
|
|---|
| 721 |
|
|---|
| 722 | The vector must be of the same item type, otherwise the result
|
|---|
| 723 | will be undefined.
|
|---|
| 724 | */
|
|---|
| 725 |
|
|---|
| 726 | /*!
|
|---|
| 727 | \typedef Q3PtrList::iterator
|
|---|
| 728 |
|
|---|
| 729 | \internal
|
|---|
| 730 | */
|
|---|
| 731 |
|
|---|
| 732 | /*!
|
|---|
| 733 | \typedef Q3PtrList::Iterator
|
|---|
| 734 |
|
|---|
| 735 | \internal
|
|---|
| 736 | */
|
|---|
| 737 |
|
|---|
| 738 | /*!
|
|---|
| 739 | \typedef Q3PtrList::ConstIterator
|
|---|
| 740 |
|
|---|
| 741 | \internal
|
|---|
| 742 | */
|
|---|
| 743 |
|
|---|
| 744 | /*!
|
|---|
| 745 | \typedef Q3PtrList::const_iterator
|
|---|
| 746 |
|
|---|
| 747 | \internal
|
|---|
| 748 | */
|
|---|
| 749 |
|
|---|
| 750 | /*!
|
|---|
| 751 | \fn Q3PtrList::constBegin() const
|
|---|
| 752 |
|
|---|
| 753 | \internal
|
|---|
| 754 | */
|
|---|
| 755 |
|
|---|
| 756 | /*!
|
|---|
| 757 | \fn Q3PtrList::constEnd() const
|
|---|
| 758 |
|
|---|
| 759 | \internal
|
|---|
| 760 | */
|
|---|
| 761 |
|
|---|
| 762 | /*!
|
|---|
| 763 | \fn Q3PtrList::erase(Iterator)
|
|---|
| 764 |
|
|---|
| 765 | \internal
|
|---|
| 766 | */
|
|---|
| 767 |
|
|---|
| 768 |
|
|---|
| 769 | /*****************************************************************************
|
|---|
| 770 | Q3PtrListIterator documentation
|
|---|
| 771 | *****************************************************************************/
|
|---|
| 772 |
|
|---|
| 773 | /*!
|
|---|
| 774 | \class Q3PtrListIterator
|
|---|
| 775 | \brief The Q3PtrListIterator class provides an iterator for
|
|---|
| 776 | Q3PtrList collections.
|
|---|
| 777 | \compat
|
|---|
| 778 |
|
|---|
| 779 | Define a template instance Q3PtrListIterator\<X\> to create a list
|
|---|
| 780 | iterator that operates on Q3PtrList\<X\> (list of X*).
|
|---|
| 781 |
|
|---|
| 782 | The following example is similar to the
|
|---|
| 783 | example in the Q3PtrList class documentation,
|
|---|
| 784 | but it uses Q3PtrListIterator. The class Employee is
|
|---|
| 785 | defined there.
|
|---|
| 786 |
|
|---|
| 787 | \snippet doc/src/snippets/code/doc_src_q3ptrlist.qdoc 3
|
|---|
| 788 |
|
|---|
| 789 | The output is
|
|---|
| 790 | \snippet doc/src/snippets/code/doc_src_q3ptrlist.qdoc 4
|
|---|
| 791 |
|
|---|
| 792 | Using a list iterator is a more robust way of traversing the list
|
|---|
| 793 | than using the Q3PtrList member functions \link Q3PtrList::first()
|
|---|
| 794 | first\endlink(), \link Q3PtrList::next() next\endlink(), \link
|
|---|
| 795 | Q3PtrList::current() current\endlink(), etc., as many iterators can
|
|---|
| 796 | traverse the same list independently.
|
|---|
| 797 |
|
|---|
| 798 | An iterator has its own current list item and can get the next and
|
|---|
| 799 | previous list items. It doesn't modify the list in any way.
|
|---|
| 800 |
|
|---|
| 801 | When an item is removed from the list, all iterators that point to
|
|---|
| 802 | that item are updated to point to Q3PtrList::current() instead to
|
|---|
| 803 | avoid dangling references.
|
|---|
| 804 |
|
|---|
| 805 | \sa Q3PtrList
|
|---|
| 806 | */
|
|---|
| 807 |
|
|---|
| 808 | /*!
|
|---|
| 809 | \fn Q3PtrListIterator::Q3PtrListIterator( const Q3PtrList<type> &list )
|
|---|
| 810 |
|
|---|
| 811 | Constructs an iterator for \a list. The current iterator item is
|
|---|
| 812 | set to point on the first item in the \a list.
|
|---|
| 813 | */
|
|---|
| 814 |
|
|---|
| 815 | /*!
|
|---|
| 816 | \fn Q3PtrListIterator::~Q3PtrListIterator()
|
|---|
| 817 |
|
|---|
| 818 | Destroys the iterator.
|
|---|
| 819 | */
|
|---|
| 820 |
|
|---|
| 821 | /*!
|
|---|
| 822 | \fn uint Q3PtrListIterator::count() const
|
|---|
| 823 |
|
|---|
| 824 | Returns the number of items in the list this iterator operates on.
|
|---|
| 825 |
|
|---|
| 826 | \sa isEmpty()
|
|---|
| 827 | */
|
|---|
| 828 |
|
|---|
| 829 | /*!
|
|---|
| 830 | \fn bool Q3PtrListIterator::isEmpty() const
|
|---|
| 831 |
|
|---|
| 832 | Returns TRUE if the list is empty; otherwise returns FALSE.
|
|---|
| 833 |
|
|---|
| 834 | \sa count()
|
|---|
| 835 | */
|
|---|
| 836 |
|
|---|
| 837 | /*!
|
|---|
| 838 | \fn bool Q3PtrListIterator::atFirst() const
|
|---|
| 839 |
|
|---|
| 840 | Returns TRUE if the current iterator item is the first list item;
|
|---|
| 841 | otherwise returns FALSE.
|
|---|
| 842 |
|
|---|
| 843 | \sa toFirst(), atLast()
|
|---|
| 844 | */
|
|---|
| 845 |
|
|---|
| 846 | /*!
|
|---|
| 847 | \fn bool Q3PtrListIterator::atLast() const
|
|---|
| 848 |
|
|---|
| 849 | Returns TRUE if the current iterator item is the last list item;
|
|---|
| 850 | otherwise returns FALSE.
|
|---|
| 851 |
|
|---|
| 852 | \sa toLast(), atFirst()
|
|---|
| 853 | */
|
|---|
| 854 |
|
|---|
| 855 | /*!
|
|---|
| 856 | \fn type *Q3PtrListIterator::toFirst()
|
|---|
| 857 |
|
|---|
| 858 | Sets the current iterator item to point to the first list item and
|
|---|
| 859 | returns a pointer to the item. Sets the current item to 0 and
|
|---|
| 860 | returns 0 if the list is empty.
|
|---|
| 861 |
|
|---|
| 862 | \sa toLast(), atFirst()
|
|---|
| 863 | */
|
|---|
| 864 |
|
|---|
| 865 | /*!
|
|---|
| 866 | \fn type *Q3PtrListIterator::toLast()
|
|---|
| 867 |
|
|---|
| 868 | Sets the current iterator item to point to the last list item and
|
|---|
| 869 | returns a pointer to the item. Sets the current item to 0 and
|
|---|
| 870 | returns 0 if the list is empty.
|
|---|
| 871 |
|
|---|
| 872 | \sa toFirst(), atLast()
|
|---|
| 873 | */
|
|---|
| 874 |
|
|---|
| 875 | /*!
|
|---|
| 876 | \fn Q3PtrListIterator::operator type *() const
|
|---|
| 877 |
|
|---|
| 878 | Cast operator. Returns a pointer to the current iterator item.
|
|---|
| 879 | Same as current().
|
|---|
| 880 | */
|
|---|
| 881 |
|
|---|
| 882 | /*!
|
|---|
| 883 | \fn type *Q3PtrListIterator::operator*()
|
|---|
| 884 |
|
|---|
| 885 | Asterisk operator. Returns a pointer to the current iterator item.
|
|---|
| 886 | Same as current().
|
|---|
| 887 | */
|
|---|
| 888 |
|
|---|
| 889 | /*!
|
|---|
| 890 | \fn type *Q3PtrListIterator::current() const
|
|---|
| 891 |
|
|---|
| 892 | Returns a pointer to the current iterator item. If the iterator is
|
|---|
| 893 | positioned before the first item in the list or after the last
|
|---|
| 894 | item in the list, 0 is returned.
|
|---|
| 895 | */
|
|---|
| 896 |
|
|---|
| 897 | /*!
|
|---|
| 898 | \fn type *Q3PtrListIterator::operator()()
|
|---|
| 899 |
|
|---|
| 900 | Makes the succeeding item current and returns the original current
|
|---|
| 901 | item.
|
|---|
| 902 |
|
|---|
| 903 | If the current iterator item was the last item in the list or if
|
|---|
| 904 | it was 0, 0 is returned.
|
|---|
| 905 | */
|
|---|
| 906 |
|
|---|
| 907 | /*!
|
|---|
| 908 | \fn type *Q3PtrListIterator::operator++()
|
|---|
| 909 |
|
|---|
| 910 | Prefix ++ makes the succeeding item current and returns the new
|
|---|
| 911 | current item.
|
|---|
| 912 |
|
|---|
| 913 | If the current iterator item was the last item in the list or if
|
|---|
| 914 | it was 0, 0 is returned.
|
|---|
| 915 | */
|
|---|
| 916 |
|
|---|
| 917 | /*!
|
|---|
| 918 | \fn type *Q3PtrListIterator::operator+=( uint jump )
|
|---|
| 919 |
|
|---|
| 920 | Sets the current item to the item \a jump positions after the
|
|---|
| 921 | current item and returns a pointer to that item.
|
|---|
| 922 |
|
|---|
| 923 | If that item is beyond the last item or if the list is empty, it
|
|---|
| 924 | sets the current item to 0 and returns 0
|
|---|
| 925 | */
|
|---|
| 926 |
|
|---|
| 927 | /*!
|
|---|
| 928 | \fn type *Q3PtrListIterator::operator--()
|
|---|
| 929 |
|
|---|
| 930 | Prefix - makes the preceding item current and returns the new
|
|---|
| 931 | current item.
|
|---|
| 932 |
|
|---|
| 933 | If the current iterator item was the first item in the list or if
|
|---|
| 934 | it was 0, 0 is returned.
|
|---|
| 935 | */
|
|---|
| 936 |
|
|---|
| 937 | /*!
|
|---|
| 938 | \fn type *Q3PtrListIterator::operator-=( uint jump )
|
|---|
| 939 |
|
|---|
| 940 | Returns the item \a jump positions before the current item or 0
|
|---|
| 941 | if it is beyond the first item. Makes this the current item.
|
|---|
| 942 | */
|
|---|
| 943 |
|
|---|
| 944 | /*!
|
|---|
| 945 | \fn Q3PtrListIterator<type>& Q3PtrListIterator::operator=( const Q3PtrListIterator<type> &it )
|
|---|
| 946 |
|
|---|
| 947 | Assignment. Makes a copy of the iterator \a it and returns a
|
|---|
| 948 | reference to this iterator.
|
|---|
| 949 | */
|
|---|
| 950 |
|
|---|
| 951 | /*!
|
|---|
| 952 | \class Q3StrList
|
|---|
| 953 | \brief The Q3StrList class provides a doubly-linked list of char*.
|
|---|
| 954 | \compat
|
|---|
| 955 |
|
|---|
| 956 | If you want a string list of \l{QString}s use QStringList.
|
|---|
| 957 |
|
|---|
| 958 | This class is a Q3PtrList\<char\> instance (a list of char*).
|
|---|
| 959 |
|
|---|
| 960 | Q3StrList can make deep or shallow copies of the strings that are
|
|---|
| 961 | inserted.
|
|---|
| 962 |
|
|---|
| 963 | A deep copy means that memory is allocated for the string and then
|
|---|
| 964 | the string data is copied into that memory. A shallow copy is just
|
|---|
| 965 | a copy of the pointer value and not of the string data itself.
|
|---|
| 966 |
|
|---|
| 967 | The disadvantage of shallow copies is that because a pointer can
|
|---|
| 968 | be deleted only once, the program must put all strings in a
|
|---|
| 969 | central place and know when it is safe to delete them (i.e. when
|
|---|
| 970 | the strings are no longer referenced by other parts of the
|
|---|
| 971 | program). This can make the program more complex. The advantage of
|
|---|
| 972 | shallow copies is that they consume far less memory than deep
|
|---|
| 973 | copies. It is also much faster to copy a pointer (typically 4 or 8
|
|---|
| 974 | bytes) than to copy string data.
|
|---|
| 975 |
|
|---|
| 976 | A Q3StrList that operates on deep copies will, by default, turn on
|
|---|
| 977 | auto-deletion (see setAutoDelete()). Thus, by default Q3StrList
|
|---|
| 978 | will deallocate any string copies it allocates.
|
|---|
| 979 |
|
|---|
| 980 | The virtual compareItems() function is reimplemented and does a
|
|---|
| 981 | case-sensitive string comparison. The inSort() function will
|
|---|
| 982 | insert strings in sorted order. In general it is fastest to insert
|
|---|
| 983 | the strings as they come and sort() at the end; inSort() is useful
|
|---|
| 984 | when you just have to add a few extra strings to an already sorted
|
|---|
| 985 | list.
|
|---|
| 986 |
|
|---|
| 987 | The Q3StrListIterator class is an iterator for Q3StrList.
|
|---|
| 988 | */
|
|---|
| 989 |
|
|---|
| 990 | /*!
|
|---|
| 991 | \fn Q3StrList::operator QList<QByteArray>() const
|
|---|
| 992 |
|
|---|
| 993 | Automatically converts a Q3StrList into a QList<QByteArray>.
|
|---|
| 994 | */
|
|---|
| 995 |
|
|---|
| 996 | /*!
|
|---|
| 997 | \fn Q3StrList::Q3StrList( bool deepCopies )
|
|---|
| 998 |
|
|---|
| 999 | Constructs an empty list of strings. Will make deep copies of all
|
|---|
| 1000 | inserted strings if \a deepCopies is TRUE, or use shallow copies
|
|---|
| 1001 | if \a deepCopies is FALSE.
|
|---|
| 1002 | */
|
|---|
| 1003 |
|
|---|
| 1004 | /*!
|
|---|
| 1005 | \fn Q3StrList::Q3StrList(const Q3StrList &list)
|
|---|
| 1006 | \fn Q3StrList::Q3StrList(const QList<QByteArray> &list)
|
|---|
| 1007 |
|
|---|
| 1008 | Constructs a copy of \a list.
|
|---|
| 1009 | */
|
|---|
| 1010 |
|
|---|
| 1011 | /*!
|
|---|
| 1012 | \fn Q3StrList::~Q3StrList()
|
|---|
| 1013 |
|
|---|
| 1014 | Destroys the list. All strings are removed.
|
|---|
| 1015 | */
|
|---|
| 1016 |
|
|---|
| 1017 | /*!
|
|---|
| 1018 | \fn Q3StrList& Q3StrList::operator=(const Q3StrList& list)
|
|---|
| 1019 | \fn Q3StrList &Q3StrList::operator=(const QList<QByteArray> &list)
|
|---|
| 1020 |
|
|---|
| 1021 | Assigns \a list to this list and returns a reference to this list.
|
|---|
| 1022 | */
|
|---|
| 1023 |
|
|---|
| 1024 | /*!
|
|---|
| 1025 | \class Q3StrIList
|
|---|
| 1026 | \brief The Q3StrIList class provides a doubly-linked list of char*
|
|---|
| 1027 | with case-insensitive comparison.
|
|---|
| 1028 | \compat
|
|---|
| 1029 |
|
|---|
| 1030 | This class is a Q3PtrList\<char\> instance (a list of char*).
|
|---|
| 1031 |
|
|---|
| 1032 | Q3StrIList is identical to Q3StrList except that the virtual
|
|---|
| 1033 | compareItems() function is reimplemented to compare strings
|
|---|
| 1034 | case-insensitively. The inSort() function inserts strings in a
|
|---|
| 1035 | sorted order. In general it is fastest to insert the strings as
|
|---|
| 1036 | they come and sort() at the end; inSort() is useful when you just
|
|---|
| 1037 | have to add a few extra strings to an already sorted list.
|
|---|
| 1038 |
|
|---|
| 1039 | The Q3StrListIterator class works for Q3StrIList.
|
|---|
| 1040 |
|
|---|
| 1041 | \sa QStringList
|
|---|
| 1042 | */
|
|---|
| 1043 |
|
|---|
| 1044 | /*!
|
|---|
| 1045 | \fn Q3StrIList::Q3StrIList( bool deepCopies )
|
|---|
| 1046 |
|
|---|
| 1047 | Constructs a list of strings. Will make deep copies of all
|
|---|
| 1048 | inserted strings if \a deepCopies is TRUE, or use shallow copies
|
|---|
| 1049 | if \a deepCopies is FALSE.
|
|---|
| 1050 | */
|
|---|
| 1051 |
|
|---|
| 1052 | /*!
|
|---|
| 1053 | \fn Q3StrIList::~Q3StrIList()
|
|---|
| 1054 |
|
|---|
| 1055 | Destroys the list. All strings are removed.
|
|---|
| 1056 | */
|
|---|
| 1057 |
|
|---|
| 1058 | /*!
|
|---|
| 1059 | \fn int Q3PtrList::compareItems( Q3PtrCollection::Item item1,
|
|---|
| 1060 | Q3PtrCollection::Item item2 )
|
|---|
| 1061 |
|
|---|
| 1062 | This virtual function compares two list items.
|
|---|
| 1063 |
|
|---|
| 1064 | Returns:
|
|---|
| 1065 | \list
|
|---|
| 1066 | \i zero if \a item1 == \a item2
|
|---|
| 1067 | \i nonzero if \a item1 != \a item2
|
|---|
| 1068 | \endlist
|
|---|
| 1069 |
|
|---|
| 1070 | This function returns \e int rather than \e bool so that
|
|---|
| 1071 | reimplementations can return three values and use it to sort by:
|
|---|
| 1072 |
|
|---|
| 1073 | \list
|
|---|
| 1074 | \i 0 if \a item1 == \a item2
|
|---|
| 1075 | \i \> 0 (positive integer) if \a item1 \> \a item2
|
|---|
| 1076 | \i \< 0 (negative integer) if \a item1 \< \a item2
|
|---|
| 1077 | \endlist
|
|---|
| 1078 |
|
|---|
| 1079 | inSort() requires that compareItems() is implemented as described
|
|---|
| 1080 | here.
|
|---|
| 1081 |
|
|---|
| 1082 | This function should not modify the list because some const
|
|---|
| 1083 | functions call compareItems().
|
|---|
| 1084 |
|
|---|
| 1085 | The default implementation compares the pointers.
|
|---|
| 1086 | */
|
|---|
| 1087 |
|
|---|
| 1088 | /*!
|
|---|
| 1089 | \fn QDataStream& Q3PtrList::read( QDataStream& s,
|
|---|
| 1090 | Q3PtrCollection::Item& item )
|
|---|
| 1091 |
|
|---|
| 1092 | Reads a list item from the stream \a s and returns a reference to
|
|---|
| 1093 | the stream.
|
|---|
| 1094 |
|
|---|
| 1095 | The default implementation sets \a item to 0.
|
|---|
| 1096 |
|
|---|
| 1097 | \sa write()
|
|---|
| 1098 | */
|
|---|
| 1099 |
|
|---|
| 1100 | /*!
|
|---|
| 1101 | \fn QDataStream& Q3PtrList::write( QDataStream& s,
|
|---|
| 1102 | Q3PtrCollection::Item item ) const
|
|---|
| 1103 |
|
|---|
| 1104 | Writes a list item, \a item to the stream \a s and returns a
|
|---|
| 1105 | reference to the stream.
|
|---|
| 1106 |
|
|---|
| 1107 | The default implementation does nothing.
|
|---|
| 1108 |
|
|---|
| 1109 | \sa read()
|
|---|
| 1110 | */
|
|---|
| 1111 |
|
|---|
| 1112 | /*! \fn iterator Q3PtrList::begin()
|
|---|
| 1113 | \internal
|
|---|
| 1114 | */
|
|---|
| 1115 | /*! \fn const_iterator Q3PtrList::begin() const
|
|---|
| 1116 | \internal
|
|---|
| 1117 | */
|
|---|
| 1118 | /*! \fn iterator Q3PtrList::end()
|
|---|
| 1119 | \internal
|
|---|
| 1120 | */
|
|---|
| 1121 | /*! \fn const_iterator Q3PtrList::end() const
|
|---|
| 1122 | \internal
|
|---|
| 1123 | */
|
|---|
| 1124 |
|
|---|
| 1125 | /*!
|
|---|
| 1126 | \class Q3StrListIterator
|
|---|
| 1127 | \brief The Q3StrListIterator class is an iterator for the Q3StrList
|
|---|
| 1128 | and Q3StrIList classes.
|
|---|
| 1129 | \compat
|
|---|
| 1130 |
|
|---|
| 1131 | This class is a Q3PtrListIterator\<char\> instance. It can traverse
|
|---|
| 1132 | the strings in the Q3StrList and Q3StrIList classes.
|
|---|
| 1133 | */
|
|---|
| 1134 |
|
|---|
| 1135 |
|
|---|
| 1136 | /*
|
|---|
| 1137 | \class Q3PtrListAutoDelete
|
|---|
| 1138 | \brief The Q3PtrListAutoDelete class is a template class that provides a list that auto-deletes its data.
|
|---|
| 1139 | \compat
|
|---|
| 1140 |
|
|---|
| 1141 | A Q3PtrListAutoDelete is identical to a Q3PtrList with
|
|---|
| 1142 | setAutoDelete(TRUE).
|
|---|
| 1143 | */
|
|---|