aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2011-08-03 15:05:25 +0200
committerQt by Nokia <qt-info@nokia.com>2011-08-04 13:01:59 +0200
commit5a594e5bfd2f000204bd4c883719e0069ad3a772 (patch)
tree0869cc80a7f3556a6cd723cf01f3760b1339b857
parent67238e2556808758657e7566264e5fa9fe378562 (diff)
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>
-rw-r--r--src/declarative/qml/qintrusivelist.cpp6
-rw-r--r--src/declarative/qml/qintrusivelist_p.h13
2 files changed, 19 insertions, 0 deletions
diff --git a/src/declarative/qml/qintrusivelist.cpp b/src/declarative/qml/qintrusivelist.cpp
index a94f5152a3..dabb893e91 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 c1ea80a767..717b11c344 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<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;