From 34965459f4f53a77f6c925292304eface57d12c6 Mon Sep 17 00:00:00 2001 From: dsinclair Date: Mon, 18 Jul 2016 13:14:49 -0700 Subject: Cleanup fgas/crt. This CL removes unused methods and default parameters from the fgas/crt code. Review-Url: https://codereview.chromium.org/2162503003 --- xfa/fgas/crt/fgas_codepage.cpp | 40 -------- xfa/fgas/crt/fgas_codepage.h | 4 +- xfa/fgas/crt/fgas_stream.cpp | 54 +++-------- xfa/fgas/crt/fgas_stream.h | 19 ++-- xfa/fgas/crt/fgas_system.h | 4 +- xfa/fgas/crt/fgas_utils.cpp | 4 +- xfa/fgas/crt/fgas_utils.h | 213 ++++++++++------------------------------- 7 files changed, 76 insertions(+), 262 deletions(-) (limited to 'xfa/fgas/crt') diff --git a/xfa/fgas/crt/fgas_codepage.cpp b/xfa/fgas/crt/fgas_codepage.cpp index 834056eddd..57f3e1e322 100644 --- a/xfa/fgas/crt/fgas_codepage.cpp +++ b/xfa/fgas/crt/fgas_codepage.cpp @@ -35,16 +35,6 @@ const FX_CHARSET_MAP g_FXCharset2CodePageTable[] = { {255, 850}, }; -const FX_CHARSET_MAP g_FXCodepage2CharsetTable[] = { - {1, 0}, {2, 42}, {254, 437}, {255, 850}, {222, 874}, - {128, 932}, {134, 936}, {129, 949}, {136, 950}, {238, 1250}, - {204, 1251}, {0, 1252}, {161, 1253}, {162, 1254}, {177, 1255}, - {178, 1256}, {186, 1257}, {163, 1258}, {130, 1361}, {77, 10000}, - {78, 10001}, {79, 10003}, {80, 10008}, {81, 10002}, {83, 10005}, - {84, 10004}, {85, 10006}, {86, 10081}, {87, 10021}, {88, 10029}, - {89, 10007}, -}; - const FX_LANG2CPMAP g_FXLang2CodepageTable[] = { {FX_LANG_Arabic_SaudiArabia, FX_CODEPAGE_MSWin_Arabic}, {FX_LANG_Bulgarian_Bulgaria, FX_CODEPAGE_MSWin_Cyrillic}, @@ -317,24 +307,6 @@ uint16_t FX_GetCodePageFromCharset(uint8_t charset) { return 0xFFFF; } -uint16_t FX_GetCharsetFromCodePage(uint16_t codepage) { - int32_t iEnd = sizeof(g_FXCodepage2CharsetTable) / sizeof(FX_CHARSET_MAP) - 1; - ASSERT(iEnd >= 0); - int32_t iStart = 0, iMid; - do { - iMid = (iStart + iEnd) / 2; - const FX_CHARSET_MAP& cp = g_FXCodepage2CharsetTable[iMid]; - if (codepage == cp.codepage) { - return cp.charset; - } else if (codepage < cp.codepage) { - iEnd = iMid - 1; - } else { - iStart = iMid + 1; - } - } while (iStart <= iEnd); - return 0xFFFF; -} - uint16_t FX_GetDefCodePageByLanguage(uint16_t wLanguage) { int32_t iEnd = sizeof(g_FXLang2CodepageTable) / sizeof(FX_LANG2CPMAP) - 1; ASSERT(iEnd >= 0); @@ -403,18 +375,6 @@ void FX_UTF16ToWChar(void* pBuffer, int32_t iLength) { } } -void FX_WCharToUTF16(void* pBuffer, int32_t iLength) { - ASSERT(pBuffer && iLength > 0); - if (sizeof(FX_WCHAR) == 2) { - return; - } - const FX_WCHAR* pSrc = (const FX_WCHAR*)pBuffer; - uint16_t* pDst = (uint16_t*)pBuffer; - while (--iLength >= 0) { - *pDst++ = (uint16_t)*pSrc++; - } -} - int32_t FX_DecodeString(uint16_t wCodePage, const FX_CHAR* pSrc, int32_t* pSrcLen, diff --git a/xfa/fgas/crt/fgas_codepage.h b/xfa/fgas/crt/fgas_codepage.h index 5d867feb8e..78aee83219 100644 --- a/xfa/fgas/crt/fgas_codepage.h +++ b/xfa/fgas/crt/fgas_codepage.h @@ -134,19 +134,17 @@ #define FX_CHARSET_OEM 255 uint16_t FX_GetCodePageFromCharset(uint8_t charset); -uint16_t FX_GetCharsetFromCodePage(uint16_t codepage); uint16_t FX_GetCodePageFromStringW(const FX_WCHAR* pStr, int32_t iLength); uint16_t FX_GetDefCodePageByLanguage(uint16_t wLanguage); void FX_SwapByteOrder(FX_WCHAR* pStr, int32_t iLength); void FX_UTF16ToWChar(void* pBuffer, int32_t iLength); -void FX_WCharToUTF16(void* pBuffer, int32_t iLength); int32_t FX_DecodeString(uint16_t wCodePage, const FX_CHAR* pSrc, int32_t* pSrcLen, FX_WCHAR* pDst, int32_t* pDstLen, - FX_BOOL bErrBreak = FALSE); + FX_BOOL bErrBreak); int32_t FX_UTF8Decode(const FX_CHAR* pSrc, int32_t* pSrcLen, FX_WCHAR* pDst, diff --git a/xfa/fgas/crt/fgas_stream.cpp b/xfa/fgas/crt/fgas_stream.cpp index dd54fbed28..25d8514257 100644 --- a/xfa/fgas/crt/fgas_stream.cpp +++ b/xfa/fgas/crt/fgas_stream.cpp @@ -227,8 +227,7 @@ class CFX_Stream : public IFX_Stream { int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, - FX_BOOL& bEOS, - int32_t const* pByteSize = nullptr) override; + FX_BOOL& bEOS) override; int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; void Flush() override; @@ -267,8 +266,7 @@ class CFX_TextStream : public IFX_Stream { int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, - FX_BOOL& bEOS, - int32_t const* pByteSize = nullptr) override; + FX_BOOL& bEOS) override; int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; void Flush() override; @@ -338,21 +336,7 @@ FX_BOOL FileSetSize(FXSYS_FILE* file, int32_t size) { } // namespace -IFX_Stream* IFX_Stream::CreateStream(IFX_BufferRead* pBufferRead, - uint32_t dwAccess, - int32_t iFileSize, - FX_BOOL bReleaseBufferRead) { - CFX_Stream* pSR = new CFX_Stream; - if (!pSR->LoadBufferRead(pBufferRead, iFileSize, dwAccess, - bReleaseBufferRead)) { - pSR->Release(); - return nullptr; - } - if (dwAccess & FX_STREAMACCESS_Text) { - return new CFX_TextStream(pSR, TRUE); - } - return pSR; -} +// static IFX_Stream* IFX_Stream::CreateStream(IFX_FileRead* pFileRead, uint32_t dwAccess) { CFX_Stream* pSR = new CFX_Stream; @@ -365,6 +349,8 @@ IFX_Stream* IFX_Stream::CreateStream(IFX_FileRead* pFileRead, } return pSR; } + +// static IFX_Stream* IFX_Stream::CreateStream(IFX_FileWrite* pFileWrite, uint32_t dwAccess) { CFX_Stream* pSR = new CFX_Stream; @@ -377,18 +363,8 @@ IFX_Stream* IFX_Stream::CreateStream(IFX_FileWrite* pFileWrite, } return pSR; } -IFX_Stream* IFX_Stream::CreateStream(const FX_WCHAR* pszFileName, - uint32_t dwAccess) { - CFX_Stream* pSR = new CFX_Stream; - if (!pSR->LoadFile(pszFileName, dwAccess)) { - pSR->Release(); - return nullptr; - } - if (dwAccess & FX_STREAMACCESS_Text) { - return new CFX_TextStream(pSR, TRUE); - } - return pSR; -} + +// static IFX_Stream* IFX_Stream::CreateStream(uint8_t* pData, int32_t length, uint32_t dwAccess) { @@ -932,11 +908,14 @@ int32_t CFX_BufferStreamImp::WriteString(const FX_WCHAR* pStr, } return iLen; } + +// static IFX_Stream* IFX_Stream::CreateTextStream(IFX_Stream* pBaseStream, FX_BOOL bDeleteOnRelease) { ASSERT(pBaseStream); return new CFX_TextStream(pBaseStream, bDeleteOnRelease); } + CFX_TextStream::CFX_TextStream(IFX_Stream* pStream, FX_BOOL bDelStream) : m_wCodePage(FX_CODEPAGE_DefANSI), m_wBOMLength(0), @@ -1073,8 +1052,7 @@ uint16_t CFX_TextStream::SetCodePage(uint16_t wCodePage) { } int32_t CFX_TextStream::ReadString(FX_WCHAR* pStr, int32_t iMaxLength, - FX_BOOL& bEOS, - int32_t const* pByteSize) { + FX_BOOL& bEOS) { ASSERT(pStr && iMaxLength > 0); if (!m_pStreamImp) { return -1; @@ -1082,7 +1060,7 @@ int32_t CFX_TextStream::ReadString(FX_WCHAR* pStr, int32_t iLen; if (m_wCodePage == FX_CODEPAGE_UTF16LE || m_wCodePage == FX_CODEPAGE_UTF16BE) { - int32_t iBytes = pByteSize ? *pByteSize : iMaxLength * 2; + int32_t iBytes = iMaxLength * 2; iLen = m_pStreamImp->ReadData((uint8_t*)pStr, iBytes); iMaxLength = iLen / 2; if (sizeof(FX_WCHAR) > 2) { @@ -1099,7 +1077,7 @@ int32_t CFX_TextStream::ReadString(FX_WCHAR* pStr, #endif } else { int32_t pos = m_pStreamImp->GetPosition(); - int32_t iBytes = pByteSize ? *pByteSize : iMaxLength; + int32_t iBytes = iMaxLength; iBytes = std::min(iBytes, m_pStreamImp->GetLength() - pos); if (iBytes > 0) { if (!m_pBuf) { @@ -1341,17 +1319,13 @@ int32_t CFX_Stream::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { } int32_t CFX_Stream::ReadString(FX_WCHAR* pStr, int32_t iMaxLength, - FX_BOOL& bEOS, - int32_t const* pByteSize) { + FX_BOOL& bEOS) { ASSERT(pStr && iMaxLength > 0); if (!m_pStreamImp) { return -1; } int32_t iEnd = m_iStart + m_iLength; int32_t iLen = iEnd - m_iPosition; - if (pByteSize) { - iLen = std::min(iLen, *pByteSize); - } iLen = std::min(iEnd / 2, iMaxLength); if (iLen <= 0) { return 0; diff --git a/xfa/fgas/crt/fgas_stream.h b/xfa/fgas/crt/fgas_stream.h index 5cd2a3daa7..443e8c7f5c 100644 --- a/xfa/fgas/crt/fgas_stream.h +++ b/xfa/fgas/crt/fgas_stream.h @@ -13,7 +13,7 @@ class IFX_Stream; IFX_FileRead* FX_CreateFileRead(IFX_Stream* pBaseStream, - FX_BOOL bReleaseStream = FALSE); + FX_BOOL bReleaseStream); enum FX_STREAMACCESS { FX_STREAMACCESS_Binary = 0x00, @@ -35,20 +35,19 @@ class IFX_Stream { public: static IFX_Stream* CreateStream(IFX_FileRead* pFileRead, uint32_t dwAccess); static IFX_Stream* CreateStream(IFX_FileWrite* pFileWrite, uint32_t dwAccess); - static IFX_Stream* CreateStream(const FX_WCHAR* pszFileName, - uint32_t dwAccess); static IFX_Stream* CreateStream(uint8_t* pData, int32_t length, uint32_t dwAccess); - static IFX_Stream* CreateStream(IFX_BufferRead* pBufferRead, - uint32_t dwAccess, - int32_t iFileSize = -1, - FX_BOOL bReleaseBufferRead = TRUE); static IFX_Stream* CreateTextStream(IFX_Stream* pBaseStream, FX_BOOL bDeleteOnRelease); virtual ~IFX_Stream() {} virtual void Release() = 0; virtual IFX_Stream* Retain() = 0; + + virtual IFX_Stream* CreateSharedStream(uint32_t dwAccess, + int32_t iOffset, + int32_t iLength) = 0; + virtual uint32_t GetAccessModes() const = 0; virtual int32_t GetLength() const = 0; virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) = 0; @@ -57,8 +56,7 @@ class IFX_Stream { virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) = 0; virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, - FX_BOOL& bEOS, - int32_t const* pByteSize = nullptr) = 0; + FX_BOOL& bEOS) = 0; virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) = 0; virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) = 0; virtual void Flush() = 0; @@ -66,9 +64,6 @@ class IFX_Stream { virtual int32_t GetBOM(uint8_t bom[4]) const = 0; virtual uint16_t GetCodePage() const = 0; virtual uint16_t SetCodePage(uint16_t wCodePage) = 0; - virtual IFX_Stream* CreateSharedStream(uint32_t dwAccess, - int32_t iOffset, - int32_t iLength) = 0; }; #endif // XFA_FGAS_CRT_FGAS_STREAM_H_ diff --git a/xfa/fgas/crt/fgas_system.h b/xfa/fgas/crt/fgas_system.h index 83c67735dc..6cf628f9d4 100644 --- a/xfa/fgas/crt/fgas_system.h +++ b/xfa/fgas/crt/fgas_system.h @@ -9,9 +9,7 @@ #include "core/fxcrt/include/fx_system.h" -FX_FLOAT FX_wcstof(const FX_WCHAR* pwsStr, - int32_t iLength = -1, - int32_t* pUsedLen = nullptr); +FX_FLOAT FX_wcstof(const FX_WCHAR* pwsStr, int32_t iLength, int32_t* pUsedLen); int32_t FX_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count); #endif // XFA_FGAS_CRT_FGAS_SYSTEM_H_ diff --git a/xfa/fgas/crt/fgas_utils.cpp b/xfa/fgas/crt/fgas_utils.cpp index 7207f055e5..e1f7c477fd 100644 --- a/xfa/fgas/crt/fgas_utils.cpp +++ b/xfa/fgas/crt/fgas_utils.cpp @@ -38,7 +38,7 @@ CFX_BaseArray::CFX_BaseArray(int32_t iGrowSize, int32_t iBlockSize) { m_pData = new FX_BASEARRAYDATA(iGrowSize, iBlockSize); } CFX_BaseArray::~CFX_BaseArray() { - RemoveAll(); + RemoveAll(FALSE); delete m_pData; } int32_t CFX_BaseArray::GetSize() const { @@ -153,7 +153,7 @@ CFX_BaseMassArrayImp::CFX_BaseMassArrayImp(int32_t iChunkSize, m_pData->SetSize(16); } CFX_BaseMassArrayImp::~CFX_BaseMassArrayImp() { - RemoveAll(); + RemoveAll(FALSE); delete m_pData; } uint8_t* CFX_BaseMassArrayImp::AddSpaceTo(int32_t index) { diff --git a/xfa/fgas/crt/fgas_utils.h b/xfa/fgas/crt/fgas_utils.h index 0cf853fa70..d7b753994c 100644 --- a/xfa/fgas/crt/fgas_utils.h +++ b/xfa/fgas/crt/fgas_utils.h @@ -22,14 +22,10 @@ class CFX_BaseArray : public CFX_Target { uint8_t* AddSpaceTo(int32_t index); uint8_t* GetAt(int32_t index) const; uint8_t* GetBuffer() const; - int32_t Append(const CFX_BaseArray& src, - int32_t iStart = 0, - int32_t iCount = -1); - int32_t Copy(const CFX_BaseArray& src, - int32_t iStart = 0, - int32_t iCount = -1); - int32_t RemoveLast(int32_t iCount = -1); - void RemoveAll(FX_BOOL bLeaveMemory = FALSE); + int32_t Append(const CFX_BaseArray& src, int32_t iStart, int32_t iCount); + int32_t Copy(const CFX_BaseArray& src, int32_t iStart, int32_t iCount); + int32_t RemoveLast(int32_t iCount); + void RemoveAll(FX_BOOL bLeaveMemory); FX_BASEARRAYDATA* m_pData; }; @@ -37,10 +33,11 @@ class CFX_BaseArray : public CFX_Target { template class CFX_BaseArrayTemplate : public CFX_BaseArray { public: - CFX_BaseArrayTemplate(int32_t iGrowSize = 100) + CFX_BaseArrayTemplate(int32_t iGrowSize) : CFX_BaseArray(iGrowSize, sizeof(baseType)) {} CFX_BaseArrayTemplate(int32_t iGrowSize, int32_t iBlockSize) : CFX_BaseArray(iGrowSize, iBlockSize) {} + int32_t GetSize() const { return CFX_BaseArray::GetSize(); } int32_t GetBlockSize() const { return CFX_BaseArray::GetBlockSize(); } baseType* AddSpace() { @@ -65,119 +62,19 @@ class CFX_BaseArrayTemplate : public CFX_BaseArray { *(baseType*)CFX_BaseArray::AddSpaceTo(index) = element; } int32_t Append(const CFX_BaseArrayTemplate& src, - int32_t iStart = 0, - int32_t iCount = -1) { + int32_t iStart, + int32_t iCount) { return CFX_BaseArray::Append(src, iStart, iCount); } int32_t Copy(const CFX_BaseArrayTemplate& src, - int32_t iStart = 0, - int32_t iCount = -1) { + int32_t iStart, + int32_t iCount) { return CFX_BaseArray::Copy(src, iStart, iCount); } - int32_t RemoveLast(int32_t iCount = -1) { + int32_t RemoveLast(int32_t iCount) { return CFX_BaseArray::RemoveLast(iCount); } - void RemoveAll(FX_BOOL bLeaveMemory = FALSE) { - CFX_BaseArray::RemoveAll(bLeaveMemory); - } -}; - -template -class CFX_ObjectBaseArrayTemplate : public CFX_BaseArray { - public: - CFX_ObjectBaseArrayTemplate(int32_t iGrowSize = 100) - : CFX_BaseArray(iGrowSize, sizeof(baseType)) {} - ~CFX_ObjectBaseArrayTemplate() { RemoveAll(FALSE); } - int32_t GetSize() const { return CFX_BaseArray::GetSize(); } - int32_t GetBlockSize() const { return CFX_BaseArray::GetBlockSize(); } - int32_t Add(const baseType& element) { - int32_t index = CFX_BaseArray::GetSize(); - baseType* p = (baseType*)CFX_BaseArray::AddSpaceTo(index); - new ((void*)p) baseType(element); - return index; - } - baseType& GetAt(int32_t index) const { - return *(baseType*)CFX_BaseArray::GetAt(index); - } - baseType* GetPtrAt(int32_t index) const { - return (baseType*)CFX_BaseArray::GetAt(index); - } - int32_t Append(const CFX_ObjectBaseArrayTemplate& src, - int32_t iStart = 0, - int32_t iCount = -1) { - ASSERT(GetBlockSize() == src.GetBlockSize()); - if (iCount == 0) { - return 0; - } - int32_t iSize = src.GetSize(); - ASSERT(iStart > -1 && iStart < iSize); - if (iCount < 0) { - iCount = iSize; - } - if (iStart + iCount > iSize) { - iCount = iSize - iStart; - } - if (iCount < 1) { - return 0; - } - iSize = CFX_BaseArray::GetSize(); - CFX_BaseArray::AddSpaceTo(iSize + iCount - 1); - uint8_t** pStart = CFX_BaseArray::GetAt(iSize); - int32_t iBlockSize = CFX_BaseArray::GetBlockSize(); - iSize = iStart + iCount; - for (int32_t i = iStart; i < iSize; i++) { - FXTARGET_NewWith((void*)pStart) baseType(src.GetAt(i)); - pStart += iBlockSize; - } - return iCount; - } - int32_t Copy(const CFX_ObjectBaseArrayTemplate& src, - int32_t iStart = 0, - int32_t iCount = -1) { - ASSERT(GetBlockSize() == src.GetBlockSize()); - if (iCount == 0) { - return 0; - } - int32_t iSize = src.GetSize(); - ASSERT(iStart > -1 && iStart < iSize); - if (iCount < 0) { - iCount = iSize; - } - if (iStart + iCount > iSize) { - iCount = iSize - iStart; - } - if (iCount < 1) { - return 0; - } - RemoveAll(TRUE); - CFX_BaseArray::AddSpaceTo(iCount - 1); - uint8_t** pStart = CFX_BaseArray::GetAt(0); - int32_t iBlockSize = CFX_BaseArray::GetBlockSize(); - iSize = iStart + iCount; - for (int32_t i = iStart; i < iSize; i++) { - new ((void*)pStart) baseType(src.GetAt(i)); - pStart += iBlockSize; - } - return iCount; - } - int32_t RemoveLast(int32_t iCount = -1) { - int32_t iSize = CFX_BaseArray::GetSize(); - if (iCount < 0 || iCount > iSize) { - iCount = iSize; - } - if (iCount == 0) { - return iSize; - } - for (int32_t i = iSize - iCount; i < iSize; i++) { - ((baseType*)GetPtrAt(i))->~baseType(); - } - return CFX_BaseArray::RemoveLast(iCount); - } - void RemoveAll(FX_BOOL bLeaveMemory = FALSE) { - int32_t iSize = CFX_BaseArray::GetSize(); - for (int32_t i = 0; i < iSize; i++) { - ((baseType*)GetPtrAt(i))->~baseType(); - } + void RemoveAll(FX_BOOL bLeaveMemory) { CFX_BaseArray::RemoveAll(bLeaveMemory); } }; @@ -191,13 +88,11 @@ class CFX_BaseMassArrayImp : public CFX_Target { uint8_t* AddSpaceTo(int32_t index); uint8_t* GetAt(int32_t index) const; int32_t Append(const CFX_BaseMassArrayImp& src, - int32_t iStart = 0, - int32_t iCount = -1); - int32_t Copy(const CFX_BaseMassArrayImp& src, - int32_t iStart = 0, - int32_t iCount = -1); - int32_t RemoveLast(int32_t iCount = -1); - void RemoveAll(FX_BOOL bLeaveMemory = FALSE); + int32_t iStart, + int32_t iCount); + int32_t Copy(const CFX_BaseMassArrayImp& src, int32_t iStart, int32_t iCount); + int32_t RemoveLast(int32_t iCount); + void RemoveAll(FX_BOOL bLeaveMemory); int32_t m_iChunkSize; int32_t m_iBlockSize; @@ -208,8 +103,8 @@ class CFX_BaseMassArrayImp : public CFX_Target { protected: void Append(int32_t iDstStart, const CFX_BaseMassArrayImp& src, - int32_t iSrcStart = 0, - int32_t iSrcCount = -1); + int32_t iSrcStart, + int32_t iSrcCount); }; class CFX_BaseMassArray : public CFX_Target { @@ -220,24 +115,21 @@ class CFX_BaseMassArray : public CFX_Target { int32_t GetSize() const; uint8_t* AddSpaceTo(int32_t index); uint8_t* GetAt(int32_t index) const; - int32_t Append(const CFX_BaseMassArray& src, - int32_t iStart = 0, - int32_t iCount = -1); - int32_t Copy(const CFX_BaseMassArray& src, - int32_t iStart = 0, - int32_t iCount = -1); - int32_t RemoveLast(int32_t iCount = -1); - void RemoveAll(FX_BOOL bLeaveMemory = FALSE); + int32_t Append(const CFX_BaseMassArray& src, int32_t iStart, int32_t iCount); + int32_t Copy(const CFX_BaseMassArray& src, int32_t iStart, int32_t iCount); + int32_t RemoveLast(int32_t iCount); + void RemoveAll(FX_BOOL bLeaveMemory); CFX_BaseMassArrayImp* m_pData; }; template class CFX_MassArrayTemplate : public CFX_BaseMassArray { public: - CFX_MassArrayTemplate(int32_t iChunkSize = 100) + CFX_MassArrayTemplate(int32_t iChunkSize) : CFX_BaseMassArray(iChunkSize, sizeof(baseType)) {} CFX_MassArrayTemplate(int32_t iChunkSize, int32_t iBlockSize) : CFX_BaseMassArray(iChunkSize, iBlockSize) {} + int32_t GetSize() const { return CFX_BaseMassArray::GetSize(); } baseType* AddSpace() { return (baseType*)CFX_BaseMassArray::AddSpaceTo( @@ -261,19 +153,19 @@ class CFX_MassArrayTemplate : public CFX_BaseMassArray { *(baseType*)CFX_BaseMassArray::AddSpaceTo(index) = element; } int32_t Append(const CFX_MassArrayTemplate& src, - int32_t iStart = 0, - int32_t iCount = -1) { + int32_t iStart, + int32_t iCount) { return CFX_BaseMassArray::Append(src, iStart, iCount); } int32_t Copy(const CFX_MassArrayTemplate& src, - int32_t iStart = 0, - int32_t iCount = -1) { + int32_t iStart, + int32_t iCount) { return CFX_BaseMassArray::Copy(src, iStart, iCount); } - int32_t RemoveLast(int32_t iCount = -1) { + int32_t RemoveLast(int32_t iCount) { return CFX_BaseMassArray::RemoveLast(iCount); } - void RemoveAll(FX_BOOL bLeaveMemory = FALSE) { + void RemoveAll(FX_BOOL bLeaveMemory) { CFX_BaseMassArray::RemoveAll(bLeaveMemory); } }; @@ -281,9 +173,10 @@ class CFX_MassArrayTemplate : public CFX_BaseMassArray { template class CFX_ObjectMassArrayTemplate : public CFX_BaseMassArray { public: - CFX_ObjectMassArrayTemplate(int32_t iChunkSize = 100) + CFX_ObjectMassArrayTemplate(int32_t iChunkSize) : CFX_BaseMassArray(iChunkSize, sizeof(baseType)) {} ~CFX_ObjectMassArrayTemplate() { RemoveAll(FALSE); } + int32_t GetSize() const { return CFX_BaseMassArray::GetSize(); } int32_t Add(const baseType& element) { int32_t index = CFX_BaseMassArray::GetSize(); @@ -298,8 +191,8 @@ class CFX_ObjectMassArrayTemplate : public CFX_BaseMassArray { return (baseType*)CFX_BaseMassArray::GetAt(index); } int32_t Append(const CFX_ObjectMassArrayTemplate& src, - int32_t iStart = 0, - int32_t iCount = -1) { + int32_t iStart, + int32_t iCount) { if (iCount == 0) { return CFX_BaseMassArray::GetSize(); } @@ -318,8 +211,8 @@ class CFX_ObjectMassArrayTemplate : public CFX_BaseMassArray { return CFX_BaseMassArray::GetSize(); } int32_t Copy(const CFX_ObjectMassArrayTemplate& src, - int32_t iStart = 0, - int32_t iCount = -1) { + int32_t iStart, + int32_t iCount) { if (iCount == 0) { return CFX_BaseMassArray::GetSize(); } @@ -338,7 +231,7 @@ class CFX_ObjectMassArrayTemplate : public CFX_BaseMassArray { } return CFX_BaseMassArray::GetSize(); } - int32_t RemoveLast(int32_t iCount = -1) { + int32_t RemoveLast(int32_t iCount) { int32_t iSize = CFX_BaseMassArray::GetSize(); if (iCount < 0 || iCount > iSize) { iCount = iSize; @@ -351,7 +244,7 @@ class CFX_ObjectMassArrayTemplate : public CFX_BaseMassArray { } return CFX_BaseMassArray::RemoveLast(iCount); } - void RemoveAll(FX_BOOL bLeaveMemory = FALSE) { + void RemoveAll(FX_BOOL bLeaveMemory) { int32_t iSize = CFX_BaseMassArray::GetSize(); for (int32_t i = 0; i < iSize; i++) { ((baseType*)GetPtrAt(i))->~baseType(); @@ -374,8 +267,9 @@ class CFX_BaseDiscreteArray : public CFX_Target { template class CFX_DiscreteArrayTemplate : public CFX_BaseDiscreteArray { public: - CFX_DiscreteArrayTemplate(int32_t iChunkSize = 100) + CFX_DiscreteArrayTemplate(int32_t iChunkSize) : CFX_BaseDiscreteArray(iChunkSize, sizeof(baseType)) {} + baseType& GetAt(int32_t index, const baseType& defValue) const { baseType* p = (baseType*)CFX_BaseDiscreteArray::GetAt(index); return p ? *p : (baseType&)defValue; @@ -388,9 +282,6 @@ class CFX_DiscreteArrayTemplate : public CFX_BaseDiscreteArray { } void RemoveAll() { CFX_BaseDiscreteArray::RemoveAll(); } }; -typedef CFX_DiscreteArrayTemplate CFX_PtrDiscreteArray; -typedef CFX_DiscreteArrayTemplate CFX_DWordDiscreteArray; -typedef CFX_DiscreteArrayTemplate CFX_WordDiscreteArray; class CFX_BaseStack : public CFX_Target { protected: @@ -402,15 +293,16 @@ class CFX_BaseStack : public CFX_Target { uint8_t* GetTopElement() const; int32_t GetSize() const; uint8_t* GetAt(int32_t index) const; - void RemoveAll(FX_BOOL bLeaveMemory = FALSE); + void RemoveAll(FX_BOOL bLeaveMemory); CFX_BaseMassArrayImp* m_pData; }; template class CFX_StackTemplate : public CFX_BaseStack { public: - CFX_StackTemplate(int32_t iChunkSize = 100) + CFX_StackTemplate(int32_t iChunkSize) : CFX_BaseStack(iChunkSize, sizeof(baseType)) {} + int32_t Push(const baseType& element) { int32_t index = CFX_BaseStack::GetSize(); *(baseType*)CFX_BaseStack::Push() = element; @@ -424,21 +316,18 @@ class CFX_StackTemplate : public CFX_BaseStack { baseType* GetAt(int32_t index) const { return (baseType*)CFX_BaseStack::GetAt(index); } - void RemoveAll(FX_BOOL bLeaveMemory = FALSE) { + void RemoveAll(FX_BOOL bLeaveMemory) { CFX_BaseStack::RemoveAll(bLeaveMemory); } }; -typedef CFX_StackTemplate CFX_PtrStack; -typedef CFX_StackTemplate CFX_DWordStack; -typedef CFX_StackTemplate CFX_WordStack; -typedef CFX_StackTemplate CFX_Int32Stack; template class CFX_ObjectStackTemplate : public CFX_BaseStack { public: - CFX_ObjectStackTemplate(int32_t iChunkSize = 100) + CFX_ObjectStackTemplate(int32_t iChunkSize) : CFX_BaseStack(iChunkSize, sizeof(baseType)) {} - ~CFX_ObjectStackTemplate() { RemoveAll(); } + ~CFX_ObjectStackTemplate() { RemoveAll(FALSE); } + int32_t Push(const baseType& element) { int32_t index = CFX_BaseStack::GetSize(); baseType* p = (baseType*)CFX_BaseStack::Push(); @@ -459,7 +348,7 @@ class CFX_ObjectStackTemplate : public CFX_BaseStack { baseType* GetAt(int32_t index) const { return (baseType*)CFX_BaseStack::GetAt(index); } - void RemoveAll(FX_BOOL bLeaveMemory = FALSE) { + void RemoveAll(FX_BOOL bLeaveMemory) { int32_t iSize = CFX_BaseStack::GetSize(); for (int32_t i = 0; i < iSize; i++) { ((baseType*)CFX_BaseStack::GetAt(i))->~baseType(); @@ -467,8 +356,8 @@ class CFX_ObjectStackTemplate : public CFX_BaseStack { CFX_BaseStack::RemoveAll(bLeaveMemory); } int32_t Copy(const CFX_ObjectStackTemplate& src, - int32_t iStart = 0, - int32_t iCount = -1) { + int32_t iStart, + int32_t iCount) { if (iCount == 0) { return CFX_BaseStack::GetSize(); } -- cgit v1.2.3