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

Side by Side Diff: base/memory/scoped_vector.h

Issue 10797017: base: Make ScopedVector::clear() destroy elements. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update location_bar_view_mac.mm Created 8 years, 5 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 | « no previous file | base/memory/scoped_vector_unittest.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 BASE_MEMORY_SCOPED_VECTOR_H_ 5 #ifndef BASE_MEMORY_SCOPED_VECTOR_H_
6 #define BASE_MEMORY_SCOPED_VECTOR_H_ 6 #define BASE_MEMORY_SCOPED_VECTOR_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 15 matching lines...) Expand all
26 typedef typename std::vector<T*>::reference reference; 26 typedef typename std::vector<T*>::reference reference;
27 typedef typename std::vector<T*>::const_reference const_reference; 27 typedef typename std::vector<T*>::const_reference const_reference;
28 typedef typename std::vector<T*>::value_type value_type; 28 typedef typename std::vector<T*>::value_type value_type;
29 typedef typename std::vector<T*>::iterator iterator; 29 typedef typename std::vector<T*>::iterator iterator;
30 typedef typename std::vector<T*>::const_iterator const_iterator; 30 typedef typename std::vector<T*>::const_iterator const_iterator;
31 typedef typename std::vector<T*>::reverse_iterator reverse_iterator; 31 typedef typename std::vector<T*>::reverse_iterator reverse_iterator;
32 typedef typename std::vector<T*>::const_reverse_iterator 32 typedef typename std::vector<T*>::const_reverse_iterator
33 const_reverse_iterator; 33 const_reverse_iterator;
34 34
35 ScopedVector() {} 35 ScopedVector() {}
36 ~ScopedVector() { reset(); } 36 ~ScopedVector() { clear(); }
37 ScopedVector(RValue& other) { swap(other); } 37 ScopedVector(RValue& other) { swap(other); }
38 38
39 ScopedVector& operator=(RValue& rhs) { 39 ScopedVector& operator=(RValue& rhs) {
40 swap(rhs); 40 swap(rhs);
41 return *this; 41 return *this;
42 } 42 }
43 43
44 T*& operator[](size_t i) { return v[i]; } 44 T*& operator[](size_t i) { return v[i]; }
45 const T* operator[](size_t i) const { return v[i]; } 45 const T* operator[](size_t i) const { return v[i]; }
46 46
(...skipping 19 matching lines...) Expand all
66 66
67 std::vector<T*>& get() { return v; } 67 std::vector<T*>& get() { return v; }
68 const std::vector<T*>& get() const { return v; } 68 const std::vector<T*>& get() const { return v; }
69 void swap(std::vector<T*>& other) { v.swap(other); } 69 void swap(std::vector<T*>& other) { v.swap(other); }
70 void swap(ScopedVector<T>& other) { v.swap(other.v); } 70 void swap(ScopedVector<T>& other) { v.swap(other.v); }
71 void release(std::vector<T*>* out) { 71 void release(std::vector<T*>* out) {
72 out->swap(v); 72 out->swap(v);
73 v.clear(); 73 v.clear();
74 } 74 }
75 75
76 void reset() { STLDeleteElements(&v); }
77 void reserve(size_t capacity) { v.reserve(capacity); } 76 void reserve(size_t capacity) { v.reserve(capacity); }
78 void resize(size_t new_size) { v.resize(new_size); } 77 void resize(size_t new_size) { v.resize(new_size); }
79 78
80 template<typename InputIterator> 79 template<typename InputIterator>
81 void assign(InputIterator begin, InputIterator end) { 80 void assign(InputIterator begin, InputIterator end) {
82 v.assign(begin, end); 81 v.assign(begin, end);
83 } 82 }
84 83
85 void clear() { v.clear(); } 84 void clear() { STLDeleteElements(&v); }
85
86 // Like |clear()|, but doesn't delete any elements.
87 void weak_clear() { v.clear(); }
86 88
87 // Lets the ScopedVector take ownership of |x|. 89 // Lets the ScopedVector take ownership of |x|.
88 iterator insert(iterator position, T* x) { 90 iterator insert(iterator position, T* x) {
89 return v.insert(position, x); 91 return v.insert(position, x);
90 } 92 }
91 93
92 // Lets the ScopedVector take ownership of elements in [first,last). 94 // Lets the ScopedVector take ownership of elements in [first,last).
93 template<typename InputIterator> 95 template<typename InputIterator>
94 void insert(iterator position, InputIterator first, InputIterator last) { 96 void insert(iterator position, InputIterator first, InputIterator last) {
95 v.insert(position, first, last); 97 v.insert(position, first, last);
(...skipping 17 matching lines...) Expand all
113 // Like |erase()|, but doesn't delete the elements in [first, last). 115 // Like |erase()|, but doesn't delete the elements in [first, last).
114 iterator weak_erase(iterator first, iterator last) { 116 iterator weak_erase(iterator first, iterator last) {
115 return v.erase(first, last); 117 return v.erase(first, last);
116 } 118 }
117 119
118 private: 120 private:
119 std::vector<T*> v; 121 std::vector<T*> v;
120 }; 122 };
121 123
122 #endif // BASE_MEMORY_SCOPED_VECTOR_H_ 124 #endif // BASE_MEMORY_SCOPED_VECTOR_H_
OLDNEW
« no previous file with comments | « no previous file | base/memory/scoped_vector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698