Qt 4.8
|
The QLinkedList class is a template class that provides linked lists. More...
#include <qdatastream.h>
Classes | |
class | const_iterator |
The QLinkedList::const_iterator class provides an STL-style const iterator for QLinkedList. More... | |
class | iterator |
The QLinkedList::iterator class provides an STL-style non-const iterator for QLinkedList. More... | |
Public Types | |
typedef const value_type * | const_pointer |
Typedef for const T *. More... | |
typedef const value_type & | const_reference |
Typedef for const T &. More... | |
typedef const_iterator | ConstIterator |
Qt-style synonym for QLinkedList::const_iterator. More... | |
typedef qptrdiff | difference_type |
Typedef for ptrdiff_t. More... | |
typedef iterator | Iterator |
Qt-style synonym for QLinkedList::iterator. More... | |
typedef value_type * | pointer |
Typedef for T *. More... | |
typedef value_type & | reference |
Typedef for T &. More... | |
typedef int | size_type |
Typedef for int. More... | |
typedef T | value_type |
Typedef for T. More... | |
Public Functions | |
void | append (const T &) |
Inserts value at the end of the list. More... | |
T & | back () |
This function is provided for STL compatibility. More... | |
const T & | back () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
iterator | begin () |
Returns an STL-style iterator pointing to the first item in the list. More... | |
const_iterator | begin () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
void | clear () |
Removes all the items in the list. More... | |
const_iterator | constBegin () const |
Returns a const STL-style iterator pointing to the first item in the list. More... | |
const_iterator | constEnd () const |
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list. More... | |
bool | contains (const T &t) const |
Returns true if the list contains an occurrence of value; otherwise returns false. More... | |
int | count (const T &t) const |
Returns the number of occurrences of value in the list. More... | |
int | count () const |
Same as size(). More... | |
void | detach () |
bool | empty () const |
This function is provided for STL compatibility. More... | |
iterator | end () |
Returns an STL-style iterator pointing to the imaginary item after the last item in the list. More... | |
const_iterator | end () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
bool | endsWith (const T &t) const |
Returns true if the list is not empty and its last item is equal to value; otherwise returns false. More... | |
iterator | erase (iterator pos) |
Removes the item pointed to by the iterator pos from the list, and returns an iterator to the next item in the list (which may be end()). More... | |
iterator | erase (iterator first, iterator last) |
Removes all the items from begin up to (but not including) end. More... | |
T & | first () |
Returns a reference to the first item in the list. More... | |
const T & | first () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
T & | front () |
This function is provided for STL compatibility. More... | |
const T & | front () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
iterator | insert (iterator before, const T &t) |
Inserts value in front of the item pointed to by the iterator before. More... | |
bool | isDetached () const |
bool | isEmpty () const |
Returns true if the list contains no items; otherwise returns false. More... | |
bool | isSharedWith (const QLinkedList< T > &other) const |
T & | last () |
Returns a reference to the last item in the list. More... | |
const T & | last () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
bool | operator!= (const QLinkedList< T > &l) const |
Returns true if other is not equal to this list; otherwise returns false. More... | |
QLinkedList< T > | operator+ (const QLinkedList< T > &l) const |
Returns a list that contains all the items in this list followed by all the items in the other list. More... | |
QLinkedList< T > & | operator+= (const QLinkedList< T > &l) |
Appends the items of the other list to this list and returns a reference to this list. More... | |
QLinkedList< T > & | operator+= (const T &t) |
Appends value to the list. More... | |
QLinkedList< T > & | operator<< (const QLinkedList< T > &l) |
Appends the items of the other list to this list and returns a reference to this list. More... | |
QLinkedList< T > & | operator<< (const T &t) |
Appends value to the list. More... | |
QLinkedList< T > & | operator= (const QLinkedList< T > &) |
Assigns other to this list and returns a reference to this list. More... | |
bool | operator== (const QLinkedList< T > &l) const |
Returns true if other is equal to this list; otherwise returns false. More... | |
void | pop_back () |
This function is provided for STL compatibility. More... | |
void | pop_front () |
This function is provided for STL compatibility. More... | |
void | prepend (const T &) |
Inserts value at the beginning of the list. More... | |
void | push_back (const T &t) |
This function is provided for STL compatibility. More... | |
void | push_front (const T &t) |
This function is provided for STL compatibility. More... | |
QLinkedList () | |
Constructs an empty list. More... | |
QLinkedList (const QLinkedList< T > &l) | |
Constructs a copy of other. More... | |
int | removeAll (const T &t) |
Removes all occurrences of value in the list. More... | |
void | removeFirst () |
Removes the first item in the list. More... | |
void | removeLast () |
Removes the last item in the list. More... | |
bool | removeOne (const T &t) |
Removes the first occurrences of value in the list. More... | |
void | setSharable (bool sharable) |
int | size () const |
Returns the number of items in the list. More... | |
bool | startsWith (const T &t) const |
Returns true if the list is not empty and its first item is equal to value; otherwise returns false. More... | |
void | swap (QLinkedList< T > &other) |
Swaps list other with this list. More... | |
T | takeFirst () |
Removes the first item in the list and returns it. More... | |
T | takeLast () |
Removes the last item in the list and returns it. More... | |
std::list< T > | toStdList () const |
Returns a std::list object with the data contained in this QLinkedList. More... | |
~QLinkedList () | |
Destroys the list. More... | |
Static Public Functions | |
static QLinkedList< T > | fromStdList (const std::list< T > &list) |
Returns a QLinkedList object with the data contained in list. More... | |
Private Types | |
typedef QLinkedListNode< T > | Node |
Private Functions | |
void | detach_helper () |
void | free (QLinkedListData *) |
Properties | |
union { | |
QLinkedListData * d | |
QLinkedListNode< T > * e | |
}; | |
Friends | |
class | const_iterator |
class | iterator |
Related Functions | |
(Note that these are not member functions.) | |
QDataStream & | operator<< (QDataStream &out, const QLinkedList< T > &list) |
Writes the linked list list to stream out. More... | |
QDataStream & | operator>> (QDataStream &in, QLinkedList< T > &list) |
Reads a linked list from stream in into list. More... | |
The QLinkedList class is a template class that provides linked lists.
QLinkedList<T> is one of Qt's generic container classes. It stores a list of values and provides iterator-based access as well as constant time insertions and removals.
QList<T>, QLinkedList<T>, and QVector<T> provide similar functionality. Here's an overview:
Here's an example of a QLinkedList that stores integers and a QLinkedList that stores QTime values:
QLinkedList stores a list of items. The default constructor creates an empty list. To insert items into the list, you can use operator<<():
If you want to get the first or last item in a linked list, use first() or last(). If you want to remove an item from either end of the list, use removeFirst() or removeLast(). If you want to remove all occurrences of a given value in the list, use removeAll().
A common requirement is to remove the first or last item in the list and do something with it. For this, QLinkedList provides takeFirst() and takeLast(). Here's a loop that removes the items from a list one at a time and calls delete
on them:
QLinkedList's value type must be an assignable data type. This covers most data types that are commonly used, but the compiler won't let you, for example, store a QWidget as a value; instead, store a QWidget *. A few functions have additional requirements; for example, contains() and removeAll() expect the value type to support operator==()
. These requirements are documented on a per-function basis.
If you want to insert, modify, or remove items in the middle of the list, you must use an iterator. QLinkedList provides both Java-style iterators (QLinkedListIterator and QMutableLinkedListIterator) and STL-style iterators (QLinkedList::const_iterator and QLinkedList::iterator). See the documentation for these classes for details.
Definition at line 63 of file qdatastream.h.
QLinkedList< T >::const_pointer |
Typedef for const T *.
Provided for STL compatibility.
Definition at line 218 of file qlinkedlist.h.
QLinkedList< T >::const_reference |
Typedef for const T &.
Provided for STL compatibility.
Definition at line 220 of file qlinkedlist.h.
QLinkedList< T >::ConstIterator |
Qt-style synonym for QLinkedList::const_iterator.
Definition at line 194 of file qlinkedlist.h.
QLinkedList< T >::difference_type |
Typedef for ptrdiff_t.
Provided for STL compatibility.
Definition at line 221 of file qlinkedlist.h.
QLinkedList< T >::Iterator |
Qt-style synonym for QLinkedList::iterator.
Definition at line 193 of file qlinkedlist.h.
|
private |
Definition at line 80 of file qlinkedlist.h.
QLinkedList< T >::pointer |
QLinkedList< T >::reference |
QLinkedList< T >::size_type |
QLinkedList< T >::value_type |
|
inline |
|
inline |
Constructs a copy of other.
This operation occurs in constant time, because QLinkedList is implicitly shared. This makes returning a QLinkedList from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and this takes linear time.
Definition at line 85 of file qlinkedlist.h.
|
inline |
Destroys the list.
References to the values in the list, and all iterators over this list, become invalid.
Definition at line 258 of file qlinkedlist.h.
void QLinkedList< T >::append | ( | const T & | value | ) |
Inserts value at the end of the list.
Example:
This is the same as list.insert(end(), value).
Definition at line 350 of file qlinkedlist.h.
Referenced by QSpanCollection::addSpan(), QScriptValueIteratorPrivate::ensureInitialized(), operator>>(), QSpanCollection::updateRemovedColumns(), and QSpanCollection::updateRemovedRows().
|
inline |
This function is provided for STL compatibility.
It is equivalent to last().
Definition at line 210 of file qlinkedlist.h.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 211 of file qlinkedlist.h.
|
inline |
Returns an STL-style iterator pointing to the first item in the list.
Definition at line 182 of file qlinkedlist.h.
Referenced by QScriptValueIteratorPrivate::ensureInitialized(), QGraphicsAnchorLayoutPrivate::getGraphParts(), QMeeGoLivePixmapData::QMeeGoLivePixmapData(), QSpanCollection::updateInsertedColumns(), QSpanCollection::updateInsertedRows(), QSpanCollection::updateRemovedColumns(), and QSpanCollection::updateRemovedRows().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 183 of file qlinkedlist.h.
void QLinkedList< T >::clear | ( | ) |
Removes all the items in the list.
Definition at line 311 of file qlinkedlist.h.
Referenced by QSpanCollection::clear(), operator>>(), and QScriptValueIteratorPrivate::~QScriptValueIteratorPrivate().
|
inline |
Returns a const STL-style iterator pointing to the first item in the list.
Definition at line 184 of file qlinkedlist.h.
|
inline |
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list.
Definition at line 187 of file qlinkedlist.h.
bool QLinkedList< T >::contains | ( | const T & | value | ) | const |
Returns true if the list contains an occurrence of value; otherwise returns false.
This function requires the value type to have an implementation of operator==()
.
Definition at line 425 of file qlinkedlist.h.
Referenced by QSpanCollection::updateRemovedColumns().
int QLinkedList< T >::count | ( | const T & | value | ) | const |
Returns the number of occurrences of value in the list.
This function requires the value type to have an implementation of operator==()
.
Definition at line 435 of file qlinkedlist.h.
|
inline |
|
inline |
Definition at line 97 of file qlinkedlist.h.
|
private |
Definition at line 267 of file qlinkedlist.h.
|
inline |
This function is provided for STL compatibility.
It is equivalent to isEmpty() and returns true if the list is empty.
Definition at line 214 of file qlinkedlist.h.
|
inline |
Returns an STL-style iterator pointing to the imaginary item after the last item in the list.
Definition at line 185 of file qlinkedlist.h.
Referenced by QGraphicsAnchorLayoutPrivate::getGraphParts(), QSpanCollection::updateInsertedColumns(), QSpanCollection::updateInsertedRows(), QSpanCollection::updateRemovedColumns(), and QSpanCollection::updateRemovedRows().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 186 of file qlinkedlist.h.
|
inline |
Returns true if the list is not empty and its last item is equal to value; otherwise returns false.
Definition at line 203 of file qlinkedlist.h.
QLinkedList< T >::iterator QLinkedList< T >::erase | ( | iterator | pos | ) |
Removes the item pointed to by the iterator pos from the list, and returns an iterator to the next item in the list (which may be end()).
Definition at line 470 of file qlinkedlist.h.
Referenced by QGraphicsAnchorLayoutPrivate::getGraphParts(), QLinkedList< JSC::Identifier >::insert(), QSpanCollection::updateRemovedColumns(), QSpanCollection::updateRemovedRows(), and QMeeGoLivePixmapData::~QMeeGoLivePixmapData().
QLinkedList::iterator QLinkedList< T >::erase | ( | iterator | begin, |
iterator | end | ||
) |
Removes all the items from begin up to (but not including) end.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Returns a reference to the first item in the list.
This function assumes that the list isn't empty.
Definition at line 196 of file qlinkedlist.h.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 197 of file qlinkedlist.h.
|
private |
Definition at line 296 of file qlinkedlist.h.
|
inlinestatic |
Returns a QLinkedList object with the data contained in list.
The order of the elements in the QLinkedList is the same as in list.
Example:
Definition at line 224 of file qlinkedlist.h.
|
inline |
This function is provided for STL compatibility.
It is equivalent to first().
Definition at line 208 of file qlinkedlist.h.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 209 of file qlinkedlist.h.
QLinkedList< T >::iterator QLinkedList< T >::insert | ( | iterator | before, |
const T & | value | ||
) |
Inserts value in front of the item pointed to by the iterator before.
Returns an iterator pointing at the inserted item.
Definition at line 447 of file qlinkedlist.h.
Referenced by QMeeGoLivePixmapData::QMeeGoLivePixmapData().
|
inline |
Definition at line 99 of file qlinkedlist.h.
|
inline |
Returns true if the list contains no items; otherwise returns false.
Definition at line 103 of file qlinkedlist.h.
Referenced by QGraphicsAnchorLayoutPrivate::getGraphParts(), QTableViewPrivate::hasSpans(), QSpanCollection::updateInsertedColumns(), QSpanCollection::updateInsertedRows(), QSpanCollection::updateRemovedColumns(), and QSpanCollection::updateRemovedRows().
|
inline |
Definition at line 101 of file qlinkedlist.h.
|
inline |
Returns a reference to the last item in the list.
This function assumes that the list isn't empty.
Definition at line 198 of file qlinkedlist.h.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 199 of file qlinkedlist.h.
|
inline |
Returns true if other is not equal to this list; otherwise returns false.
Two lists are considered equal if they contain the same values in the same order.
This function requires the value type to implement operator==()
.
Definition at line 94 of file qlinkedlist.h.
QLinkedList< T > QLinkedList< T >::operator+ | ( | const QLinkedList< T > & | other | ) | const |
Returns a list that contains all the items in this list followed by all the items in the other list.
Definition at line 511 of file qlinkedlist.h.
QLinkedList< T > & QLinkedList< T >::operator+= | ( | const QLinkedList< T > & | other | ) |
Appends the items of the other list to this list and returns a reference to this list.
Definition at line 486 of file qlinkedlist.h.
|
inline |
Appends value to the list.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 248 of file qlinkedlist.h.
|
inline |
Appends value to the list.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 249 of file qlinkedlist.h.
|
inline |
Appends the items of the other list to this list and returns a reference to this list.
Definition at line 250 of file qlinkedlist.h.
QLinkedList< T > & QLinkedList< T >::operator= | ( | const QLinkedList< T > & | other | ) |
Assigns other to this list and returns a reference to this list.
Definition at line 317 of file qlinkedlist.h.
bool QLinkedList< T >::operator== | ( | const QLinkedList< T > & | other | ) | const |
Returns true if other is equal to this list; otherwise returns false.
Two lists are considered equal if they contain the same values in the same order.
This function requires the value type to implement operator==()
.
Definition at line 332 of file qlinkedlist.h.
|
inline |
This function is provided for STL compatibility.
It is equivalent to removeLast().
Definition at line 213 of file qlinkedlist.h.
|
inline |
This function is provided for STL compatibility.
It is equivalent to removeFirst().
Definition at line 212 of file qlinkedlist.h.
void QLinkedList< T >::prepend | ( | const T & | value | ) |
Inserts value at the beginning of the list.
Example:
This is the same as list.insert(begin(), value).
Definition at line 362 of file qlinkedlist.h.
|
inline |
This function is provided for STL compatibility.
It is equivalent to append(value).
Definition at line 206 of file qlinkedlist.h.
|
inline |
This function is provided for STL compatibility.
It is equivalent to prepend(value).
Definition at line 207 of file qlinkedlist.h.
int QLinkedList< T >::removeAll | ( | const T & | value | ) |
Removes all occurrences of value in the list.
Example:
This function requires the value type to have an implementation of operator==()
.
Definition at line 374 of file qlinkedlist.h.
|
inline |
Removes the first item in the list.
This is the same as erase(begin()).
Definition at line 200 of file qlinkedlist.h.
|
inline |
Removes the last item in the list.
Definition at line 201 of file qlinkedlist.h.
bool QLinkedList< T >::removeOne | ( | const T & | value | ) |
Removes the first occurrences of value in the list.
Returns true on success; otherwise returns false.
Example:
This function requires the value type to have an implementation of operator==()
.
Definition at line 397 of file qlinkedlist.h.
Referenced by QSpanCollection::updateSpan().
|
inline |
Definition at line 100 of file qlinkedlist.h.
|
inline |
|
inline |
Returns true if the list is not empty and its first item is equal to value; otherwise returns false.
Definition at line 202 of file qlinkedlist.h.
|
inline |
Swaps list other with this list.
This operation is very fast and never fails.
Definition at line 92 of file qlinkedlist.h.
|
inline |
Removes the first item in the list and returns it.
If you don't use the return value, removeFirst() is more efficient.
Definition at line 409 of file qlinkedlist.h.
|
inline |
Removes the last item in the list and returns it.
If you don't use the return value, removeLast() is more efficient.
Definition at line 417 of file qlinkedlist.h.
|
inline |
Returns a std::list object with the data contained in this QLinkedList.
Example:
Definition at line 226 of file qlinkedlist.h.
|
friend |
Definition at line 179 of file qlinkedlist.h.
Definition at line 149 of file qlinkedlist.h.
|
related |
Writes the linked list list to stream out.
This function requires the value type to implement operator<<()
.
Definition at line 287 of file qdatastream.h.
|
related |
Reads a linked list from stream in into list.
This function requires the value type to implement operator>>()
.
Definition at line 270 of file qdatastream.h.
union { ... } |
QLinkedListData* QLinkedList< T >::d |
QLinkedListNode<T>* QLinkedList< T >::e |
Definition at line 81 of file qlinkedlist.h.
Referenced by QLinkedList< JSC::Identifier >::operator+=(), and QLinkedList< JSC::Identifier >::operator==().