feat(array): add copy assignment operator to TSFixedArray

This commit is contained in:
fallenoak 2023-02-04 23:48:20 -06:00 committed by GitHub
parent 8bdbe3c653
commit 0a941aaa08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,7 +9,10 @@ template <class T>
class TSFixedArray : public TSBaseArray<T> { class TSFixedArray : public TSBaseArray<T> {
public: public:
~TSFixedArray(); ~TSFixedArray();
TSFixedArray<T>& operator=(const TSFixedArray<T>& source);
void ReallocAndClearData(uint32_t count);
void ReallocData(uint32_t count); void ReallocData(uint32_t count);
void Set(uint32_t count, const T* data);
void SetCount(uint32_t count); void SetCount(uint32_t count);
}; };
@ -25,6 +28,25 @@ TSFixedArray<T>::~TSFixedArray() {
} }
} }
template <class T>
TSFixedArray<T>& TSFixedArray<T>::operator=(const TSFixedArray<T>& source) {
if (this != &source) {
this->Set(source.Count(), source.Ptr());
}
return *this;
}
template <class T>
void TSFixedArray<T>::ReallocAndClearData(uint32_t count) {
this->m_alloc = count;
if (this->m_data || count) {
void* m = SMemReAlloc(this->m_data, sizeof(T) * count, this->MemFileName(), this->MemLineNo(), 0x0);
this->m_data = static_cast<T*>(m);
}
}
template <class T> template <class T>
void TSFixedArray<T>::ReallocData(uint32_t count) { void TSFixedArray<T>::ReallocData(uint32_t count) {
T* oldData = this->m_data; T* oldData = this->m_data;
@ -60,6 +82,17 @@ void TSFixedArray<T>::ReallocData(uint32_t count) {
} }
} }
template <class T>
void TSFixedArray<T>::Set(uint32_t count, const T* data) {
this->ReallocAndClearData(count);
for (uint32_t i; i < count; i++) {
new (&this->m_data[i]) T(data[i]);
}
this->m_count = count;
}
template <class T> template <class T>
void TSFixedArray<T>::SetCount(uint32_t count) { void TSFixedArray<T>::SetCount(uint32_t count) {
if (count != this->m_count) { if (count != this->m_count) {