Permalink
Browse files

Eliminate _loadArray function

  • Loading branch information...
TheCycoONE committed May 4, 2018
1 parent 34b3cdb commit 9a99400b94c161782041cc1d80809e65529b4d67
Showing with 6 additions and 27 deletions.
  1. +6 −27 AnimView/th.h
@@ -206,18 +206,13 @@ class THAnimations
static unsigned char* Decompress(unsigned char* pData, size_t& iLength);
protected:
template <class T>
bool _loadArray(T*& pArray, size_t& iCount, wxString sFilename)
{
if(pArray != NULL)
{
delete[] pArray;
pArray = NULL;
}
iCount = 0;
bool loadVector(std::vector<T>& vector, wxString sFilename) {
vector.clear();
wxFile oFile(sFilename);
if(!oFile.IsOpened())
if (!oFile.IsOpened())
return false;
size_t iLen = oFile.Length();
unsigned char* pBuffer = new unsigned char[iLen];
oFile.Read(pBuffer, iLen);
@@ -229,26 +224,10 @@ class THAnimations
return false;
}
}
pArray = (T*)pBuffer;
iCount = iLen / sizeof(T);
return true;
}
template <class T>
bool loadVector(std::vector<T>& vector, wxString sFilename) {
vector.clear();
T* tmpArray = nullptr;
std::size_t iCount = 0;
if (!_loadArray(tmpArray, iCount, sFilename)) {
return false;
}
for (int i = 0; i < iCount; i++) {
vector.push_back(tmpArray[i]);
for (int offset = 0; offset < iLen; offset += sizeof(T)) {
vector.push_back(*(reinterpret_cast<T*>(pBuffer + offset)));
}
delete[] tmpArray;
return true;
}

0 comments on commit 9a99400

Please sign in to comment.