2012-02-20 04:46:08 +04:00
|
|
|
#ifndef MERT_SCOPED_VECTOR_H_
|
|
|
|
#define MERT_SCOPED_VECTOR_H_
|
2011-11-11 14:11:10 +04:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
class ScopedVector {
|
|
|
|
public:
|
|
|
|
typedef typename std::vector<T*>::iterator iterator;
|
|
|
|
typedef typename std::vector<T*>::const_iterator const_iterator;
|
|
|
|
|
|
|
|
ScopedVector() {}
|
|
|
|
virtual ~ScopedVector() { reset(); }
|
|
|
|
|
2012-03-10 12:12:34 +04:00
|
|
|
bool empty() const { return m_vec.empty(); }
|
2011-11-11 14:11:10 +04:00
|
|
|
|
2012-03-10 12:12:34 +04:00
|
|
|
void push_back(T *e) { m_vec.push_back(e); }
|
2011-11-11 14:11:10 +04:00
|
|
|
|
|
|
|
void reset() {
|
2012-03-10 12:12:34 +04:00
|
|
|
for (iterator it = m_vec.begin(); it != m_vec.end(); ++it) {
|
2011-11-11 14:11:10 +04:00
|
|
|
delete *it;
|
|
|
|
}
|
2012-03-10 12:12:34 +04:00
|
|
|
m_vec.clear();
|
2011-11-11 14:11:10 +04:00
|
|
|
}
|
|
|
|
|
2012-03-10 12:12:34 +04:00
|
|
|
void reserve(size_t capacity) { m_vec.reserve(capacity); }
|
|
|
|
void resize(size_t size) { m_vec.resize(size); }
|
2011-11-11 14:11:10 +04:00
|
|
|
|
2012-03-10 12:12:34 +04:00
|
|
|
size_t size() const {return m_vec.size(); }
|
2011-11-11 14:11:10 +04:00
|
|
|
|
2012-03-10 12:12:34 +04:00
|
|
|
iterator begin() { return m_vec.begin(); }
|
|
|
|
const_iterator begin() const { return m_vec.begin(); }
|
2011-11-11 14:11:10 +04:00
|
|
|
|
2012-03-10 12:12:34 +04:00
|
|
|
iterator end() { return m_vec.end(); }
|
|
|
|
const_iterator end() const { return m_vec.end(); }
|
2011-11-11 14:11:10 +04:00
|
|
|
|
2012-03-10 12:12:34 +04:00
|
|
|
std::vector<T*>& get() { return m_vec; }
|
|
|
|
const std::vector<T*>& get() const { return m_vec; }
|
2011-11-11 14:11:10 +04:00
|
|
|
|
2012-03-10 12:12:34 +04:00
|
|
|
std::vector<T*>* operator->() { return &m_vec; }
|
|
|
|
const std::vector<T*>* operator->() const { return &m_vec; }
|
2011-11-11 14:11:10 +04:00
|
|
|
|
2012-03-10 12:12:34 +04:00
|
|
|
T*& operator[](size_t i) { return m_vec[i]; }
|
|
|
|
const T* operator[](size_t i) const { return m_vec[i]; }
|
2011-11-11 14:11:10 +04:00
|
|
|
|
|
|
|
private:
|
2012-03-10 12:12:34 +04:00
|
|
|
std::vector<T*> m_vec;
|
2011-11-11 14:11:10 +04:00
|
|
|
|
|
|
|
// no copying allowed.
|
|
|
|
ScopedVector<T>(const ScopedVector<T>&);
|
|
|
|
void operator=(const ScopedVector<T>&);
|
|
|
|
};
|
|
|
|
|
2012-02-20 04:46:08 +04:00
|
|
|
#endif // MERT_SCOPED_VECTOR_H_
|