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

Side by Side Diff: cc/scoped_ptr_vector.h

Issue 10979010: Remove WTF HashMap and PassOwnPtr dependencies for CCRenderPass (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/scoped_ptr_hash_map.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CC_OWN_PTR_VECTOR_H_ 5 #ifndef CC_SCOPED_PTR_VECTOR_H_
6 #define CC_OWN_PTR_VECTOR_H_ 6 #define CC_SCOPED_PTR_VECTOR_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
9 #include "base/stl_util.h" 10 #include "base/stl_util.h"
10 #include <wtf/PassOwnPtr.h>
11 #include <wtf/OwnPtr.h>
12 11
13 namespace cc { 12 namespace cc {
14 13
15 // This type acts like a Vector<OwnPtr> but based on top of std::vector. The 14 // This type acts like a vector<scoped_ptr> based on top of std::vector. The
16 // OwnPtrVector has ownership of all elements in the vector. 15 // ScopedPtrVector has ownership of all elements in the vector.
17 template <typename T> 16 template <typename T>
18 class OwnPtrVector { 17 class ScopedPtrVector {
19 public: 18 public:
20 typedef typename std::vector<T*>::iterator iterator; 19 typedef typename std::vector<T*>::iterator iterator;
21 typedef typename std::vector<T*>::const_iterator const_iterator; 20 typedef typename std::vector<T*>::const_iterator const_iterator;
22 typedef typename std::vector<T*>::reverse_iterator reverse_iterator; 21 typedef typename std::vector<T*>::reverse_iterator reverse_iterator;
23 typedef typename std::vector<T*>::const_reverse_iterator 22 typedef typename std::vector<T*>::const_reverse_iterator
24 const_reverse_iterator; 23 const_reverse_iterator;
25 24
26 OwnPtrVector() {} 25 ScopedPtrVector() {}
27 26
28 ~OwnPtrVector() { clear(); } 27 ~ScopedPtrVector() { clear(); }
29 28
30 size_t size() const { 29 size_t size() const {
31 return data_.size(); 30 return data_.size();
32 } 31 }
33 32
34 T* Peek(size_t index) const { 33 T* Peek(size_t index) const {
35 ASSERT(index < size()); 34 ASSERT(index < size());
36 return data_[index]; 35 return data_[index];
37 } 36 }
38 37
39 T* operator[](size_t index) const { 38 T* operator[](size_t index) const {
40 return Peek(index); 39 return Peek(index);
41 } 40 }
42 41
43 T* first() const { 42 T* first() const {
44 ASSERT(!isEmpty()); 43 ASSERT(!isEmpty());
45 return Peek(0); 44 return Peek(0);
46 } 45 }
47 46
48 T* last() const { 47 T* last() const {
49 ASSERT(!isEmpty()); 48 ASSERT(!isEmpty());
50 return Peek(size() - 1); 49 return Peek(size() - 1);
51 } 50 }
52 51
53 bool isEmpty() const { 52 bool isEmpty() const {
54 return size() == 0; 53 return size() == 0;
55 } 54 }
56 55
57 PassOwnPtr<T> take(size_t index) { 56 scoped_ptr<T> take(size_t index) {
58 ASSERT(index < size()); 57 ASSERT(index < size());
59 OwnPtr<T> ret = adoptPtr(data_[index]); 58 scoped_ptr<T> ret(data_[index]);
60 data_[index] = NULL; 59 data_[index] = NULL;
61 return ret.release(); 60 return ret.Pass();
62 } 61 }
63 62
64 void remove(size_t index) { 63 void remove(size_t index) {
65 ASSERT(index < size()); 64 ASSERT(index < size());
66 delete data_[index]; 65 delete data_[index];
67 data_.erase(data_.begin() + index); 66 data_.erase(data_.begin() + index);
68 } 67 }
69 68
70 void clear() { 69 void clear() {
71 STLDeleteElements(&data_); 70 STLDeleteElements(&data_);
72 } 71 }
73 72
74 void append(PassOwnPtr<T> item) { 73 void append(scoped_ptr<T> item) {
75 data_.push_back(item.leakPtr()); 74 data_.push_back(item.release());
76 } 75 }
77 76
78 void insert(size_t index, PassOwnPtr<T> item) { 77 void insert(size_t index, scoped_ptr<T> item) {
79 ASSERT(index < size()); 78 ASSERT(index < size());
80 data_.insert(data_.begin() + index, item.leakPtr()); 79 data_.insert(data_.begin() + index, item.release());
81 } 80 }
82 81
83 iterator begin() { return data_.begin(); } 82 iterator begin() { return data_.begin(); }
84 const_iterator begin() const { return data_.begin(); } 83 const_iterator begin() const { return data_.begin(); }
85 iterator end() { return data_.end(); } 84 iterator end() { return data_.end(); }
86 const_iterator end() const { return data_.end(); } 85 const_iterator end() const { return data_.end(); }
87 86
88 reverse_iterator rbegin() { return data_.rbegin(); } 87 reverse_iterator rbegin() { return data_.rbegin(); }
89 const_reverse_iterator rbegin() const { return data_.rbegin(); } 88 const_reverse_iterator rbegin() const { return data_.rbegin(); }
90 reverse_iterator rend() { return data_.rend(); } 89 reverse_iterator rend() { return data_.rend(); }
91 const_reverse_iterator rend() const { return data_.rend(); } 90 const_reverse_iterator rend() const { return data_.rend(); }
92 91
93 private: 92 private:
94 std::vector<T*> data_; 93 std::vector<T*> data_;
95 94
96 DISALLOW_COPY_AND_ASSIGN(OwnPtrVector); 95 DISALLOW_COPY_AND_ASSIGN(ScopedPtrVector);
97 }; 96 };
98 97
99 } // namespace cc 98 } // namespace cc
100 99
101 #endif // CC_OWN_PTR_VECTOR_H_ 100 #endif // CC_SCOPED_PTR_VECTOR_H_
OLDNEW
« no previous file with comments | « cc/scoped_ptr_hash_map.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698