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

Side by Side Diff: cc/own_ptr_vector.h

Issue 11048044: cc: Switch to Chromium DCHECKs and LOGs (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase 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
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_OWN_PTR_VECTOR_H_
6 #define CC_OWN_PTR_VECTOR_H_ 6 #define CC_OWN_PTR_VECTOR_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "cc/dcheck.h"
10 #include <wtf/PassOwnPtr.h> 11 #include <wtf/PassOwnPtr.h>
11 #include <wtf/OwnPtr.h> 12 #include <wtf/OwnPtr.h>
12 13
13 namespace cc { 14 namespace cc {
14 15
15 // This type acts like a Vector<OwnPtr> but based on top of std::vector. The 16 // This type acts like a Vector<OwnPtr> but based on top of std::vector. The
16 // OwnPtrVector has ownership of all elements in the vector. 17 // OwnPtrVector has ownership of all elements in the vector.
17 template <typename T> 18 template <typename T>
18 class OwnPtrVector { 19 class OwnPtrVector {
19 public: 20 public:
20 typedef typename std::vector<T*>::iterator iterator; 21 typedef typename std::vector<T*>::iterator iterator;
21 typedef typename std::vector<T*>::const_iterator const_iterator; 22 typedef typename std::vector<T*>::const_iterator const_iterator;
22 typedef typename std::vector<T*>::reverse_iterator reverse_iterator; 23 typedef typename std::vector<T*>::reverse_iterator reverse_iterator;
23 typedef typename std::vector<T*>::const_reverse_iterator 24 typedef typename std::vector<T*>::const_reverse_iterator
24 const_reverse_iterator; 25 const_reverse_iterator;
25 26
26 OwnPtrVector() {} 27 OwnPtrVector() {}
27 28
28 ~OwnPtrVector() { clear(); } 29 ~OwnPtrVector() { clear(); }
29 30
30 size_t size() const { 31 size_t size() const {
31 return data_.size(); 32 return data_.size();
32 } 33 }
33 34
34 T* Peek(size_t index) const { 35 T* Peek(size_t index) const {
35 ASSERT(index < size()); 36 CC_DCHECK(index < size());
36 return data_[index]; 37 return data_[index];
37 } 38 }
38 39
39 T* operator[](size_t index) const { 40 T* operator[](size_t index) const {
40 return Peek(index); 41 return Peek(index);
41 } 42 }
42 43
43 T* first() const { 44 T* first() const {
44 ASSERT(!isEmpty()); 45 CC_DCHECK(!isEmpty());
45 return Peek(0); 46 return Peek(0);
46 } 47 }
47 48
48 T* last() const { 49 T* last() const {
49 ASSERT(!isEmpty()); 50 CC_DCHECK(!isEmpty());
50 return Peek(size() - 1); 51 return Peek(size() - 1);
51 } 52 }
52 53
53 bool isEmpty() const { 54 bool isEmpty() const {
54 return size() == 0; 55 return size() == 0;
55 } 56 }
56 57
57 PassOwnPtr<T> take(size_t index) { 58 PassOwnPtr<T> take(size_t index) {
58 ASSERT(index < size()); 59 CC_DCHECK(index < size());
59 OwnPtr<T> ret = adoptPtr(data_[index]); 60 OwnPtr<T> ret = adoptPtr(data_[index]);
60 data_[index] = NULL; 61 data_[index] = NULL;
61 return ret.release(); 62 return ret.release();
62 } 63 }
63 64
64 void remove(size_t index) { 65 void remove(size_t index) {
65 ASSERT(index < size()); 66 CC_DCHECK(index < size());
66 delete data_[index]; 67 delete data_[index];
67 data_.erase(data_.begin() + index); 68 data_.erase(data_.begin() + index);
68 } 69 }
69 70
70 void clear() { 71 void clear() {
71 STLDeleteElements(&data_); 72 STLDeleteElements(&data_);
72 } 73 }
73 74
74 void append(PassOwnPtr<T> item) { 75 void append(PassOwnPtr<T> item) {
75 data_.push_back(item.leakPtr()); 76 data_.push_back(item.leakPtr());
76 } 77 }
77 78
78 void insert(size_t index, PassOwnPtr<T> item) { 79 void insert(size_t index, PassOwnPtr<T> item) {
79 ASSERT(index < size()); 80 CC_DCHECK(index < size());
80 data_.insert(data_.begin() + index, item.leakPtr()); 81 data_.insert(data_.begin() + index, item.leakPtr());
81 } 82 }
82 83
83 iterator begin() { return data_.begin(); } 84 iterator begin() { return data_.begin(); }
84 const_iterator begin() const { return data_.begin(); } 85 const_iterator begin() const { return data_.begin(); }
85 iterator end() { return data_.end(); } 86 iterator end() { return data_.end(); }
86 const_iterator end() const { return data_.end(); } 87 const_iterator end() const { return data_.end(); }
87 88
88 reverse_iterator rbegin() { return data_.rbegin(); } 89 reverse_iterator rbegin() { return data_.rbegin(); }
89 const_reverse_iterator rbegin() const { return data_.rbegin(); } 90 const_reverse_iterator rbegin() const { return data_.rbegin(); }
90 reverse_iterator rend() { return data_.rend(); } 91 reverse_iterator rend() { return data_.rend(); }
91 const_reverse_iterator rend() const { return data_.rend(); } 92 const_reverse_iterator rend() const { return data_.rend(); }
92 93
93 private: 94 private:
94 std::vector<T*> data_; 95 std::vector<T*> data_;
95 96
96 DISALLOW_COPY_AND_ASSIGN(OwnPtrVector); 97 DISALLOW_COPY_AND_ASSIGN(OwnPtrVector);
97 }; 98 };
98 99
99 } // namespace cc 100 } // namespace cc
100 101
101 #endif // CC_OWN_PTR_VECTOR_H_ 102 #endif // CC_OWN_PTR_VECTOR_H_
OLDNEW
« no previous file with comments | « cc/occlusion_tracker_unittest.cc ('k') | cc/platform_color.h » ('j') | cc/yuv_video_draw_quad.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698