| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #ifndef XFA_FGAS_CRT_FGAS_UTILS_H_ | 7 #ifndef XFA_FGAS_CRT_FGAS_UTILS_H_ |
| 8 #define XFA_FGAS_CRT_FGAS_UTILS_H_ | 8 #define XFA_FGAS_CRT_FGAS_UTILS_H_ |
| 9 | 9 |
| 10 #include "core/fxcrt/include/fx_coordinates.h" | 10 #include "core/fxcrt/include/fx_coordinates.h" |
| 11 #include "xfa/fgas/crt/fgas_memory.h" | 11 #include "xfa/fgas/crt/fgas_memory.h" |
| 12 | 12 |
| 13 class FX_BASEARRAYDATA; | 13 class FX_BASEARRAYDATA; |
| 14 | 14 |
| 15 class CFX_BaseArray : public CFX_Target { | 15 class CFX_BaseArray : public CFX_Target { |
| 16 protected: | 16 protected: |
| 17 CFX_BaseArray(int32_t iGrowSize, int32_t iBlockSize); | 17 CFX_BaseArray(int32_t iGrowSize, int32_t iBlockSize); |
| 18 ~CFX_BaseArray() override; | 18 ~CFX_BaseArray() override; |
| 19 | 19 |
| 20 int32_t GetSize() const; | 20 int32_t GetSize() const; |
| 21 int32_t GetBlockSize() const; | 21 int32_t GetBlockSize() const; |
| 22 uint8_t* AddSpaceTo(int32_t index); | 22 uint8_t* AddSpaceTo(int32_t index); |
| 23 uint8_t* GetAt(int32_t index) const; | 23 uint8_t* GetAt(int32_t index) const; |
| 24 uint8_t* GetBuffer() const; | 24 uint8_t* GetBuffer() const; |
| 25 int32_t Append(const CFX_BaseArray& src, | 25 int32_t Append(const CFX_BaseArray& src, int32_t iStart, int32_t iCount); |
| 26 int32_t iStart = 0, | 26 int32_t Copy(const CFX_BaseArray& src, int32_t iStart, int32_t iCount); |
| 27 int32_t iCount = -1); | 27 int32_t RemoveLast(int32_t iCount); |
| 28 int32_t Copy(const CFX_BaseArray& src, | 28 void RemoveAll(FX_BOOL bLeaveMemory); |
| 29 int32_t iStart = 0, | |
| 30 int32_t iCount = -1); | |
| 31 int32_t RemoveLast(int32_t iCount = -1); | |
| 32 void RemoveAll(FX_BOOL bLeaveMemory = FALSE); | |
| 33 | 29 |
| 34 FX_BASEARRAYDATA* m_pData; | 30 FX_BASEARRAYDATA* m_pData; |
| 35 }; | 31 }; |
| 36 | 32 |
| 37 template <class baseType> | 33 template <class baseType> |
| 38 class CFX_BaseArrayTemplate : public CFX_BaseArray { | 34 class CFX_BaseArrayTemplate : public CFX_BaseArray { |
| 39 public: | 35 public: |
| 40 CFX_BaseArrayTemplate(int32_t iGrowSize = 100) | 36 CFX_BaseArrayTemplate(int32_t iGrowSize) |
| 41 : CFX_BaseArray(iGrowSize, sizeof(baseType)) {} | 37 : CFX_BaseArray(iGrowSize, sizeof(baseType)) {} |
| 42 CFX_BaseArrayTemplate(int32_t iGrowSize, int32_t iBlockSize) | 38 CFX_BaseArrayTemplate(int32_t iGrowSize, int32_t iBlockSize) |
| 43 : CFX_BaseArray(iGrowSize, iBlockSize) {} | 39 : CFX_BaseArray(iGrowSize, iBlockSize) {} |
| 40 |
| 44 int32_t GetSize() const { return CFX_BaseArray::GetSize(); } | 41 int32_t GetSize() const { return CFX_BaseArray::GetSize(); } |
| 45 int32_t GetBlockSize() const { return CFX_BaseArray::GetBlockSize(); } | 42 int32_t GetBlockSize() const { return CFX_BaseArray::GetBlockSize(); } |
| 46 baseType* AddSpace() { | 43 baseType* AddSpace() { |
| 47 return (baseType*)CFX_BaseArray::AddSpaceTo(CFX_BaseArray::GetSize()); | 44 return (baseType*)CFX_BaseArray::AddSpaceTo(CFX_BaseArray::GetSize()); |
| 48 } | 45 } |
| 49 int32_t Add(const baseType& element) { | 46 int32_t Add(const baseType& element) { |
| 50 int32_t index = CFX_BaseArray::GetSize(); | 47 int32_t index = CFX_BaseArray::GetSize(); |
| 51 *(baseType*)CFX_BaseArray::AddSpaceTo(index) = element; | 48 *(baseType*)CFX_BaseArray::AddSpaceTo(index) = element; |
| 52 return index; | 49 return index; |
| 53 } | 50 } |
| 54 baseType* GetBuffer() const { return (baseType*)CFX_BaseArray::GetBuffer(); } | 51 baseType* GetBuffer() const { return (baseType*)CFX_BaseArray::GetBuffer(); } |
| 55 baseType& GetAt(int32_t index) const { | 52 baseType& GetAt(int32_t index) const { |
| 56 return *(baseType*)CFX_BaseArray::GetAt(index); | 53 return *(baseType*)CFX_BaseArray::GetAt(index); |
| 57 } | 54 } |
| 58 baseType* GetPtrAt(int32_t index) const { | 55 baseType* GetPtrAt(int32_t index) const { |
| 59 return (baseType*)CFX_BaseArray::GetAt(index); | 56 return (baseType*)CFX_BaseArray::GetAt(index); |
| 60 } | 57 } |
| 61 void SetAt(int32_t index, const baseType& element) { | 58 void SetAt(int32_t index, const baseType& element) { |
| 62 *(baseType*)CFX_BaseArray::GetAt(index) = element; | 59 *(baseType*)CFX_BaseArray::GetAt(index) = element; |
| 63 } | 60 } |
| 64 void SetAtGrow(int32_t index, const baseType& element) { | 61 void SetAtGrow(int32_t index, const baseType& element) { |
| 65 *(baseType*)CFX_BaseArray::AddSpaceTo(index) = element; | 62 *(baseType*)CFX_BaseArray::AddSpaceTo(index) = element; |
| 66 } | 63 } |
| 67 int32_t Append(const CFX_BaseArrayTemplate& src, | 64 int32_t Append(const CFX_BaseArrayTemplate& src, |
| 68 int32_t iStart = 0, | 65 int32_t iStart, |
| 69 int32_t iCount = -1) { | 66 int32_t iCount) { |
| 70 return CFX_BaseArray::Append(src, iStart, iCount); | 67 return CFX_BaseArray::Append(src, iStart, iCount); |
| 71 } | 68 } |
| 72 int32_t Copy(const CFX_BaseArrayTemplate& src, | 69 int32_t Copy(const CFX_BaseArrayTemplate& src, |
| 73 int32_t iStart = 0, | 70 int32_t iStart, |
| 74 int32_t iCount = -1) { | 71 int32_t iCount) { |
| 75 return CFX_BaseArray::Copy(src, iStart, iCount); | 72 return CFX_BaseArray::Copy(src, iStart, iCount); |
| 76 } | 73 } |
| 77 int32_t RemoveLast(int32_t iCount = -1) { | 74 int32_t RemoveLast(int32_t iCount) { |
| 78 return CFX_BaseArray::RemoveLast(iCount); | 75 return CFX_BaseArray::RemoveLast(iCount); |
| 79 } | 76 } |
| 80 void RemoveAll(FX_BOOL bLeaveMemory = FALSE) { | 77 void RemoveAll(FX_BOOL bLeaveMemory) { |
| 81 CFX_BaseArray::RemoveAll(bLeaveMemory); | 78 CFX_BaseArray::RemoveAll(bLeaveMemory); |
| 82 } | 79 } |
| 83 }; | 80 }; |
| 84 | |
| 85 template <class baseType> | |
| 86 class CFX_ObjectBaseArrayTemplate : public CFX_BaseArray { | |
| 87 public: | |
| 88 CFX_ObjectBaseArrayTemplate(int32_t iGrowSize = 100) | |
| 89 : CFX_BaseArray(iGrowSize, sizeof(baseType)) {} | |
| 90 ~CFX_ObjectBaseArrayTemplate() { RemoveAll(FALSE); } | |
| 91 int32_t GetSize() const { return CFX_BaseArray::GetSize(); } | |
| 92 int32_t GetBlockSize() const { return CFX_BaseArray::GetBlockSize(); } | |
| 93 int32_t Add(const baseType& element) { | |
| 94 int32_t index = CFX_BaseArray::GetSize(); | |
| 95 baseType* p = (baseType*)CFX_BaseArray::AddSpaceTo(index); | |
| 96 new ((void*)p) baseType(element); | |
| 97 return index; | |
| 98 } | |
| 99 baseType& GetAt(int32_t index) const { | |
| 100 return *(baseType*)CFX_BaseArray::GetAt(index); | |
| 101 } | |
| 102 baseType* GetPtrAt(int32_t index) const { | |
| 103 return (baseType*)CFX_BaseArray::GetAt(index); | |
| 104 } | |
| 105 int32_t Append(const CFX_ObjectBaseArrayTemplate& src, | |
| 106 int32_t iStart = 0, | |
| 107 int32_t iCount = -1) { | |
| 108 ASSERT(GetBlockSize() == src.GetBlockSize()); | |
| 109 if (iCount == 0) { | |
| 110 return 0; | |
| 111 } | |
| 112 int32_t iSize = src.GetSize(); | |
| 113 ASSERT(iStart > -1 && iStart < iSize); | |
| 114 if (iCount < 0) { | |
| 115 iCount = iSize; | |
| 116 } | |
| 117 if (iStart + iCount > iSize) { | |
| 118 iCount = iSize - iStart; | |
| 119 } | |
| 120 if (iCount < 1) { | |
| 121 return 0; | |
| 122 } | |
| 123 iSize = CFX_BaseArray::GetSize(); | |
| 124 CFX_BaseArray::AddSpaceTo(iSize + iCount - 1); | |
| 125 uint8_t** pStart = CFX_BaseArray::GetAt(iSize); | |
| 126 int32_t iBlockSize = CFX_BaseArray::GetBlockSize(); | |
| 127 iSize = iStart + iCount; | |
| 128 for (int32_t i = iStart; i < iSize; i++) { | |
| 129 FXTARGET_NewWith((void*)pStart) baseType(src.GetAt(i)); | |
| 130 pStart += iBlockSize; | |
| 131 } | |
| 132 return iCount; | |
| 133 } | |
| 134 int32_t Copy(const CFX_ObjectBaseArrayTemplate& src, | |
| 135 int32_t iStart = 0, | |
| 136 int32_t iCount = -1) { | |
| 137 ASSERT(GetBlockSize() == src.GetBlockSize()); | |
| 138 if (iCount == 0) { | |
| 139 return 0; | |
| 140 } | |
| 141 int32_t iSize = src.GetSize(); | |
| 142 ASSERT(iStart > -1 && iStart < iSize); | |
| 143 if (iCount < 0) { | |
| 144 iCount = iSize; | |
| 145 } | |
| 146 if (iStart + iCount > iSize) { | |
| 147 iCount = iSize - iStart; | |
| 148 } | |
| 149 if (iCount < 1) { | |
| 150 return 0; | |
| 151 } | |
| 152 RemoveAll(TRUE); | |
| 153 CFX_BaseArray::AddSpaceTo(iCount - 1); | |
| 154 uint8_t** pStart = CFX_BaseArray::GetAt(0); | |
| 155 int32_t iBlockSize = CFX_BaseArray::GetBlockSize(); | |
| 156 iSize = iStart + iCount; | |
| 157 for (int32_t i = iStart; i < iSize; i++) { | |
| 158 new ((void*)pStart) baseType(src.GetAt(i)); | |
| 159 pStart += iBlockSize; | |
| 160 } | |
| 161 return iCount; | |
| 162 } | |
| 163 int32_t RemoveLast(int32_t iCount = -1) { | |
| 164 int32_t iSize = CFX_BaseArray::GetSize(); | |
| 165 if (iCount < 0 || iCount > iSize) { | |
| 166 iCount = iSize; | |
| 167 } | |
| 168 if (iCount == 0) { | |
| 169 return iSize; | |
| 170 } | |
| 171 for (int32_t i = iSize - iCount; i < iSize; i++) { | |
| 172 ((baseType*)GetPtrAt(i))->~baseType(); | |
| 173 } | |
| 174 return CFX_BaseArray::RemoveLast(iCount); | |
| 175 } | |
| 176 void RemoveAll(FX_BOOL bLeaveMemory = FALSE) { | |
| 177 int32_t iSize = CFX_BaseArray::GetSize(); | |
| 178 for (int32_t i = 0; i < iSize; i++) { | |
| 179 ((baseType*)GetPtrAt(i))->~baseType(); | |
| 180 } | |
| 181 CFX_BaseArray::RemoveAll(bLeaveMemory); | |
| 182 } | |
| 183 }; | |
| 184 | 81 |
| 185 class CFX_BaseMassArrayImp : public CFX_Target { | 82 class CFX_BaseMassArrayImp : public CFX_Target { |
| 186 public: | 83 public: |
| 187 CFX_BaseMassArrayImp(int32_t iChunkSize, int32_t iBlockSize); | 84 CFX_BaseMassArrayImp(int32_t iChunkSize, int32_t iBlockSize); |
| 188 ~CFX_BaseMassArrayImp() override; | 85 ~CFX_BaseMassArrayImp() override; |
| 189 | 86 |
| 190 uint8_t* AddSpace() { return AddSpaceTo(m_iBlockCount); } | 87 uint8_t* AddSpace() { return AddSpaceTo(m_iBlockCount); } |
| 191 uint8_t* AddSpaceTo(int32_t index); | 88 uint8_t* AddSpaceTo(int32_t index); |
| 192 uint8_t* GetAt(int32_t index) const; | 89 uint8_t* GetAt(int32_t index) const; |
| 193 int32_t Append(const CFX_BaseMassArrayImp& src, | 90 int32_t Append(const CFX_BaseMassArrayImp& src, |
| 194 int32_t iStart = 0, | 91 int32_t iStart, |
| 195 int32_t iCount = -1); | 92 int32_t iCount); |
| 196 int32_t Copy(const CFX_BaseMassArrayImp& src, | 93 int32_t Copy(const CFX_BaseMassArrayImp& src, int32_t iStart, int32_t iCount); |
| 197 int32_t iStart = 0, | 94 int32_t RemoveLast(int32_t iCount); |
| 198 int32_t iCount = -1); | 95 void RemoveAll(FX_BOOL bLeaveMemory); |
| 199 int32_t RemoveLast(int32_t iCount = -1); | |
| 200 void RemoveAll(FX_BOOL bLeaveMemory = FALSE); | |
| 201 | 96 |
| 202 int32_t m_iChunkSize; | 97 int32_t m_iChunkSize; |
| 203 int32_t m_iBlockSize; | 98 int32_t m_iBlockSize; |
| 204 int32_t m_iChunkCount; | 99 int32_t m_iChunkCount; |
| 205 int32_t m_iBlockCount; | 100 int32_t m_iBlockCount; |
| 206 CFX_ArrayTemplate<void*>* m_pData; | 101 CFX_ArrayTemplate<void*>* m_pData; |
| 207 | 102 |
| 208 protected: | 103 protected: |
| 209 void Append(int32_t iDstStart, | 104 void Append(int32_t iDstStart, |
| 210 const CFX_BaseMassArrayImp& src, | 105 const CFX_BaseMassArrayImp& src, |
| 211 int32_t iSrcStart = 0, | 106 int32_t iSrcStart, |
| 212 int32_t iSrcCount = -1); | 107 int32_t iSrcCount); |
| 213 }; | 108 }; |
| 214 | 109 |
| 215 class CFX_BaseMassArray : public CFX_Target { | 110 class CFX_BaseMassArray : public CFX_Target { |
| 216 protected: | 111 protected: |
| 217 CFX_BaseMassArray(int32_t iChunkSize, int32_t iBlockSize); | 112 CFX_BaseMassArray(int32_t iChunkSize, int32_t iBlockSize); |
| 218 ~CFX_BaseMassArray() override; | 113 ~CFX_BaseMassArray() override; |
| 219 | 114 |
| 220 int32_t GetSize() const; | 115 int32_t GetSize() const; |
| 221 uint8_t* AddSpaceTo(int32_t index); | 116 uint8_t* AddSpaceTo(int32_t index); |
| 222 uint8_t* GetAt(int32_t index) const; | 117 uint8_t* GetAt(int32_t index) const; |
| 223 int32_t Append(const CFX_BaseMassArray& src, | 118 int32_t Append(const CFX_BaseMassArray& src, int32_t iStart, int32_t iCount); |
| 224 int32_t iStart = 0, | 119 int32_t Copy(const CFX_BaseMassArray& src, int32_t iStart, int32_t iCount); |
| 225 int32_t iCount = -1); | 120 int32_t RemoveLast(int32_t iCount); |
| 226 int32_t Copy(const CFX_BaseMassArray& src, | 121 void RemoveAll(FX_BOOL bLeaveMemory); |
| 227 int32_t iStart = 0, | |
| 228 int32_t iCount = -1); | |
| 229 int32_t RemoveLast(int32_t iCount = -1); | |
| 230 void RemoveAll(FX_BOOL bLeaveMemory = FALSE); | |
| 231 CFX_BaseMassArrayImp* m_pData; | 122 CFX_BaseMassArrayImp* m_pData; |
| 232 }; | 123 }; |
| 233 | 124 |
| 234 template <class baseType> | 125 template <class baseType> |
| 235 class CFX_MassArrayTemplate : public CFX_BaseMassArray { | 126 class CFX_MassArrayTemplate : public CFX_BaseMassArray { |
| 236 public: | 127 public: |
| 237 CFX_MassArrayTemplate(int32_t iChunkSize = 100) | 128 CFX_MassArrayTemplate(int32_t iChunkSize) |
| 238 : CFX_BaseMassArray(iChunkSize, sizeof(baseType)) {} | 129 : CFX_BaseMassArray(iChunkSize, sizeof(baseType)) {} |
| 239 CFX_MassArrayTemplate(int32_t iChunkSize, int32_t iBlockSize) | 130 CFX_MassArrayTemplate(int32_t iChunkSize, int32_t iBlockSize) |
| 240 : CFX_BaseMassArray(iChunkSize, iBlockSize) {} | 131 : CFX_BaseMassArray(iChunkSize, iBlockSize) {} |
| 132 |
| 241 int32_t GetSize() const { return CFX_BaseMassArray::GetSize(); } | 133 int32_t GetSize() const { return CFX_BaseMassArray::GetSize(); } |
| 242 baseType* AddSpace() { | 134 baseType* AddSpace() { |
| 243 return (baseType*)CFX_BaseMassArray::AddSpaceTo( | 135 return (baseType*)CFX_BaseMassArray::AddSpaceTo( |
| 244 CFX_BaseMassArray::GetSize()); | 136 CFX_BaseMassArray::GetSize()); |
| 245 } | 137 } |
| 246 int32_t Add(const baseType& element) { | 138 int32_t Add(const baseType& element) { |
| 247 int32_t index = CFX_BaseMassArray::GetSize(); | 139 int32_t index = CFX_BaseMassArray::GetSize(); |
| 248 *(baseType*)CFX_BaseMassArray::AddSpaceTo(index) = element; | 140 *(baseType*)CFX_BaseMassArray::AddSpaceTo(index) = element; |
| 249 return index; | 141 return index; |
| 250 } | 142 } |
| 251 baseType& GetAt(int32_t index) const { | 143 baseType& GetAt(int32_t index) const { |
| 252 return *(baseType*)CFX_BaseMassArray::GetAt(index); | 144 return *(baseType*)CFX_BaseMassArray::GetAt(index); |
| 253 } | 145 } |
| 254 baseType* GetPtrAt(int32_t index) const { | 146 baseType* GetPtrAt(int32_t index) const { |
| 255 return (baseType*)CFX_BaseMassArray::GetAt(index); | 147 return (baseType*)CFX_BaseMassArray::GetAt(index); |
| 256 } | 148 } |
| 257 void SetAt(int32_t index, const baseType& element) { | 149 void SetAt(int32_t index, const baseType& element) { |
| 258 *(baseType*)CFX_BaseMassArray::GetAt(index) = element; | 150 *(baseType*)CFX_BaseMassArray::GetAt(index) = element; |
| 259 } | 151 } |
| 260 void SetAtGrow(int32_t index, const baseType& element) { | 152 void SetAtGrow(int32_t index, const baseType& element) { |
| 261 *(baseType*)CFX_BaseMassArray::AddSpaceTo(index) = element; | 153 *(baseType*)CFX_BaseMassArray::AddSpaceTo(index) = element; |
| 262 } | 154 } |
| 263 int32_t Append(const CFX_MassArrayTemplate& src, | 155 int32_t Append(const CFX_MassArrayTemplate& src, |
| 264 int32_t iStart = 0, | 156 int32_t iStart, |
| 265 int32_t iCount = -1) { | 157 int32_t iCount) { |
| 266 return CFX_BaseMassArray::Append(src, iStart, iCount); | 158 return CFX_BaseMassArray::Append(src, iStart, iCount); |
| 267 } | 159 } |
| 268 int32_t Copy(const CFX_MassArrayTemplate& src, | 160 int32_t Copy(const CFX_MassArrayTemplate& src, |
| 269 int32_t iStart = 0, | 161 int32_t iStart, |
| 270 int32_t iCount = -1) { | 162 int32_t iCount) { |
| 271 return CFX_BaseMassArray::Copy(src, iStart, iCount); | 163 return CFX_BaseMassArray::Copy(src, iStart, iCount); |
| 272 } | 164 } |
| 273 int32_t RemoveLast(int32_t iCount = -1) { | 165 int32_t RemoveLast(int32_t iCount) { |
| 274 return CFX_BaseMassArray::RemoveLast(iCount); | 166 return CFX_BaseMassArray::RemoveLast(iCount); |
| 275 } | 167 } |
| 276 void RemoveAll(FX_BOOL bLeaveMemory = FALSE) { | 168 void RemoveAll(FX_BOOL bLeaveMemory) { |
| 277 CFX_BaseMassArray::RemoveAll(bLeaveMemory); | 169 CFX_BaseMassArray::RemoveAll(bLeaveMemory); |
| 278 } | 170 } |
| 279 }; | 171 }; |
| 280 | 172 |
| 281 template <class baseType> | 173 template <class baseType> |
| 282 class CFX_ObjectMassArrayTemplate : public CFX_BaseMassArray { | 174 class CFX_ObjectMassArrayTemplate : public CFX_BaseMassArray { |
| 283 public: | 175 public: |
| 284 CFX_ObjectMassArrayTemplate(int32_t iChunkSize = 100) | 176 CFX_ObjectMassArrayTemplate(int32_t iChunkSize) |
| 285 : CFX_BaseMassArray(iChunkSize, sizeof(baseType)) {} | 177 : CFX_BaseMassArray(iChunkSize, sizeof(baseType)) {} |
| 286 ~CFX_ObjectMassArrayTemplate() { RemoveAll(FALSE); } | 178 ~CFX_ObjectMassArrayTemplate() { RemoveAll(FALSE); } |
| 179 |
| 287 int32_t GetSize() const { return CFX_BaseMassArray::GetSize(); } | 180 int32_t GetSize() const { return CFX_BaseMassArray::GetSize(); } |
| 288 int32_t Add(const baseType& element) { | 181 int32_t Add(const baseType& element) { |
| 289 int32_t index = CFX_BaseMassArray::GetSize(); | 182 int32_t index = CFX_BaseMassArray::GetSize(); |
| 290 baseType* p = (baseType*)CFX_BaseMassArray::AddSpaceTo(index); | 183 baseType* p = (baseType*)CFX_BaseMassArray::AddSpaceTo(index); |
| 291 new ((void*)p) baseType(element); | 184 new ((void*)p) baseType(element); |
| 292 return index; | 185 return index; |
| 293 } | 186 } |
| 294 baseType& GetAt(int32_t index) const { | 187 baseType& GetAt(int32_t index) const { |
| 295 return *(baseType*)CFX_BaseMassArray::GetAt(index); | 188 return *(baseType*)CFX_BaseMassArray::GetAt(index); |
| 296 } | 189 } |
| 297 baseType* GetPtrAt(int32_t index) const { | 190 baseType* GetPtrAt(int32_t index) const { |
| 298 return (baseType*)CFX_BaseMassArray::GetAt(index); | 191 return (baseType*)CFX_BaseMassArray::GetAt(index); |
| 299 } | 192 } |
| 300 int32_t Append(const CFX_ObjectMassArrayTemplate& src, | 193 int32_t Append(const CFX_ObjectMassArrayTemplate& src, |
| 301 int32_t iStart = 0, | 194 int32_t iStart, |
| 302 int32_t iCount = -1) { | 195 int32_t iCount) { |
| 303 if (iCount == 0) { | 196 if (iCount == 0) { |
| 304 return CFX_BaseMassArray::GetSize(); | 197 return CFX_BaseMassArray::GetSize(); |
| 305 } | 198 } |
| 306 int32_t iSize = src.GetSize(); | 199 int32_t iSize = src.GetSize(); |
| 307 ASSERT(iStart > -1 && iStart < iSize); | 200 ASSERT(iStart > -1 && iStart < iSize); |
| 308 if (iCount < 0) { | 201 if (iCount < 0) { |
| 309 iCount = iSize; | 202 iCount = iSize; |
| 310 } | 203 } |
| 311 int32_t iEnd = iStart + iCount; | 204 int32_t iEnd = iStart + iCount; |
| 312 if (iEnd > iSize) { | 205 if (iEnd > iSize) { |
| 313 iEnd = iSize; | 206 iEnd = iSize; |
| 314 } | 207 } |
| 315 for (int32_t i = iStart; i < iEnd; i++) { | 208 for (int32_t i = iStart; i < iEnd; i++) { |
| 316 Add(src.GetAt(i)); | 209 Add(src.GetAt(i)); |
| 317 } | 210 } |
| 318 return CFX_BaseMassArray::GetSize(); | 211 return CFX_BaseMassArray::GetSize(); |
| 319 } | 212 } |
| 320 int32_t Copy(const CFX_ObjectMassArrayTemplate& src, | 213 int32_t Copy(const CFX_ObjectMassArrayTemplate& src, |
| 321 int32_t iStart = 0, | 214 int32_t iStart, |
| 322 int32_t iCount = -1) { | 215 int32_t iCount) { |
| 323 if (iCount == 0) { | 216 if (iCount == 0) { |
| 324 return CFX_BaseMassArray::GetSize(); | 217 return CFX_BaseMassArray::GetSize(); |
| 325 } | 218 } |
| 326 int32_t iSize = src.GetSize(); | 219 int32_t iSize = src.GetSize(); |
| 327 ASSERT(iStart > -1 && iStart < iSize); | 220 ASSERT(iStart > -1 && iStart < iSize); |
| 328 if (iCount < 0) { | 221 if (iCount < 0) { |
| 329 iCount = iSize; | 222 iCount = iSize; |
| 330 } | 223 } |
| 331 int32_t iEnd = iStart + iCount; | 224 int32_t iEnd = iStart + iCount; |
| 332 if (iEnd > iSize) { | 225 if (iEnd > iSize) { |
| 333 iEnd = iSize; | 226 iEnd = iSize; |
| 334 } | 227 } |
| 335 RemoveAll(TRUE); | 228 RemoveAll(TRUE); |
| 336 for (int32_t i = iStart; i < iEnd; i++) { | 229 for (int32_t i = iStart; i < iEnd; i++) { |
| 337 Add(src.GetAt(i)); | 230 Add(src.GetAt(i)); |
| 338 } | 231 } |
| 339 return CFX_BaseMassArray::GetSize(); | 232 return CFX_BaseMassArray::GetSize(); |
| 340 } | 233 } |
| 341 int32_t RemoveLast(int32_t iCount = -1) { | 234 int32_t RemoveLast(int32_t iCount) { |
| 342 int32_t iSize = CFX_BaseMassArray::GetSize(); | 235 int32_t iSize = CFX_BaseMassArray::GetSize(); |
| 343 if (iCount < 0 || iCount > iSize) { | 236 if (iCount < 0 || iCount > iSize) { |
| 344 iCount = iSize; | 237 iCount = iSize; |
| 345 } | 238 } |
| 346 if (iCount == 0) { | 239 if (iCount == 0) { |
| 347 return iSize; | 240 return iSize; |
| 348 } | 241 } |
| 349 for (int32_t i = iSize - iCount; i < iSize; i++) { | 242 for (int32_t i = iSize - iCount; i < iSize; i++) { |
| 350 ((baseType*)GetPtrAt(i))->~baseType(); | 243 ((baseType*)GetPtrAt(i))->~baseType(); |
| 351 } | 244 } |
| 352 return CFX_BaseMassArray::RemoveLast(iCount); | 245 return CFX_BaseMassArray::RemoveLast(iCount); |
| 353 } | 246 } |
| 354 void RemoveAll(FX_BOOL bLeaveMemory = FALSE) { | 247 void RemoveAll(FX_BOOL bLeaveMemory) { |
| 355 int32_t iSize = CFX_BaseMassArray::GetSize(); | 248 int32_t iSize = CFX_BaseMassArray::GetSize(); |
| 356 for (int32_t i = 0; i < iSize; i++) { | 249 for (int32_t i = 0; i < iSize; i++) { |
| 357 ((baseType*)GetPtrAt(i))->~baseType(); | 250 ((baseType*)GetPtrAt(i))->~baseType(); |
| 358 } | 251 } |
| 359 CFX_BaseMassArray::RemoveAll(bLeaveMemory); | 252 CFX_BaseMassArray::RemoveAll(bLeaveMemory); |
| 360 } | 253 } |
| 361 }; | 254 }; |
| 362 | 255 |
| 363 class CFX_BaseDiscreteArray : public CFX_Target { | 256 class CFX_BaseDiscreteArray : public CFX_Target { |
| 364 protected: | 257 protected: |
| 365 CFX_BaseDiscreteArray(int32_t iChunkSize, int32_t iBlockSize); | 258 CFX_BaseDiscreteArray(int32_t iChunkSize, int32_t iBlockSize); |
| 366 ~CFX_BaseDiscreteArray() override; | 259 ~CFX_BaseDiscreteArray() override; |
| 367 | 260 |
| 368 uint8_t* AddSpaceTo(int32_t index); | 261 uint8_t* AddSpaceTo(int32_t index); |
| 369 uint8_t* GetAt(int32_t index) const; | 262 uint8_t* GetAt(int32_t index) const; |
| 370 void RemoveAll(); | 263 void RemoveAll(); |
| 371 void* m_pData; | 264 void* m_pData; |
| 372 }; | 265 }; |
| 373 | 266 |
| 374 template <class baseType> | 267 template <class baseType> |
| 375 class CFX_DiscreteArrayTemplate : public CFX_BaseDiscreteArray { | 268 class CFX_DiscreteArrayTemplate : public CFX_BaseDiscreteArray { |
| 376 public: | 269 public: |
| 377 CFX_DiscreteArrayTemplate(int32_t iChunkSize = 100) | 270 CFX_DiscreteArrayTemplate(int32_t iChunkSize) |
| 378 : CFX_BaseDiscreteArray(iChunkSize, sizeof(baseType)) {} | 271 : CFX_BaseDiscreteArray(iChunkSize, sizeof(baseType)) {} |
| 272 |
| 379 baseType& GetAt(int32_t index, const baseType& defValue) const { | 273 baseType& GetAt(int32_t index, const baseType& defValue) const { |
| 380 baseType* p = (baseType*)CFX_BaseDiscreteArray::GetAt(index); | 274 baseType* p = (baseType*)CFX_BaseDiscreteArray::GetAt(index); |
| 381 return p ? *p : (baseType&)defValue; | 275 return p ? *p : (baseType&)defValue; |
| 382 } | 276 } |
| 383 baseType* GetPtrAt(int32_t index) const { | 277 baseType* GetPtrAt(int32_t index) const { |
| 384 return (baseType*)CFX_BaseDiscreteArray::GetAt(index); | 278 return (baseType*)CFX_BaseDiscreteArray::GetAt(index); |
| 385 } | 279 } |
| 386 void SetAtGrow(int32_t index, const baseType& element) { | 280 void SetAtGrow(int32_t index, const baseType& element) { |
| 387 *(baseType*)CFX_BaseDiscreteArray::AddSpaceTo(index) = element; | 281 *(baseType*)CFX_BaseDiscreteArray::AddSpaceTo(index) = element; |
| 388 } | 282 } |
| 389 void RemoveAll() { CFX_BaseDiscreteArray::RemoveAll(); } | 283 void RemoveAll() { CFX_BaseDiscreteArray::RemoveAll(); } |
| 390 }; | 284 }; |
| 391 typedef CFX_DiscreteArrayTemplate<void*> CFX_PtrDiscreteArray; | |
| 392 typedef CFX_DiscreteArrayTemplate<uint32_t> CFX_DWordDiscreteArray; | |
| 393 typedef CFX_DiscreteArrayTemplate<uint16_t> CFX_WordDiscreteArray; | |
| 394 | 285 |
| 395 class CFX_BaseStack : public CFX_Target { | 286 class CFX_BaseStack : public CFX_Target { |
| 396 protected: | 287 protected: |
| 397 CFX_BaseStack(int32_t iChunkSize, int32_t iBlockSize); | 288 CFX_BaseStack(int32_t iChunkSize, int32_t iBlockSize); |
| 398 ~CFX_BaseStack() override; | 289 ~CFX_BaseStack() override; |
| 399 | 290 |
| 400 uint8_t* Push(); | 291 uint8_t* Push(); |
| 401 void Pop(); | 292 void Pop(); |
| 402 uint8_t* GetTopElement() const; | 293 uint8_t* GetTopElement() const; |
| 403 int32_t GetSize() const; | 294 int32_t GetSize() const; |
| 404 uint8_t* GetAt(int32_t index) const; | 295 uint8_t* GetAt(int32_t index) const; |
| 405 void RemoveAll(FX_BOOL bLeaveMemory = FALSE); | 296 void RemoveAll(FX_BOOL bLeaveMemory); |
| 406 CFX_BaseMassArrayImp* m_pData; | 297 CFX_BaseMassArrayImp* m_pData; |
| 407 }; | 298 }; |
| 408 | 299 |
| 409 template <class baseType> | 300 template <class baseType> |
| 410 class CFX_StackTemplate : public CFX_BaseStack { | 301 class CFX_StackTemplate : public CFX_BaseStack { |
| 411 public: | 302 public: |
| 412 CFX_StackTemplate(int32_t iChunkSize = 100) | 303 CFX_StackTemplate(int32_t iChunkSize) |
| 413 : CFX_BaseStack(iChunkSize, sizeof(baseType)) {} | 304 : CFX_BaseStack(iChunkSize, sizeof(baseType)) {} |
| 305 |
| 414 int32_t Push(const baseType& element) { | 306 int32_t Push(const baseType& element) { |
| 415 int32_t index = CFX_BaseStack::GetSize(); | 307 int32_t index = CFX_BaseStack::GetSize(); |
| 416 *(baseType*)CFX_BaseStack::Push() = element; | 308 *(baseType*)CFX_BaseStack::Push() = element; |
| 417 return index; | 309 return index; |
| 418 } | 310 } |
| 419 void Pop() { CFX_BaseStack::Pop(); } | 311 void Pop() { CFX_BaseStack::Pop(); } |
| 420 baseType* GetTopElement() const { | 312 baseType* GetTopElement() const { |
| 421 return (baseType*)CFX_BaseStack::GetTopElement(); | 313 return (baseType*)CFX_BaseStack::GetTopElement(); |
| 422 } | 314 } |
| 423 int32_t GetSize() const { return CFX_BaseStack::GetSize(); } | 315 int32_t GetSize() const { return CFX_BaseStack::GetSize(); } |
| 424 baseType* GetAt(int32_t index) const { | 316 baseType* GetAt(int32_t index) const { |
| 425 return (baseType*)CFX_BaseStack::GetAt(index); | 317 return (baseType*)CFX_BaseStack::GetAt(index); |
| 426 } | 318 } |
| 427 void RemoveAll(FX_BOOL bLeaveMemory = FALSE) { | 319 void RemoveAll(FX_BOOL bLeaveMemory) { |
| 428 CFX_BaseStack::RemoveAll(bLeaveMemory); | 320 CFX_BaseStack::RemoveAll(bLeaveMemory); |
| 429 } | 321 } |
| 430 }; | 322 }; |
| 431 typedef CFX_StackTemplate<void*> CFX_PtrStack; | |
| 432 typedef CFX_StackTemplate<uint32_t> CFX_DWordStack; | |
| 433 typedef CFX_StackTemplate<uint16_t> CFX_WordStack; | |
| 434 typedef CFX_StackTemplate<int32_t> CFX_Int32Stack; | |
| 435 | 323 |
| 436 template <class baseType> | 324 template <class baseType> |
| 437 class CFX_ObjectStackTemplate : public CFX_BaseStack { | 325 class CFX_ObjectStackTemplate : public CFX_BaseStack { |
| 438 public: | 326 public: |
| 439 CFX_ObjectStackTemplate(int32_t iChunkSize = 100) | 327 CFX_ObjectStackTemplate(int32_t iChunkSize) |
| 440 : CFX_BaseStack(iChunkSize, sizeof(baseType)) {} | 328 : CFX_BaseStack(iChunkSize, sizeof(baseType)) {} |
| 441 ~CFX_ObjectStackTemplate() { RemoveAll(); } | 329 ~CFX_ObjectStackTemplate() { RemoveAll(FALSE); } |
| 330 |
| 442 int32_t Push(const baseType& element) { | 331 int32_t Push(const baseType& element) { |
| 443 int32_t index = CFX_BaseStack::GetSize(); | 332 int32_t index = CFX_BaseStack::GetSize(); |
| 444 baseType* p = (baseType*)CFX_BaseStack::Push(); | 333 baseType* p = (baseType*)CFX_BaseStack::Push(); |
| 445 new ((void*)p) baseType(element); | 334 new ((void*)p) baseType(element); |
| 446 return index; | 335 return index; |
| 447 } | 336 } |
| 448 void Pop() { | 337 void Pop() { |
| 449 baseType* p = (baseType*)CFX_BaseStack::GetTopElement(); | 338 baseType* p = (baseType*)CFX_BaseStack::GetTopElement(); |
| 450 if (p) { | 339 if (p) { |
| 451 p->~baseType(); | 340 p->~baseType(); |
| 452 } | 341 } |
| 453 CFX_BaseStack::Pop(); | 342 CFX_BaseStack::Pop(); |
| 454 } | 343 } |
| 455 baseType* GetTopElement() const { | 344 baseType* GetTopElement() const { |
| 456 return (baseType*)CFX_BaseStack::GetTopElement(); | 345 return (baseType*)CFX_BaseStack::GetTopElement(); |
| 457 } | 346 } |
| 458 int32_t GetSize() const { return CFX_BaseStack::GetSize(); } | 347 int32_t GetSize() const { return CFX_BaseStack::GetSize(); } |
| 459 baseType* GetAt(int32_t index) const { | 348 baseType* GetAt(int32_t index) const { |
| 460 return (baseType*)CFX_BaseStack::GetAt(index); | 349 return (baseType*)CFX_BaseStack::GetAt(index); |
| 461 } | 350 } |
| 462 void RemoveAll(FX_BOOL bLeaveMemory = FALSE) { | 351 void RemoveAll(FX_BOOL bLeaveMemory) { |
| 463 int32_t iSize = CFX_BaseStack::GetSize(); | 352 int32_t iSize = CFX_BaseStack::GetSize(); |
| 464 for (int32_t i = 0; i < iSize; i++) { | 353 for (int32_t i = 0; i < iSize; i++) { |
| 465 ((baseType*)CFX_BaseStack::GetAt(i))->~baseType(); | 354 ((baseType*)CFX_BaseStack::GetAt(i))->~baseType(); |
| 466 } | 355 } |
| 467 CFX_BaseStack::RemoveAll(bLeaveMemory); | 356 CFX_BaseStack::RemoveAll(bLeaveMemory); |
| 468 } | 357 } |
| 469 int32_t Copy(const CFX_ObjectStackTemplate& src, | 358 int32_t Copy(const CFX_ObjectStackTemplate& src, |
| 470 int32_t iStart = 0, | 359 int32_t iStart, |
| 471 int32_t iCount = -1) { | 360 int32_t iCount) { |
| 472 if (iCount == 0) { | 361 if (iCount == 0) { |
| 473 return CFX_BaseStack::GetSize(); | 362 return CFX_BaseStack::GetSize(); |
| 474 } | 363 } |
| 475 int32_t iSize = src.GetSize(); | 364 int32_t iSize = src.GetSize(); |
| 476 ASSERT(iStart > -1 && iStart < iSize); | 365 ASSERT(iStart > -1 && iStart < iSize); |
| 477 if (iCount < 0) { | 366 if (iCount < 0) { |
| 478 iCount = iSize; | 367 iCount = iSize; |
| 479 } | 368 } |
| 480 int32_t iEnd = iStart + iCount; | 369 int32_t iEnd = iStart + iCount; |
| 481 if (iEnd > iSize) { | 370 if (iEnd > iSize) { |
| 482 iEnd = iSize; | 371 iEnd = iSize; |
| 483 } | 372 } |
| 484 RemoveAll(TRUE); | 373 RemoveAll(TRUE); |
| 485 for (int32_t i = iStart; i < iEnd; i++) { | 374 for (int32_t i = iStart; i < iEnd; i++) { |
| 486 Push(*src.GetAt(i)); | 375 Push(*src.GetAt(i)); |
| 487 } | 376 } |
| 488 return CFX_BaseStack::GetSize(); | 377 return CFX_BaseStack::GetSize(); |
| 489 } | 378 } |
| 490 }; | 379 }; |
| 491 | 380 |
| 492 #endif // XFA_FGAS_CRT_FGAS_UTILS_H_ | 381 #endif // XFA_FGAS_CRT_FGAS_UTILS_H_ |
| OLD | NEW |