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

Unified Diff: cc/scoped_ptr_vector.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 side-by-side diff with in-line comments
Download patch
Index: cc/scoped_ptr_vector.h
diff --git a/cc/scoped_ptr_vector.h b/cc/scoped_ptr_vector.h
index 28c00141004fede6e357428ac1b43796941938ff..6cbe812139508eacf1945154f6a489408763eb4e 100644
--- a/cc/scoped_ptr_vector.h
+++ b/cc/scoped_ptr_vector.h
@@ -31,53 +31,63 @@ class ScopedPtrVector {
return data_.size();
}
- T* Peek(size_t index) const {
+ T* at(size_t index) const {
DCHECK(index < size());
return data_[index];
}
T* operator[](size_t index) const {
- return Peek(index);
+ return at(index);
}
- T* first() const {
- DCHECK(!isEmpty());
- return Peek(0);
+ T* front() const {
+ DCHECK(!empty());
+ return at(0);
}
- T* last() const {
- DCHECK(!isEmpty());
- return Peek(size() - 1);
+ T* back() const {
+ DCHECK(!empty());
+ return at(size() - 1);
}
- bool isEmpty() const {
+ bool empty() const {
return size() == 0;
}
- scoped_ptr<T> take(size_t index) {
- DCHECK(index < size());
- scoped_ptr<T> ret(data_[index]);
- data_[index] = NULL;
+ scoped_ptr<T> take(iterator position) {
enne (OOO) 2012/11/21 04:12:57 Same question here.
danakj 2012/11/21 04:23:21 But here, take is different than erase. It removes
+ if (position == end())
+ return scoped_ptr<T>(NULL);
+ scoped_ptr<T> ret(*position);
+ *position = NULL;
return ret.Pass();
}
- void remove(size_t index) {
- DCHECK(index < size());
- delete data_[index];
- data_.erase(data_.begin() + index);
+ void erase(iterator position) {
+ if (position == end())
+ return;
+ delete *position;
+ data_.erase(position);
+ }
+
+ void erase(iterator first, iterator last) {
+ DCHECK(first <= last);
+ for (iterator it = first; it != last; ++it) {
+ DCHECK(it != end());
+ delete *it;
+ data_.erase(it);
+ }
}
void clear() {
STLDeleteElements(&data_);
}
- void append(scoped_ptr<T> item) {
+ void push_back(scoped_ptr<T> item) {
data_.push_back(item.release());
}
- void insert(size_t index, scoped_ptr<T> item) {
- DCHECK(index < size());
- data_.insert(data_.begin() + index, item.release());
+ void insert(iterator position, scoped_ptr<T> item) {
+ data_.insert(position, item.release());
}
iterator begin() { return data_.begin(); }
« cc/scoped_ptr_deque.h ('K') | « cc/scoped_ptr_deque.h ('k') | cc/test/mock_quad_culler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698