Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1239)

Unified Diff: Source/wtf/OwnPtrList.h

Issue 705003002: Change the return type of WTF::bind() to |OwnPtr<Function>| (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« Source/wtf/MainThread.h ('K') | « Source/wtf/MainThread.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/OwnPtrList.h
diff --git a/Source/wtf/OwnPtrList.h b/Source/wtf/OwnPtrList.h
new file mode 100644
index 0000000000000000000000000000000000000000..b910258f0795da0f01cb2d0f894972f5cd60b4f2
--- /dev/null
+++ b/Source/wtf/OwnPtrList.h
@@ -0,0 +1,73 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WTF_OwnPtrList_h
+#define WTF_OwnPtrList_h
+
+#include "wtf/OwnPtr.h"
+#include "wtf/PassOwnPtr.h"
+#include "wtf/Vector.h"
+
+namespace WTF {
+
+// OwnPtrList<T> is a list container for OwnPtr<T>.
+// Vector<OwnPtr<T>> cannot be used because we cannot copy OwnPtr<T>.
+template<typename T>
+class OwnPtrList {
+ WTF_MAKE_NONCOPYABLE(OwnPtrList);
+public:
+ OwnPtrList() { }
+ void append(PassOwnPtr<T> ptr)
+ {
+ OwnPtr<OwnPtrListNode<T>> node = adoptPtr(new OwnPtrListNode<T>(ptr, m_head.release()));
+ m_head = node.release();
+ }
+
+ // call ptr->f() for each OwnPtr in the list, in the order of |append|.
+ void applyEach(void(T::*f)()) const
+ {
+ Vector<T*> v;
+ for (OwnPtrListNode<T>* p = m_head.get(); p; p = p->m_next.get()) {
+ v.append(p->m_ptr.get());
+ }
+ for (typename Vector<T*>::reverse_iterator it = v.rbegin(), itEnd = v.rend(); it != itEnd; ++it)
+ ((*it)->*f)();
+ }
+
+ void applyEach(void(T::*f)() const) const
+ {
+ Vector<T*> v;
+ for (OwnPtrListNode<T>* p = m_head.get(); p; p = p->m_next.get()) {
+ v.append(p->m_ptr.get());
+ }
+ for (typename Vector<T*>::const_reverse_iterator it = v.rbegin(), itEnd = v.rend(); it != itEnd; ++it)
+ ((*it)->*f)();
+ }
+
+private:
+ template<typename U>
+ class OwnPtrListNode {
+ WTF_MAKE_NONCOPYABLE(OwnPtrListNode);
+ public:
+ OwnPtrListNode(PassOwnPtr<U> ptr, PassOwnPtr<OwnPtrListNode<U>> next)
+ : m_ptr(ptr)
+ , m_next(next)
+ {
+ }
+ private:
+ OwnPtr<U> m_ptr;
+ OwnPtr<OwnPtrListNode<U>> m_next;
+ friend class OwnPtrList<U>;
+ };
+
+ // The linked list starting from |m_head| stores the elements in the
+ // reverse order of |append|.
+ OwnPtr<OwnPtrListNode<T>> m_head;
+};
+
+} // namespace WTF
+
+using WTF::OwnPtrList;
+
+#endif // WTF_OwnPtrList_h
« Source/wtf/MainThread.h ('K') | « Source/wtf/MainThread.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698