From: Kent Hansen Date: Wed, 3 Aug 2011 13:05:25 +0000 (+0200) Subject: Add QIntrusiveList::contains() function X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=5a594e5bfd2f000204bd4c883719e0069ad3a772;p=konrad%2Fqtdeclarative.git 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 Reviewed-by: Aaron Kennedy --- diff --git a/src/declarative/qml/qintrusivelist.cpp b/src/declarative/qml/qintrusivelist.cpp index a94f515..dabb893 100644 --- a/src/declarative/qml/qintrusivelist.cpp +++ b/src/declarative/qml/qintrusivelist.cpp @@ -113,6 +113,12 @@ 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 Returns the first entry in this list, or null if the list is empty. diff --git a/src/declarative/qml/qintrusivelist_p.h b/src/declarative/qml/qintrusivelist_p.h index c1ea80a..717b11c 100644 --- a/src/declarative/qml/qintrusivelist_p.h +++ b/src/declarative/qml/qintrusivelist_p.h @@ -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: @@ -202,6 +203,18 @@ void QIntrusiveList::remove(N *n) } template +bool QIntrusiveList::contains(N *n) const +{ + QIntrusiveListNode *nnode = __first; + while (nnode) { + if (nodeToN(nnode) == n) + return true; + nnode = nnode->_next; + } + return false; +} + +template N *QIntrusiveList::first() const { return __first?nodeToN(__first):0;