Added array class

This commit is contained in:
Jordan Cristiano 2015-06-14 16:12:09 -04:00
parent 21087117d7
commit 4c560eacac
1 changed files with 80 additions and 0 deletions

80
demboyz/base/array.h Normal file
View File

@ -0,0 +1,80 @@
#pragma once
#include <cstdint>
template<typename T, typename SizeType = std::int32_t>
class Array
{
public:
Array():
m_array(nullptr),
m_length(0)
{
}
Array(const Array& other) = delete;
Array& operator=(const Array& other) = delete;
Array(Array&& other):
m_array(other.m_array),
m_length(other.m_length)
{
other.m_array = nullptr;
other.m_length = 0;
}
~Array()
{
delete[] m_array;
}
Array& operator=(Array&& other)
{
m_array = other.m_array;
m_length = other.m_length;
other.m_array = nullptr;
other.m_length = 0;
return *this;
}
bool reset(SizeType length)
{
delete[] m_array;
if (length > 0)
{
m_array = new T[length];
m_length = length;
}
else if (length <= 0)
{
m_array = nullptr;
m_length = 0;
}
return (length >= 0);
}
T* begin() const
{
return m_array;
}
T* end() const
{
return m_array + m_length;
}
SizeType length() const
{
return m_length;
}
T& operator[](SizeType index) const
{
return *(m_array + index);
}
private:
T* m_array;
SizeType m_length;
};