| 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 CORE_FXCRT_FX_BASIC_H_ | 7 #ifndef CORE_FXCRT_FX_BASIC_H_ |
| 8 #define CORE_FXCRT_FX_BASIC_H_ | 8 #define CORE_FXCRT_FX_BASIC_H_ |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 protected: | 175 protected: |
| 176 CFX_ByteTextBuf m_Buffer; | 176 CFX_ByteTextBuf m_Buffer; |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 class CFX_BasicArray { | 179 class CFX_BasicArray { |
| 180 protected: | 180 protected: |
| 181 explicit CFX_BasicArray(int unit_size); | 181 explicit CFX_BasicArray(int unit_size); |
| 182 CFX_BasicArray(const CFX_BasicArray&) = delete; | 182 CFX_BasicArray(const CFX_BasicArray&) = delete; |
| 183 ~CFX_BasicArray(); | 183 ~CFX_BasicArray(); |
| 184 | 184 |
| 185 FX_BOOL SetSize(int nNewSize); | 185 bool SetSize(int nNewSize); |
| 186 FX_BOOL Append(const CFX_BasicArray& src); | 186 bool Append(const CFX_BasicArray& src); |
| 187 FX_BOOL Copy(const CFX_BasicArray& src); | 187 bool Copy(const CFX_BasicArray& src); |
| 188 uint8_t* InsertSpaceAt(int nIndex, int nCount); | 188 uint8_t* InsertSpaceAt(int nIndex, int nCount); |
| 189 FX_BOOL RemoveAt(int nIndex, int nCount); | 189 bool RemoveAt(int nIndex, int nCount); |
| 190 FX_BOOL InsertAt(int nStartIndex, const CFX_BasicArray* pNewArray); | 190 bool InsertAt(int nStartIndex, const CFX_BasicArray* pNewArray); |
| 191 const void* GetDataPtr(int index) const; | 191 const void* GetDataPtr(int index) const; |
| 192 | 192 |
| 193 protected: | 193 protected: |
| 194 uint8_t* m_pData; | 194 uint8_t* m_pData; |
| 195 int m_nSize; | 195 int m_nSize; |
| 196 int m_nMaxSize; | 196 int m_nMaxSize; |
| 197 int m_nUnitSize; | 197 int m_nUnitSize; |
| 198 }; | 198 }; |
| 199 | 199 |
| 200 template <class TYPE> | 200 template <class TYPE> |
| 201 class CFX_ArrayTemplate : public CFX_BasicArray { | 201 class CFX_ArrayTemplate : public CFX_BasicArray { |
| 202 public: | 202 public: |
| 203 CFX_ArrayTemplate() : CFX_BasicArray(sizeof(TYPE)) {} | 203 CFX_ArrayTemplate() : CFX_BasicArray(sizeof(TYPE)) {} |
| 204 | 204 |
| 205 int GetSize() const { return m_nSize; } | 205 int GetSize() const { return m_nSize; } |
| 206 | 206 |
| 207 int GetUpperBound() const { return m_nSize - 1; } | 207 int GetUpperBound() const { return m_nSize - 1; } |
| 208 | 208 |
| 209 FX_BOOL SetSize(int nNewSize) { return CFX_BasicArray::SetSize(nNewSize); } | 209 bool SetSize(int nNewSize) { return CFX_BasicArray::SetSize(nNewSize); } |
| 210 | 210 |
| 211 void RemoveAll() { SetSize(0); } | 211 void RemoveAll() { SetSize(0); } |
| 212 | 212 |
| 213 const TYPE GetAt(int nIndex) const { | 213 const TYPE GetAt(int nIndex) const { |
| 214 if (nIndex < 0 || nIndex >= m_nSize) { | 214 if (nIndex < 0 || nIndex >= m_nSize) { |
| 215 PDFIUM_IMMEDIATE_CRASH(); | 215 PDFIUM_IMMEDIATE_CRASH(); |
| 216 } | 216 } |
| 217 return ((const TYPE*)m_pData)[nIndex]; | 217 return ((const TYPE*)m_pData)[nIndex]; |
| 218 } | 218 } |
| 219 | 219 |
| 220 FX_BOOL SetAt(int nIndex, TYPE newElement) { | 220 bool SetAt(int nIndex, TYPE newElement) { |
| 221 if (nIndex < 0 || nIndex >= m_nSize) { | 221 if (nIndex < 0 || nIndex >= m_nSize) { |
| 222 return FALSE; | 222 return false; |
| 223 } | 223 } |
| 224 ((TYPE*)m_pData)[nIndex] = newElement; | 224 ((TYPE*)m_pData)[nIndex] = newElement; |
| 225 return TRUE; | 225 return true; |
| 226 } | 226 } |
| 227 | 227 |
| 228 TYPE& ElementAt(int nIndex) { | 228 TYPE& ElementAt(int nIndex) { |
| 229 if (nIndex < 0 || nIndex >= m_nSize) { | 229 if (nIndex < 0 || nIndex >= m_nSize) { |
| 230 PDFIUM_IMMEDIATE_CRASH(); | 230 PDFIUM_IMMEDIATE_CRASH(); |
| 231 } | 231 } |
| 232 return ((TYPE*)m_pData)[nIndex]; | 232 return ((TYPE*)m_pData)[nIndex]; |
| 233 } | 233 } |
| 234 | 234 |
| 235 const TYPE* GetData() const { return (const TYPE*)m_pData; } | 235 const TYPE* GetData() const { return (const TYPE*)m_pData; } |
| 236 | 236 |
| 237 TYPE* GetData() { return (TYPE*)m_pData; } | 237 TYPE* GetData() { return (TYPE*)m_pData; } |
| 238 | 238 |
| 239 FX_BOOL SetAtGrow(int nIndex, TYPE newElement) { | 239 bool SetAtGrow(int nIndex, TYPE newElement) { |
| 240 if (nIndex < 0) | 240 if (nIndex < 0) |
| 241 return FALSE; | 241 return false; |
| 242 | 242 |
| 243 if (nIndex >= m_nSize && !SetSize(nIndex + 1)) | 243 if (nIndex >= m_nSize && !SetSize(nIndex + 1)) |
| 244 return FALSE; | 244 return false; |
| 245 | 245 |
| 246 ((TYPE*)m_pData)[nIndex] = newElement; | 246 ((TYPE*)m_pData)[nIndex] = newElement; |
| 247 return TRUE; | 247 return true; |
| 248 } | 248 } |
| 249 | 249 |
| 250 FX_BOOL Add(TYPE newElement) { | 250 bool Add(TYPE newElement) { |
| 251 if (m_nSize < m_nMaxSize) { | 251 if (m_nSize < m_nMaxSize) { |
| 252 m_nSize++; | 252 m_nSize++; |
| 253 } else if (!SetSize(m_nSize + 1)) { | 253 } else if (!SetSize(m_nSize + 1)) { |
| 254 return FALSE; | 254 return false; |
| 255 } | 255 } |
| 256 ((TYPE*)m_pData)[m_nSize - 1] = newElement; | 256 ((TYPE*)m_pData)[m_nSize - 1] = newElement; |
| 257 return TRUE; | 257 return true; |
| 258 } | 258 } |
| 259 | 259 |
| 260 FX_BOOL Append(const CFX_ArrayTemplate& src) { | 260 bool Append(const CFX_ArrayTemplate& src) { |
| 261 return CFX_BasicArray::Append(src); | 261 return CFX_BasicArray::Append(src); |
| 262 } | 262 } |
| 263 | 263 |
| 264 FX_BOOL Copy(const CFX_ArrayTemplate& src) { | 264 bool Copy(const CFX_ArrayTemplate& src) { return CFX_BasicArray::Copy(src); } |
| 265 return CFX_BasicArray::Copy(src); | |
| 266 } | |
| 267 | 265 |
| 268 TYPE* GetDataPtr(int index) { | 266 TYPE* GetDataPtr(int index) { |
| 269 return (TYPE*)CFX_BasicArray::GetDataPtr(index); | 267 return (TYPE*)CFX_BasicArray::GetDataPtr(index); |
| 270 } | 268 } |
| 271 | 269 |
| 272 TYPE* AddSpace() { return (TYPE*)CFX_BasicArray::InsertSpaceAt(m_nSize, 1); } | 270 TYPE* AddSpace() { return (TYPE*)CFX_BasicArray::InsertSpaceAt(m_nSize, 1); } |
| 273 | 271 |
| 274 TYPE* InsertSpaceAt(int nIndex, int nCount) { | 272 TYPE* InsertSpaceAt(int nIndex, int nCount) { |
| 275 return (TYPE*)CFX_BasicArray::InsertSpaceAt(nIndex, nCount); | 273 return (TYPE*)CFX_BasicArray::InsertSpaceAt(nIndex, nCount); |
| 276 } | 274 } |
| 277 | 275 |
| 278 const TYPE operator[](int nIndex) const { | 276 const TYPE operator[](int nIndex) const { |
| 279 if (nIndex < 0 || nIndex >= m_nSize) { | 277 if (nIndex < 0 || nIndex >= m_nSize) { |
| 280 *(volatile char*)0 = '\0'; | 278 *(volatile char*)0 = '\0'; |
| 281 } | 279 } |
| 282 return ((const TYPE*)m_pData)[nIndex]; | 280 return ((const TYPE*)m_pData)[nIndex]; |
| 283 } | 281 } |
| 284 | 282 |
| 285 TYPE& operator[](int nIndex) { | 283 TYPE& operator[](int nIndex) { |
| 286 if (nIndex < 0 || nIndex >= m_nSize) { | 284 if (nIndex < 0 || nIndex >= m_nSize) { |
| 287 *(volatile char*)0 = '\0'; | 285 *(volatile char*)0 = '\0'; |
| 288 } | 286 } |
| 289 return ((TYPE*)m_pData)[nIndex]; | 287 return ((TYPE*)m_pData)[nIndex]; |
| 290 } | 288 } |
| 291 | 289 |
| 292 FX_BOOL InsertAt(int nIndex, TYPE newElement, int nCount = 1) { | 290 bool InsertAt(int nIndex, TYPE newElement, int nCount = 1) { |
| 293 if (!InsertSpaceAt(nIndex, nCount)) { | 291 if (!InsertSpaceAt(nIndex, nCount)) { |
| 294 return FALSE; | 292 return false; |
| 295 } | 293 } |
| 296 while (nCount--) { | 294 while (nCount--) { |
| 297 ((TYPE*)m_pData)[nIndex++] = newElement; | 295 ((TYPE*)m_pData)[nIndex++] = newElement; |
| 298 } | 296 } |
| 299 return TRUE; | 297 return true; |
| 300 } | 298 } |
| 301 | 299 |
| 302 FX_BOOL RemoveAt(int nIndex, int nCount = 1) { | 300 bool RemoveAt(int nIndex, int nCount = 1) { |
| 303 return CFX_BasicArray::RemoveAt(nIndex, nCount); | 301 return CFX_BasicArray::RemoveAt(nIndex, nCount); |
| 304 } | 302 } |
| 305 | 303 |
| 306 FX_BOOL InsertAt(int nStartIndex, const CFX_BasicArray* pNewArray) { | 304 bool InsertAt(int nStartIndex, const CFX_BasicArray* pNewArray) { |
| 307 return CFX_BasicArray::InsertAt(nStartIndex, pNewArray); | 305 return CFX_BasicArray::InsertAt(nStartIndex, pNewArray); |
| 308 } | 306 } |
| 309 | 307 |
| 310 int Find(TYPE data, int iStart = 0) const { | 308 int Find(TYPE data, int iStart = 0) const { |
| 311 if (iStart < 0) { | 309 if (iStart < 0) { |
| 312 return -1; | 310 return -1; |
| 313 } | 311 } |
| 314 for (; iStart < (int)m_nSize; iStart++) | 312 for (; iStart < (int)m_nSize; iStart++) |
| 315 if (((TYPE*)m_pData)[iStart] == data) { | 313 if (((TYPE*)m_pData)[iStart] == data) { |
| 316 return iStart; | 314 return iStart; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 void* value; | 454 void* value; |
| 457 }; | 455 }; |
| 458 | 456 |
| 459 public: | 457 public: |
| 460 CFX_MapPtrToPtr(int nBlockSize = 10); | 458 CFX_MapPtrToPtr(int nBlockSize = 10); |
| 461 ~CFX_MapPtrToPtr(); | 459 ~CFX_MapPtrToPtr(); |
| 462 | 460 |
| 463 int GetCount() const { return m_nCount; } | 461 int GetCount() const { return m_nCount; } |
| 464 bool IsEmpty() const { return m_nCount == 0; } | 462 bool IsEmpty() const { return m_nCount == 0; } |
| 465 | 463 |
| 466 FX_BOOL Lookup(void* key, void*& rValue) const; | 464 bool Lookup(void* key, void*& rValue) const; |
| 467 | 465 |
| 468 void* GetValueAt(void* key) const; | 466 void* GetValueAt(void* key) const; |
| 469 | 467 |
| 470 void*& operator[](void* key); | 468 void*& operator[](void* key); |
| 471 | 469 |
| 472 void SetAt(void* key, void* newValue) { (*this)[key] = newValue; } | 470 void SetAt(void* key, void* newValue) { (*this)[key] = newValue; } |
| 473 | 471 |
| 474 FX_BOOL RemoveKey(void* key); | 472 bool RemoveKey(void* key); |
| 475 | 473 |
| 476 void RemoveAll(); | 474 void RemoveAll(); |
| 477 | 475 |
| 478 FX_POSITION GetStartPosition() const { | 476 FX_POSITION GetStartPosition() const { |
| 479 return m_nCount == 0 ? nullptr : (FX_POSITION)-1; | 477 return m_nCount == 0 ? nullptr : (FX_POSITION)-1; |
| 480 } | 478 } |
| 481 | 479 |
| 482 void GetNextAssoc(FX_POSITION& rNextPosition, | 480 void GetNextAssoc(FX_POSITION& rNextPosition, |
| 483 void*& rKey, | 481 void*& rKey, |
| 484 void*& rValue) const; | 482 void*& rValue) const; |
| 485 | 483 |
| 486 uint32_t GetHashTableSize() const { return m_nHashTableSize; } | 484 uint32_t GetHashTableSize() const { return m_nHashTableSize; } |
| 487 | 485 |
| 488 void InitHashTable(uint32_t hashSize, FX_BOOL bAllocNow = TRUE); | 486 void InitHashTable(uint32_t hashSize, bool bAllocNow = true); |
| 489 | 487 |
| 490 protected: | 488 protected: |
| 491 CAssoc** m_pHashTable; | 489 CAssoc** m_pHashTable; |
| 492 | 490 |
| 493 uint32_t m_nHashTableSize; | 491 uint32_t m_nHashTableSize; |
| 494 | 492 |
| 495 int m_nCount; | 493 int m_nCount; |
| 496 | 494 |
| 497 CAssoc* m_pFreeList; | 495 CAssoc* m_pFreeList; |
| 498 | 496 |
| 499 struct CFX_Plex* m_pBlocks; | 497 struct CFX_Plex* m_pBlocks; |
| 500 | 498 |
| 501 int m_nBlockSize; | 499 int m_nBlockSize; |
| 502 | 500 |
| 503 uint32_t HashKey(void* key) const; | 501 uint32_t HashKey(void* key) const; |
| 504 | 502 |
| 505 CAssoc* NewAssoc(); | 503 CAssoc* NewAssoc(); |
| 506 | 504 |
| 507 void FreeAssoc(CAssoc* pAssoc); | 505 void FreeAssoc(CAssoc* pAssoc); |
| 508 | 506 |
| 509 CAssoc* GetAssocAt(void* key, uint32_t& hash) const; | 507 CAssoc* GetAssocAt(void* key, uint32_t& hash) const; |
| 510 }; | 508 }; |
| 511 | 509 |
| 512 template <class KeyType, class ValueType> | 510 template <class KeyType, class ValueType> |
| 513 class CFX_MapPtrTemplate : public CFX_MapPtrToPtr { | 511 class CFX_MapPtrTemplate : public CFX_MapPtrToPtr { |
| 514 public: | 512 public: |
| 515 CFX_MapPtrTemplate() : CFX_MapPtrToPtr(10) {} | 513 CFX_MapPtrTemplate() : CFX_MapPtrToPtr(10) {} |
| 516 | 514 |
| 517 FX_BOOL Lookup(KeyType key, ValueType& rValue) const { | 515 bool Lookup(KeyType key, ValueType& rValue) const { |
| 518 void* pValue = nullptr; | 516 void* pValue = nullptr; |
| 519 if (!CFX_MapPtrToPtr::Lookup((void*)(uintptr_t)key, pValue)) { | 517 if (!CFX_MapPtrToPtr::Lookup((void*)(uintptr_t)key, pValue)) { |
| 520 return FALSE; | 518 return false; |
| 521 } | 519 } |
| 522 rValue = (ValueType)(uintptr_t)pValue; | 520 rValue = (ValueType)(uintptr_t)pValue; |
| 523 return TRUE; | 521 return true; |
| 524 } | 522 } |
| 525 | 523 |
| 526 ValueType& operator[](KeyType key) { | 524 ValueType& operator[](KeyType key) { |
| 527 return (ValueType&)CFX_MapPtrToPtr::operator[]((void*)(uintptr_t)key); | 525 return (ValueType&)CFX_MapPtrToPtr::operator[]((void*)(uintptr_t)key); |
| 528 } | 526 } |
| 529 | 527 |
| 530 void SetAt(KeyType key, ValueType newValue) { | 528 void SetAt(KeyType key, ValueType newValue) { |
| 531 CFX_MapPtrToPtr::SetAt((void*)(uintptr_t)key, (void*)(uintptr_t)newValue); | 529 CFX_MapPtrToPtr::SetAt((void*)(uintptr_t)key, (void*)(uintptr_t)newValue); |
| 532 } | 530 } |
| 533 | 531 |
| 534 FX_BOOL RemoveKey(KeyType key) { | 532 bool RemoveKey(KeyType key) { |
| 535 return CFX_MapPtrToPtr::RemoveKey((void*)(uintptr_t)key); | 533 return CFX_MapPtrToPtr::RemoveKey((void*)(uintptr_t)key); |
| 536 } | 534 } |
| 537 | 535 |
| 538 void GetNextAssoc(FX_POSITION& rNextPosition, | 536 void GetNextAssoc(FX_POSITION& rNextPosition, |
| 539 KeyType& rKey, | 537 KeyType& rKey, |
| 540 ValueType& rValue) const { | 538 ValueType& rValue) const { |
| 541 void* pKey = nullptr; | 539 void* pKey = nullptr; |
| 542 void* pValue = nullptr; | 540 void* pValue = nullptr; |
| 543 CFX_MapPtrToPtr::GetNextAssoc(rNextPosition, pKey, pValue); | 541 CFX_MapPtrToPtr::GetNextAssoc(rNextPosition, pKey, pValue); |
| 544 rKey = (KeyType)(uintptr_t)pKey; | 542 rKey = (KeyType)(uintptr_t)pKey; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 #endif // PDF_ENABLE_XFA | 620 #endif // PDF_ENABLE_XFA |
| 623 | 621 |
| 624 class CFX_BitStream { | 622 class CFX_BitStream { |
| 625 public: | 623 public: |
| 626 void Init(const uint8_t* pData, uint32_t dwSize); | 624 void Init(const uint8_t* pData, uint32_t dwSize); |
| 627 | 625 |
| 628 uint32_t GetBits(uint32_t nBits); | 626 uint32_t GetBits(uint32_t nBits); |
| 629 | 627 |
| 630 void ByteAlign(); | 628 void ByteAlign(); |
| 631 | 629 |
| 632 FX_BOOL IsEOF() { return m_BitPos >= m_BitSize; } | 630 bool IsEOF() { return m_BitPos >= m_BitSize; } |
| 633 | 631 |
| 634 void SkipBits(uint32_t nBits) { m_BitPos += nBits; } | 632 void SkipBits(uint32_t nBits) { m_BitPos += nBits; } |
| 635 | 633 |
| 636 void Rewind() { m_BitPos = 0; } | 634 void Rewind() { m_BitPos = 0; } |
| 637 | 635 |
| 638 uint32_t GetPos() const { return m_BitPos; } | 636 uint32_t GetPos() const { return m_BitPos; } |
| 639 | 637 |
| 640 uint32_t BitsRemaining() const { | 638 uint32_t BitsRemaining() const { |
| 641 return m_BitSize >= m_BitPos ? m_BitSize - m_BitPos : 0; | 639 return m_BitSize >= m_BitPos ? m_BitSize - m_BitPos : 0; |
| 642 } | 640 } |
| 643 | 641 |
| 644 protected: | 642 protected: |
| 645 uint32_t m_BitPos; | 643 uint32_t m_BitPos; |
| 646 | 644 |
| 647 uint32_t m_BitSize; | 645 uint32_t m_BitSize; |
| 648 | 646 |
| 649 const uint8_t* m_pData; | 647 const uint8_t* m_pData; |
| 650 }; | 648 }; |
| 651 | 649 |
| 652 class IFX_Pause { | 650 class IFX_Pause { |
| 653 public: | 651 public: |
| 654 virtual ~IFX_Pause() {} | 652 virtual ~IFX_Pause() {} |
| 655 virtual FX_BOOL NeedToPauseNow() = 0; | 653 virtual bool NeedToPauseNow() = 0; |
| 656 }; | 654 }; |
| 657 | 655 |
| 658 template <typename T> | 656 template <typename T> |
| 659 class CFX_AutoRestorer { | 657 class CFX_AutoRestorer { |
| 660 public: | 658 public: |
| 661 explicit CFX_AutoRestorer(T* location) | 659 explicit CFX_AutoRestorer(T* location) |
| 662 : m_Location(location), m_OldValue(*location) {} | 660 : m_Location(location), m_OldValue(*location) {} |
| 663 ~CFX_AutoRestorer() { *m_Location = m_OldValue; } | 661 ~CFX_AutoRestorer() { *m_Location = m_OldValue; } |
| 664 | 662 |
| 665 private: | 663 private: |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 FX_FLOAT e; | 849 FX_FLOAT e; |
| 852 FX_FLOAT f; | 850 FX_FLOAT f; |
| 853 FX_FLOAT g; | 851 FX_FLOAT g; |
| 854 FX_FLOAT h; | 852 FX_FLOAT h; |
| 855 FX_FLOAT i; | 853 FX_FLOAT i; |
| 856 }; | 854 }; |
| 857 | 855 |
| 858 uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits); | 856 uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits); |
| 859 | 857 |
| 860 #endif // CORE_FXCRT_FX_BASIC_H_ | 858 #endif // CORE_FXCRT_FX_BASIC_H_ |
| OLD | NEW |