| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2008 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_COMMON_SCOPED_VECTOR_H__ | |
| 6 #define CHROME_BROWSER_COMMON_SCOPED_VECTOR_H__ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "chrome/common/stl_util-inl.h" | |
| 11 | |
| 12 // ScopedVector wraps a vector deleting the elements from its | |
| 13 // destructor. | |
| 14 template <class T> | |
| 15 class ScopedVector { | |
| 16 public: | |
| 17 typedef typename std::vector<T*>::iterator iterator; | |
| 18 typedef typename std::vector<T*>::const_iterator const_iterator; | |
| 19 | |
| 20 ScopedVector() {} | |
| 21 ~ScopedVector() { reset(); } | |
| 22 | |
| 23 std::vector<T*>* operator->() { return &v; } | |
| 24 const std::vector<T*>* operator->() const { return &v; } | |
| 25 T* operator[](size_t i) { return v[i]; } | |
| 26 const T* operator[](size_t i) const { return v[i]; } | |
| 27 | |
| 28 bool empty() const { return v.empty(); } | |
| 29 size_t size() const { return v.size(); } | |
| 30 | |
| 31 iterator begin() { return v.begin(); } | |
| 32 const_iterator begin() const { return v.begin(); } | |
| 33 iterator end() { return v.end(); } | |
| 34 const_iterator end() const { return v.end(); } | |
| 35 | |
| 36 void push_back(T* elem) { v.push_back(elem); } | |
| 37 | |
| 38 std::vector<T*>& get() { return v; } | |
| 39 const std::vector<T*>& get() const { return v; } | |
| 40 void swap(ScopedVector<T>& other) { v.swap(other.v); } | |
| 41 void release(std::vector<T*>* out) { out->swap(v); v.clear(); } | |
| 42 | |
| 43 void reset() { STLDeleteElements(&v); } | |
| 44 | |
| 45 private: | |
| 46 std::vector<T*> v; | |
| 47 | |
| 48 DISALLOW_EVIL_CONSTRUCTORS(ScopedVector); | |
| 49 }; | |
| 50 | |
| 51 #endif // CHROME_BROWSER_COMMON_SCOPED_VECTOR_H__ | |
| OLD | NEW |