2015-12-07 23:27:53 +03:00
|
|
|
/*
|
|
|
|
* Vector.h
|
|
|
|
*
|
|
|
|
* Created on: 7 Dec 2015
|
|
|
|
* Author: hieu
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2015-12-10 08:49:51 +03:00
|
|
|
#include <cassert>
|
2015-12-07 23:27:53 +03:00
|
|
|
#include "MemPool.h"
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
class Vector {
|
|
|
|
public:
|
2015-12-10 08:49:51 +03:00
|
|
|
typedef T* iterator;
|
|
|
|
typedef const T* const_iterator;
|
|
|
|
|
|
|
|
T *begin()
|
|
|
|
{ return m_arr; }
|
|
|
|
const T *begin() const
|
|
|
|
{ return m_arr; }
|
|
|
|
|
|
|
|
T *end()
|
|
|
|
{ return m_arr + m_size; }
|
|
|
|
const T *end() const
|
|
|
|
{ return m_arr + m_size; }
|
|
|
|
|
2015-12-07 23:27:53 +03:00
|
|
|
Vector(MemPool &pool, size_t size)
|
|
|
|
:m_size(size)
|
2015-12-10 08:49:51 +03:00
|
|
|
,m_maxSize(size)
|
2015-12-07 23:27:53 +03:00
|
|
|
{
|
|
|
|
m_arr = pool.Allocate<T>(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~Vector()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-10 08:49:51 +03:00
|
|
|
T& operator[](size_t ind)
|
|
|
|
{ return m_arr[ind]; }
|
|
|
|
const T& operator[](size_t ind) const
|
|
|
|
{ return m_arr[ind]; }
|
|
|
|
|
|
|
|
size_t size() const
|
|
|
|
{ return m_size; }
|
|
|
|
|
|
|
|
void resize(size_t newSize)
|
|
|
|
{
|
|
|
|
assert(newSize <= m_maxSize);
|
|
|
|
m_size = newSize;
|
|
|
|
}
|
|
|
|
|
2015-12-07 23:27:53 +03:00
|
|
|
protected:
|
2015-12-10 08:49:51 +03:00
|
|
|
size_t m_size, m_maxSize;
|
2015-12-07 23:27:53 +03:00
|
|
|
T *m_arr;
|
|
|
|
};
|
|
|
|
|