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

Side by Side Diff: base/scoped_vector.h

Issue 600133: Mac: Content blocked icons. (Closed)
Patch Set: comments andybons Created 10 years, 10 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
« no previous file with comments | « no previous file | chrome/app/nibs/Preferences.xib » ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_SCOPED_VECTOR_H_ 5 #ifndef BASE_SCOPED_VECTOR_H_
6 #define BASE_SCOPED_VECTOR_H_ 6 #define BASE_SCOPED_VECTOR_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/stl_util-inl.h" 11 #include "base/stl_util-inl.h"
12 12
13 // ScopedVector wraps a vector deleting the elements from its 13 // ScopedVector wraps a vector deleting the elements from its
14 // destructor. 14 // destructor.
15 template <class T> 15 template <class T>
16 class ScopedVector { 16 class ScopedVector {
17 public: 17 public:
18 typedef typename std::vector<T*>::iterator iterator; 18 typedef typename std::vector<T*>::iterator iterator;
19 typedef typename std::vector<T*>::const_iterator const_iterator; 19 typedef typename std::vector<T*>::const_iterator const_iterator;
20 typedef typename std::vector<T*>::reverse_iterator reverse_iterator;
21 typedef typename std::vector<T*>::const_reverse_iterator
22 const_reverse_iterator;
20 23
21 ScopedVector() {} 24 ScopedVector() {}
22 ~ScopedVector() { reset(); } 25 ~ScopedVector() { reset(); }
23 26
24 std::vector<T*>* operator->() { return &v; } 27 std::vector<T*>* operator->() { return &v; }
25 const std::vector<T*>* operator->() const { return &v; } 28 const std::vector<T*>* operator->() const { return &v; }
26 T* operator[](size_t i) { return v[i]; } 29 T* operator[](size_t i) { return v[i]; }
27 const T* operator[](size_t i) const { return v[i]; } 30 const T* operator[](size_t i) const { return v[i]; }
28 31
29 bool empty() const { return v.empty(); } 32 bool empty() const { return v.empty(); }
30 size_t size() const { return v.size(); } 33 size_t size() const { return v.size(); }
31 34
35 reverse_iterator rbegin() { return v.rbegin(); }
36 const_reverse_iterator rbegin() const { return v.rbegin(); }
37 reverse_iterator rend() { return v.rend(); }
38 const_reverse_iterator rend() const { return v.rend(); }
39
32 iterator begin() { return v.begin(); } 40 iterator begin() { return v.begin(); }
33 const_iterator begin() const { return v.begin(); } 41 const_iterator begin() const { return v.begin(); }
34 iterator end() { return v.end(); } 42 iterator end() { return v.end(); }
35 const_iterator end() const { return v.end(); } 43 const_iterator end() const { return v.end(); }
36 44
37 void push_back(T* elem) { v.push_back(elem); } 45 void push_back(T* elem) { v.push_back(elem); }
38 46
39 std::vector<T*>& get() { return v; } 47 std::vector<T*>& get() { return v; }
40 const std::vector<T*>& get() const { return v; } 48 const std::vector<T*>& get() const { return v; }
41 void swap(ScopedVector<T>& other) { v.swap(other.v); } 49 void swap(ScopedVector<T>& other) { v.swap(other.v); }
42 void release(std::vector<T*>* out) { 50 void release(std::vector<T*>* out) {
43 out->swap(v); 51 out->swap(v);
44 v.clear(); 52 v.clear();
45 } 53 }
46 54
47 void reset() { STLDeleteElements(&v); } 55 void reset() { STLDeleteElements(&v); }
48 56
49 private: 57 private:
50 std::vector<T*> v; 58 std::vector<T*> v;
51 59
52 DISALLOW_COPY_AND_ASSIGN(ScopedVector); 60 DISALLOW_COPY_AND_ASSIGN(ScopedVector);
53 }; 61 };
54 62
55 #endif // BASE_SCOPED_VECTOR_H_ 63 #endif // BASE_SCOPED_VECTOR_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/app/nibs/Preferences.xib » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698