Remove extra line from unit_tests.isolate
[chromium-blink-merge.git] / cc / own_ptr_vector.h
blob196f82107e565c680dc4c9424181b6700c213ebd
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
3 // found in the LICENSE file.
5 #ifndef CC_OWN_PTR_VECTOR_H_
6 #define CC_OWN_PTR_VECTOR_H_
8 #include "base/basictypes.h"
9 #include "base/stl_util.h"
10 #include <wtf/PassOwnPtr.h>
11 #include <wtf/OwnPtr.h>
13 namespace cc {
15 // 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 template <typename T>
18 class OwnPtrVector {
19 public:
20 typedef typename std::vector<T*>::iterator iterator;
21 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*>::const_reverse_iterator
24 const_reverse_iterator;
26 OwnPtrVector() {}
28 ~OwnPtrVector() { clear(); }
30 size_t size() const {
31 return data_.size();
34 T* Peek(size_t index) const {
35 ASSERT(index < size());
36 return data_[index];
39 T* operator[](size_t index) const {
40 return Peek(index);
43 T* first() const {
44 ASSERT(!isEmpty());
45 return Peek(0);
48 T* last() const {
49 ASSERT(!isEmpty());
50 return Peek(size() - 1);
53 bool isEmpty() const {
54 return size() == 0;
57 PassOwnPtr<T> take(size_t index) {
58 ASSERT(index < size());
59 OwnPtr<T> ret = adoptPtr(data_[index]);
60 data_[index] = NULL;
61 return ret.release();
64 void remove(size_t index) {
65 ASSERT(index < size());
66 delete data_[index];
67 data_.erase(data_.begin() + index);
70 void clear() {
71 STLDeleteElements(&data_);
74 void append(PassOwnPtr<T> item) {
75 data_.push_back(item.leakPtr());
78 void insert(size_t index, PassOwnPtr<T> item) {
79 ASSERT(index < size());
80 data_.insert(data_.begin() + index, item.leakPtr());
83 iterator begin() { return data_.begin(); }
84 const_iterator begin() const { return data_.begin(); }
85 iterator end() { return data_.end(); }
86 const_iterator end() const { return data_.end(); }
88 reverse_iterator rbegin() { return data_.rbegin(); }
89 const_reverse_iterator rbegin() const { return data_.rbegin(); }
90 reverse_iterator rend() { return data_.rend(); }
91 const_reverse_iterator rend() const { return data_.rend(); }
93 private:
94 std::vector<T*> data_;
96 DISALLOW_COPY_AND_ASSIGN(OwnPtrVector);
99 } // namespace cc
101 #endif // CC_OWN_PTR_VECTOR_H_