feat(array): add TSBaseArray<T>::CheckArrayBounds

This commit is contained in:
fallenoak 2020-12-08 23:42:11 -06:00
parent a47059bd90
commit 67841ebf14
No known key found for this signature in database
GPG key ID: 7628F8E61AEA070D

View file

@ -1,6 +1,7 @@
#ifndef STORM_ARRAY_TS_BASE_ARRAY_HPP #ifndef STORM_ARRAY_TS_BASE_ARRAY_HPP
#define STORM_ARRAY_TS_BASE_ARRAY_HPP #define STORM_ARRAY_TS_BASE_ARRAY_HPP
#include "storm/Error.hpp"
#include <cstdint> #include <cstdint>
#include <typeinfo> #include <typeinfo>
@ -15,15 +16,34 @@ class TSBaseArray {
virtual int32_t MemLineNo() const; virtual int32_t MemLineNo() const;
T& operator[](uint32_t index); T& operator[](uint32_t index);
void CheckArrayBounds(uint32_t index) const;
uint32_t Count() const; uint32_t Count() const;
void Clear(); void Clear();
}; };
template <class T> template <class T>
T& TSBaseArray<T>::operator[](uint32_t index) { T& TSBaseArray<T>::operator[](uint32_t index) {
this->CheckArrayBounds(index);
return this->m_data[index]; return this->m_data[index];
} }
template <class T>
void TSBaseArray<T>::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 <class T> template <class T>
uint32_t TSBaseArray<T>::Count() const { uint32_t TSBaseArray<T>::Count() const {
return this->m_count; return this->m_count;