Add QIntrusiveList::contains() function

QIntrusiveList is nice, but it needs a contains() function.

Change-Id: I17adf63db080ffd39acac18cd8ecb23e48d76ed6
Reviewed-on: http://codereview.qt.nokia.com/2569
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
This commit is contained in:
Kent Hansen 2011-08-03 15:05:25 +02:00 committed by Qt by Nokia
parent 67238e2556
commit 5a594e5bfd
2 changed files with 19 additions and 0 deletions

View File

@ -112,6 +112,12 @@ removed and inserted at the head of this list.
Remove \a object from the list. \a object must not be null.
*/
/*!
\fn bool QIntrusiveList::contains(N *object) const
Returns true if the list contains \a object; otherwise returns false.
*/
/*!
\fn N *QIntrusiveList::first() const

View File

@ -68,6 +68,7 @@ public:
inline bool isEmpty() const;
inline void insert(N *n);
inline void remove(N *n);
inline bool contains(N *) const;
class iterator {
public:
@ -201,6 +202,18 @@ void QIntrusiveList<N, member>::remove(N *n)
nnode->remove();
}
template<class N, QIntrusiveListNode N::*member>
bool QIntrusiveList<N, member>::contains(N *n) const
{
QIntrusiveListNode *nnode = __first;
while (nnode) {
if (nodeToN(nnode) == n)
return true;
nnode = nnode->_next;
}
return false;
}
template<class N, QIntrusiveListNode N::*member>
N *QIntrusiveList<N, member>::first() const
{