diff options
author | Patrick Scott <phanna@android.com> | 2010-02-04 10:37:17 -0500 |
---|---|---|
committer | Patrick Scott <phanna@android.com> | 2010-02-04 10:39:42 -0500 |
commit | c7f5f8508d98d5952d42ed7648c2a8f30a4da156 (patch) | |
tree | dd51dbfbf6670daa61279b3a19e7b1835b301dbf /base/scoped_vector.h | |
parent | 139d8152182f9093f03d9089822b688e49fa7667 (diff) | |
download | external_chromium-c7f5f8508d98d5952d42ed7648c2a8f30a4da156.zip external_chromium-c7f5f8508d98d5952d42ed7648c2a8f30a4da156.tar.gz external_chromium-c7f5f8508d98d5952d42ed7648c2a8f30a4da156.tar.bz2 |
Initial source checkin.
The source files were determined by building net_unittests in chromium's source
tree. Some of the obvious libraries were left out (v8, gmock, gtest).
The Android.mk file has all the sources (minus unittests and tools) that were
used during net_unittests compilation. Nothing builds yet because of STL but
that is the next task. The .cpp files will most likely not compile anyways
because of the LOCAL_CPP_EXTENSION mod. I will have to break this into multiple
projects to get around that limitation.
Diffstat (limited to 'base/scoped_vector.h')
-rw-r--r-- | base/scoped_vector.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/base/scoped_vector.h b/base/scoped_vector.h new file mode 100644 index 0000000..0c7449d --- /dev/null +++ b/base/scoped_vector.h @@ -0,0 +1,55 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_SCOPED_VECTOR_H_ +#define BASE_SCOPED_VECTOR_H_ + +#include <vector> + +#include "base/logging.h" +#include "base/stl_util-inl.h" + +// ScopedVector wraps a vector deleting the elements from its +// destructor. +template <class T> +class ScopedVector { + public: + typedef typename std::vector<T*>::iterator iterator; + typedef typename std::vector<T*>::const_iterator const_iterator; + + ScopedVector() {} + ~ScopedVector() { reset(); } + + std::vector<T*>* operator->() { return &v; } + const std::vector<T*>* operator->() const { return &v; } + T* operator[](size_t i) { return v[i]; } + const T* operator[](size_t i) const { return v[i]; } + + bool empty() const { return v.empty(); } + size_t size() const { return v.size(); } + + iterator begin() { return v.begin(); } + const_iterator begin() const { return v.begin(); } + iterator end() { return v.end(); } + const_iterator end() const { return v.end(); } + + void push_back(T* elem) { v.push_back(elem); } + + std::vector<T*>& get() { return v; } + const std::vector<T*>& get() const { return v; } + void swap(ScopedVector<T>& other) { v.swap(other.v); } + void release(std::vector<T*>* out) { + out->swap(v); + v.clear(); + } + + void reset() { STLDeleteElements(&v); } + + private: + std::vector<T*> v; + + DISALLOW_COPY_AND_ASSIGN(ScopedVector); +}; + +#endif // BASE_SCOPED_VECTOR_H_ |