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

Side by Side Diff: cc/scoped_ptr_deque.h

Issue 11192030: cc: Switch to Chromium DCHECKs LOGs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebaseonenne 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/scheduler_unittest.cc ('k') | cc/scoped_ptr_hash_map.h » ('j') | 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_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/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
10 #include "base/stl_util.h" 11 #include "base/stl_util.h"
11 #include <deque> 12 #include <deque>
12 13
13 namespace cc { 14 namespace cc {
14 15
15 // This type acts like a deque<scoped_ptr> based on top of std::deque. The 16 // This type acts like a deque<scoped_ptr> based on top of std::deque. The
16 // ScopedPtrDeque has ownership of all elements in the deque. 17 // ScopedPtrDeque has ownership of all elements in the deque.
17 template <typename T> 18 template <typename T>
18 class ScopedPtrDeque { 19 class ScopedPtrDeque {
19 public: 20 public:
20 typedef typename std::deque<T*>::iterator iterator; 21 typedef typename std::deque<T*>::iterator iterator;
21 typedef typename std::deque<T*>::const_iterator const_iterator; 22 typedef typename std::deque<T*>::const_iterator const_iterator;
22 typedef typename std::deque<T*>::reverse_iterator reverse_iterator; 23 typedef typename std::deque<T*>::reverse_iterator reverse_iterator;
23 typedef typename std::deque<T*>::const_reverse_iterator const_reverse_iterator ; 24 typedef typename std::deque<T*>::const_reverse_iterator const_reverse_iterator ;
24 25
25 ScopedPtrDeque() {} 26 ScopedPtrDeque() {}
26 27
27 ~ScopedPtrDeque() { clear(); } 28 ~ScopedPtrDeque() { clear(); }
28 29
29 size_t size() const { 30 size_t size() const {
30 return data_.size(); 31 return data_.size();
31 } 32 }
32 33
33 T* Peek(size_t index) const { 34 T* Peek(size_t index) const {
34 ASSERT(index < size()); 35 DCHECK(index < size());
35 return data_[index]; 36 return data_[index];
36 } 37 }
37 38
38 T* operator[](size_t index) const { 39 T* operator[](size_t index) const {
39 return Peek(index); 40 return Peek(index);
40 } 41 }
41 42
42 T* first() const { 43 T* first() const {
43 ASSERT(!isEmpty()); 44 DCHECK(!isEmpty());
44 return Peek(0); 45 return Peek(0);
45 } 46 }
46 47
47 T* last() const { 48 T* last() const {
48 ASSERT(!isEmpty()); 49 DCHECK(!isEmpty());
49 return Peek(size() - 1); 50 return Peek(size() - 1);
50 } 51 }
51 52
52 bool isEmpty() const { 53 bool isEmpty() const {
53 return size() == 0; 54 return size() == 0;
54 } 55 }
55 56
56 scoped_ptr<T> takeFirst() { 57 scoped_ptr<T> takeFirst() {
57 scoped_ptr<T> ret(first()); 58 scoped_ptr<T> ret(first());
58 data_.pop_front(); 59 data_.pop_front();
59 return ret.Pass(); 60 return ret.Pass();
60 } 61 }
61 62
62 scoped_ptr<T> takeLast() { 63 scoped_ptr<T> takeLast() {
63 scoped_ptr<T> ret(last()); 64 scoped_ptr<T> ret(last());
64 data_.pop_back(); 65 data_.pop_back();
65 return ret.Pass(); 66 return ret.Pass();
66 } 67 }
67 68
68 void clear() { 69 void clear() {
69 STLDeleteElements(&data_); 70 STLDeleteElements(&data_);
70 } 71 }
71 72
72 void append(scoped_ptr<T> item) { 73 void append(scoped_ptr<T> item) {
73 data_.push_back(item.release()); 74 data_.push_back(item.release());
74 } 75 }
75 76
76 void insert(size_t index, scoped_ptr<T> item) { 77 void insert(size_t index, scoped_ptr<T> item) {
77 ASSERT(index < size()); 78 DCHECK(index < size());
78 data_.insert(data_.begin() + index, item.release()); 79 data_.insert(data_.begin() + index, item.release());
79 } 80 }
80 81
81 iterator begin() { return data_.begin(); } 82 iterator begin() { return data_.begin(); }
82 const_iterator begin() const { return data_.begin(); } 83 const_iterator begin() const { return data_.begin(); }
83 iterator end() { return data_.end(); } 84 iterator end() { return data_.end(); }
84 const_iterator end() const { return data_.end(); } 85 const_iterator end() const { return data_.end(); }
85 86
86 reverse_iterator rbegin() { return data_.rbegin(); } 87 reverse_iterator rbegin() { return data_.rbegin(); }
87 const_reverse_iterator rbegin() const { return data_.rbegin(); } 88 const_reverse_iterator rbegin() const { return data_.rbegin(); }
88 reverse_iterator rend() { return data_.rend(); } 89 reverse_iterator rend() { return data_.rend(); }
89 const_reverse_iterator rend() const { return data_.rend(); } 90 const_reverse_iterator rend() const { return data_.rend(); }
90 91
91 private: 92 private:
92 std::deque<T*> data_; 93 std::deque<T*> data_;
93 94
94 DISALLOW_COPY_AND_ASSIGN(ScopedPtrDeque); 95 DISALLOW_COPY_AND_ASSIGN(ScopedPtrDeque);
95 }; 96 };
96 97
97 } // namespace cc 98 } // namespace cc
98 99
99 #endif // CC_SCOPED_PTR_DEQUE_H_ 100 #endif // CC_SCOPED_PTR_DEQUE_H_
OLDNEW
« no previous file with comments | « cc/scheduler_unittest.cc ('k') | cc/scoped_ptr_hash_map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698