2020-09-24 23:33:18 -05:00
|
|
|
#ifndef STORM_ARRAY_TS_BASE_ARRAY_HPP
|
|
|
|
|
#define STORM_ARRAY_TS_BASE_ARRAY_HPP
|
|
|
|
|
|
2020-12-08 23:42:11 -06:00
|
|
|
#include "storm/Error.hpp"
|
2020-09-24 23:33:18 -05:00
|
|
|
#include <cstdint>
|
2020-12-08 19:40:26 -06:00
|
|
|
#include <typeinfo>
|
2020-09-24 23:33:18 -05:00
|
|
|
|
2020-11-14 17:12:00 -06:00
|
|
|
template <class T>
|
2020-09-24 23:33:18 -05:00
|
|
|
class TSBaseArray {
|
|
|
|
|
public:
|
|
|
|
|
uint32_t m_alloc = 0;
|
|
|
|
|
uint32_t m_count = 0;
|
|
|
|
|
T* m_data = nullptr;
|
|
|
|
|
|
2020-12-08 19:40:26 -06:00
|
|
|
virtual const char* MemFileName() const;
|
2020-12-08 23:12:59 -06:00
|
|
|
virtual int32_t MemLineNo() const;
|
2020-12-08 19:40:26 -06:00
|
|
|
|
2020-12-08 23:29:45 -06:00
|
|
|
T& operator[](uint32_t index);
|
2020-12-08 23:42:11 -06:00
|
|
|
void CheckArrayBounds(uint32_t index) const;
|
2020-12-08 23:26:57 -06:00
|
|
|
uint32_t Count() const;
|
|
|
|
|
void Clear();
|
2021-01-03 10:35:58 -06:00
|
|
|
T* Ptr();
|
|
|
|
|
const T* Ptr() const;
|
2020-09-24 23:33:18 -05:00
|
|
|
};
|
|
|
|
|
|
2020-11-14 17:12:00 -06:00
|
|
|
template <class T>
|
2020-12-08 23:29:45 -06:00
|
|
|
T& TSBaseArray<T>::operator[](uint32_t index) {
|
2020-12-08 23:42:11 -06:00
|
|
|
this->CheckArrayBounds(index);
|
2020-12-08 23:29:45 -06:00
|
|
|
return this->m_data[index];
|
2020-09-24 23:33:18 -05:00
|
|
|
}
|
|
|
|
|
|
2020-12-08 23:42:11 -06:00
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-14 17:12:00 -06:00
|
|
|
template <class T>
|
2020-12-08 23:26:09 -06:00
|
|
|
uint32_t TSBaseArray<T>::Count() const {
|
2020-09-24 23:33:18 -05:00
|
|
|
return this->m_count;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-14 17:12:00 -06:00
|
|
|
template <class T>
|
2020-09-24 23:33:18 -05:00
|
|
|
void TSBaseArray<T>::Clear() {
|
|
|
|
|
delete[] this->m_data;
|
|
|
|
|
TSBaseArray<T>();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-08 19:40:26 -06:00
|
|
|
template <class T>
|
|
|
|
|
const char* TSBaseArray<T>::MemFileName() const {
|
|
|
|
|
return typeid(T).name();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-08 23:12:59 -06:00
|
|
|
template <class T>
|
|
|
|
|
int32_t TSBaseArray<T>::MemLineNo() const {
|
|
|
|
|
return -2;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-03 10:35:58 -06:00
|
|
|
template <class T>
|
|
|
|
|
T* TSBaseArray<T>::Ptr() {
|
|
|
|
|
return this->m_data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
|
const T* TSBaseArray<T>::Ptr() const {
|
|
|
|
|
return this->m_data;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-24 23:33:18 -05:00
|
|
|
#endif
|