diff --git a/demboyz/base/array.h b/demboyz/base/array.h new file mode 100644 index 0000000..ad3605e --- /dev/null +++ b/demboyz/base/array.h @@ -0,0 +1,80 @@ + +#pragma once + +#include + +template +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; +};