Add QIntrusiveList::contains() function
authorKent Hansen <kent.hansen@nokia.com>
Wed, 3 Aug 2011 13:05:25 +0000 (15:05 +0200)
committerQt by Nokia <qt-info@nokia.com>
Thu, 4 Aug 2011 11:01:59 +0000 (13:01 +0200)
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>

src/declarative/qml/qintrusivelist.cpp
src/declarative/qml/qintrusivelist_p.h

index a94f515..dabb893 100644 (file)
@@ -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.
index c1ea80a..717b11c 100644 (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:
@@ -202,6 +203,18 @@ void QIntrusiveList<N, member>::remove(N *n)
 }
 
 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 
 { 
     return __first?nodeToN(__first):0;