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:
|
2023-02-21 22:10:14 -06:00
|
|
|
// Member variables
|
|
|
|
|
uint32_t m_alloc;
|
|
|
|
|
uint32_t m_count;
|
|
|
|
|
T* m_data;
|
2020-09-24 23:33:18 -05:00
|
|
|
|
2023-02-21 22:10:14 -06:00
|
|
|
// Virtual member functions
|
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
|
|
|
|
2023-02-21 22:10:14 -06:00
|
|
|
// Member functions
|
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;
|
2023-02-21 22:10:14 -06:00
|
|
|
void Constructor();
|
2020-12-08 23:26:57 -06:00
|
|
|
uint32_t Count() const;
|
2021-01-03 10:35:58 -06:00
|
|
|
T* Ptr();
|
|
|
|
|
const T* Ptr() const;
|
2023-01-15 17:42:00 -06:00
|
|
|
T* Top();
|
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>
|
2023-02-21 22:10:14 -06:00
|
|
|
void TSBaseArray<T>::Constructor() {
|
|
|
|
|
this->m_alloc = 0;
|
|
|
|
|
this->m_count = 0;
|
|
|
|
|
this->m_data = nullptr;
|
2020-09-24 23:33:18 -05:00
|
|
|
}
|
|
|
|
|
|
2020-11-14 17:12:00 -06:00
|
|
|
template <class T>
|
2023-02-21 22:10:14 -06:00
|
|
|
uint32_t TSBaseArray<T>::Count() const {
|
|
|
|
|
return this->m_count;
|
2020-09-24 23:33:18 -05:00
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-15 17:42:00 -06:00
|
|
|
template <class T>
|
|
|
|
|
T* TSBaseArray<T>::Top() {
|
|
|
|
|
if (this->m_count == 0) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &this->m_data[this->m_count - 1];
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-24 23:33:18 -05:00
|
|
|
#endif
|