diff options
Diffstat (limited to 'xfa/fgas/crt/fgas_utils.h')
-rw-r--r-- | xfa/fgas/crt/fgas_utils.h | 213 |
1 files changed, 51 insertions, 162 deletions
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 baseType> 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 baseType> -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 baseType> 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 baseType> 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 baseType> 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<void*> CFX_PtrDiscreteArray; -typedef CFX_DiscreteArrayTemplate<uint32_t> CFX_DWordDiscreteArray; -typedef CFX_DiscreteArrayTemplate<uint16_t> 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 baseType> 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<void*> CFX_PtrStack; -typedef CFX_StackTemplate<uint32_t> CFX_DWordStack; -typedef CFX_StackTemplate<uint16_t> CFX_WordStack; -typedef CFX_StackTemplate<int32_t> CFX_Int32Stack; template <class baseType> 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(); } |