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

Side by Side Diff: cc/scoped_ptr_deque.h

Issue 11418108: cc: Make the ScopedPtrVector and ScopedPtrDeque containers act like STL vector and deque. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add DCHECK Created 8 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 unified diff | Download patch | Annotate | Revision Log
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_SCOPED_PTR_DEQUE_H_ 5 #ifndef CC_SCOPED_PTR_DEQUE_H_
6 #define CC_SCOPED_PTR_DEQUE_H_ 6 #define CC_SCOPED_PTR_DEQUE_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 13 matching lines...) Expand all
24 typedef typename std::deque<T*>::const_reverse_iterator const_reverse_iterator ; 24 typedef typename std::deque<T*>::const_reverse_iterator const_reverse_iterator ;
25 25
26 ScopedPtrDeque() {} 26 ScopedPtrDeque() {}
27 27
28 ~ScopedPtrDeque() { clear(); } 28 ~ScopedPtrDeque() { clear(); }
29 29
30 size_t size() const { 30 size_t size() const {
31 return data_.size(); 31 return data_.size();
32 } 32 }
33 33
34 T* Peek(size_t index) const { 34 T* at(size_t index) const {
35 DCHECK(index < size()); 35 DCHECK(index < size());
36 return data_[index]; 36 return data_[index];
37 } 37 }
38 38
39 T* operator[](size_t index) const { 39 T* operator[](size_t index) const {
40 return Peek(index); 40 return at(index);
41 } 41 }
42 42
43 T* first() const { 43 T* front() const {
44 DCHECK(!isEmpty()); 44 DCHECK(!empty());
45 return Peek(0); 45 return at(0);
46 } 46 }
47 47
48 T* last() const { 48 T* back() const {
49 DCHECK(!isEmpty()); 49 DCHECK(!empty());
50 return Peek(size() - 1); 50 return at(size() - 1);
51 } 51 }
52 52
53 bool isEmpty() const { 53 bool empty() const {
54 return size() == 0; 54 return size() == 0;
55 } 55 }
56 56
57 scoped_ptr<T> takeFirst() { 57 scoped_ptr<T> take_front() {
enne (OOO) 2012/11/21 04:12:57 I know take is convenient, but it's also inconsist
danakj 2012/11/21 04:23:21 Oh, take_front is removing the element so it could
58 scoped_ptr<T> ret(first()); 58 scoped_ptr<T> ret(front());
59 data_.pop_front(); 59 data_.pop_front();
60 return ret.Pass(); 60 return ret.Pass();
61 } 61 }
62 62
63 scoped_ptr<T> takeLast() { 63 scoped_ptr<T> take_back() {
64 scoped_ptr<T> ret(last()); 64 scoped_ptr<T> ret(back());
65 data_.pop_back(); 65 data_.pop_back();
66 return ret.Pass(); 66 return ret.Pass();
67 } 67 }
68 68
69 void clear() { 69 void clear() {
70 STLDeleteElements(&data_); 70 STLDeleteElements(&data_);
71 } 71 }
72 72
73 void append(scoped_ptr<T> item) { 73 void push_front(scoped_ptr<T> item) {
74 data_.push_front(item.release());
75 }
76
77 void push_back(scoped_ptr<T> item) {
74 data_.push_back(item.release()); 78 data_.push_back(item.release());
75 } 79 }
76 80
77 void insert(size_t index, scoped_ptr<T> item) { 81 void insert(iterator position, scoped_ptr<T> item) {
78 DCHECK(index < size()); 82 data_.insert(position, item.release());
79 data_.insert(data_.begin() + index, item.release());
80 } 83 }
81 84
82 iterator begin() { return data_.begin(); } 85 iterator begin() { return data_.begin(); }
83 const_iterator begin() const { return data_.begin(); } 86 const_iterator begin() const { return data_.begin(); }
84 iterator end() { return data_.end(); } 87 iterator end() { return data_.end(); }
85 const_iterator end() const { return data_.end(); } 88 const_iterator end() const { return data_.end(); }
86 89
87 reverse_iterator rbegin() { return data_.rbegin(); } 90 reverse_iterator rbegin() { return data_.rbegin(); }
88 const_reverse_iterator rbegin() const { return data_.rbegin(); } 91 const_reverse_iterator rbegin() const { return data_.rbegin(); }
89 reverse_iterator rend() { return data_.rend(); } 92 reverse_iterator rend() { return data_.rend(); }
90 const_reverse_iterator rend() const { return data_.rend(); } 93 const_reverse_iterator rend() const { return data_.rend(); }
91 94
92 private: 95 private:
93 std::deque<T*> data_; 96 std::deque<T*> data_;
94 97
95 DISALLOW_COPY_AND_ASSIGN(ScopedPtrDeque); 98 DISALLOW_COPY_AND_ASSIGN(ScopedPtrDeque);
96 }; 99 };
97 100
98 } // namespace cc 101 } // namespace cc
99 102
100 #endif // CC_SCOPED_PTR_DEQUE_H_ 103 #endif // CC_SCOPED_PTR_DEQUE_H_
OLDNEW
« no previous file with comments | « cc/resource_provider_unittest.cc ('k') | cc/scoped_ptr_vector.h » ('j') | cc/scoped_ptr_vector.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698