#ifndef STORM_ARRAY_TS_BASE_ARRAY_HPP #define STORM_ARRAY_TS_BASE_ARRAY_HPP #include "storm/Error.hpp" #include #include template class TSBaseArray { public: uint32_t m_alloc = 0; uint32_t m_count = 0; T* m_data = nullptr; virtual const char* MemFileName() const; virtual int32_t MemLineNo() const; T& operator[](uint32_t index); void CheckArrayBounds(uint32_t index) const; uint32_t Count() const; void Clear(); T* Ptr(); const T* Ptr() const; T* Top(); }; template T& TSBaseArray::operator[](uint32_t index) { this->CheckArrayBounds(index); return this->m_data[index]; } template void TSBaseArray::CheckArrayBounds(uint32_t index) const { if (index < this->Count()) { return; } SErrDisplayErrorFmt( 0x85100080, this->MemFileName(), this->MemLineNo(), 1, 1, "index (0x%08X), array size (0x%08X)", index, this->Count()); } template uint32_t TSBaseArray::Count() const { return this->m_count; } template void TSBaseArray::Clear() { delete[] this->m_data; TSBaseArray(); } template const char* TSBaseArray::MemFileName() const { return typeid(T).name(); } template int32_t TSBaseArray::MemLineNo() const { return -2; } template T* TSBaseArray::Ptr() { return this->m_data; } template const T* TSBaseArray::Ptr() const { return this->m_data; } template T* TSBaseArray::Top() { if (this->m_count == 0) { return nullptr; } return &this->m_data[this->m_count - 1]; } #endif