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

Side by Side Diff: chrome/common/scoped_vector.h

Issue 107001: Move scoped_vector.h and stl_util-inl.h to base/ (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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 | « chrome/common/pref_service.cc ('k') | chrome/common/sqlite_compiled_statement.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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__
OLDNEW
« no previous file with comments | « chrome/common/pref_service.cc ('k') | chrome/common/sqlite_compiled_statement.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698