Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: core/fxcrt/include/fx_basic.h

Issue 2032613003: Get rid of NULLs in core/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Fix a bad merge Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fxcrt/fxcrt_windows.cpp ('k') | core/fxcrt/include/fx_ext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_INCLUDE_FX_BASIC_H_ 7 #ifndef CORE_FXCRT_INCLUDE_FX_BASIC_H_
8 #define CORE_FXCRT_INCLUDE_FX_BASIC_H_ 8 #define CORE_FXCRT_INCLUDE_FX_BASIC_H_
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 469
470 void*& operator[](void* key); 470 void*& operator[](void* key);
471 471
472 void SetAt(void* key, void* newValue) { (*this)[key] = newValue; } 472 void SetAt(void* key, void* newValue) { (*this)[key] = newValue; }
473 473
474 FX_BOOL RemoveKey(void* key); 474 FX_BOOL RemoveKey(void* key);
475 475
476 void RemoveAll(); 476 void RemoveAll();
477 477
478 FX_POSITION GetStartPosition() const { 478 FX_POSITION GetStartPosition() const {
479 return (m_nCount == 0) ? NULL : (FX_POSITION)-1; 479 return m_nCount == 0 ? nullptr : (FX_POSITION)-1;
480 } 480 }
481 481
482 void GetNextAssoc(FX_POSITION& rNextPosition, 482 void GetNextAssoc(FX_POSITION& rNextPosition,
483 void*& rKey, 483 void*& rKey,
484 void*& rValue) const; 484 void*& rValue) const;
485 485
486 uint32_t GetHashTableSize() const { return m_nHashTableSize; } 486 uint32_t GetHashTableSize() const { return m_nHashTableSize; }
487 487
488 void InitHashTable(uint32_t hashSize, FX_BOOL bAllocNow = TRUE); 488 void InitHashTable(uint32_t hashSize, FX_BOOL bAllocNow = TRUE);
489 489
(...skipping 18 matching lines...) Expand all
508 508
509 CAssoc* GetAssocAt(void* key, uint32_t& hash) const; 509 CAssoc* GetAssocAt(void* key, uint32_t& hash) const;
510 }; 510 };
511 511
512 template <class KeyType, class ValueType> 512 template <class KeyType, class ValueType>
513 class CFX_MapPtrTemplate : public CFX_MapPtrToPtr { 513 class CFX_MapPtrTemplate : public CFX_MapPtrToPtr {
514 public: 514 public:
515 CFX_MapPtrTemplate() : CFX_MapPtrToPtr(10) {} 515 CFX_MapPtrTemplate() : CFX_MapPtrToPtr(10) {}
516 516
517 FX_BOOL Lookup(KeyType key, ValueType& rValue) const { 517 FX_BOOL Lookup(KeyType key, ValueType& rValue) const {
518 void* pValue = NULL; 518 void* pValue = nullptr;
519 if (!CFX_MapPtrToPtr::Lookup((void*)(uintptr_t)key, pValue)) { 519 if (!CFX_MapPtrToPtr::Lookup((void*)(uintptr_t)key, pValue)) {
520 return FALSE; 520 return FALSE;
521 } 521 }
522 rValue = (ValueType)(uintptr_t)pValue; 522 rValue = (ValueType)(uintptr_t)pValue;
523 return TRUE; 523 return TRUE;
524 } 524 }
525 525
526 ValueType& operator[](KeyType key) { 526 ValueType& operator[](KeyType key) {
527 return (ValueType&)CFX_MapPtrToPtr::operator[]((void*)(uintptr_t)key); 527 return (ValueType&)CFX_MapPtrToPtr::operator[]((void*)(uintptr_t)key);
528 } 528 }
529 529
530 void SetAt(KeyType key, ValueType newValue) { 530 void SetAt(KeyType key, ValueType newValue) {
531 CFX_MapPtrToPtr::SetAt((void*)(uintptr_t)key, (void*)(uintptr_t)newValue); 531 CFX_MapPtrToPtr::SetAt((void*)(uintptr_t)key, (void*)(uintptr_t)newValue);
532 } 532 }
533 533
534 FX_BOOL RemoveKey(KeyType key) { 534 FX_BOOL RemoveKey(KeyType key) {
535 return CFX_MapPtrToPtr::RemoveKey((void*)(uintptr_t)key); 535 return CFX_MapPtrToPtr::RemoveKey((void*)(uintptr_t)key);
536 } 536 }
537 537
538 void GetNextAssoc(FX_POSITION& rNextPosition, 538 void GetNextAssoc(FX_POSITION& rNextPosition,
539 KeyType& rKey, 539 KeyType& rKey,
540 ValueType& rValue) const { 540 ValueType& rValue) const {
541 void* pKey = NULL; 541 void* pKey = nullptr;
542 void* pValue = NULL; 542 void* pValue = nullptr;
543 CFX_MapPtrToPtr::GetNextAssoc(rNextPosition, pKey, pValue); 543 CFX_MapPtrToPtr::GetNextAssoc(rNextPosition, pKey, pValue);
544 rKey = (KeyType)(uintptr_t)pKey; 544 rKey = (KeyType)(uintptr_t)pKey;
545 rValue = (ValueType)(uintptr_t)pValue; 545 rValue = (ValueType)(uintptr_t)pValue;
546 } 546 }
547 }; 547 };
548 #endif // PDF_ENABLE_XFA 548 #endif // PDF_ENABLE_XFA
549 549
550 class CFX_PtrList { 550 class CFX_PtrList {
551 protected: 551 protected:
552 struct CNode { 552 struct CNode {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 int GetCount() const { return m_nCount; } 589 int GetCount() const { return m_nCount; }
590 FX_POSITION AddTail(void* newElement); 590 FX_POSITION AddTail(void* newElement);
591 FX_POSITION AddHead(void* newElement); 591 FX_POSITION AddHead(void* newElement);
592 592
593 void SetAt(FX_POSITION pos, void* newElement) { 593 void SetAt(FX_POSITION pos, void* newElement) {
594 CNode* pNode = (CNode*)pos; 594 CNode* pNode = (CNode*)pos;
595 pNode->data = newElement; 595 pNode->data = newElement;
596 } 596 }
597 FX_POSITION InsertAfter(FX_POSITION pos, void* newElement); 597 FX_POSITION InsertAfter(FX_POSITION pos, void* newElement);
598 598
599 FX_POSITION Find(void* searchValue, FX_POSITION startAfter = NULL) const; 599 FX_POSITION Find(void* searchValue, FX_POSITION startAfter = nullptr) const;
600 FX_POSITION FindIndex(int index) const; 600 FX_POSITION FindIndex(int index) const;
601 601
602 void RemoveAt(FX_POSITION pos); 602 void RemoveAt(FX_POSITION pos);
603 void RemoveAll(); 603 void RemoveAll();
604 604
605 protected: 605 protected:
606 CNode* m_pNodeHead; 606 CNode* m_pNodeHead;
607 CNode* m_pNodeTail; 607 CNode* m_pNodeTail;
608 int m_nCount; 608 int m_nCount;
609 CNode* m_pNodeFree; 609 CNode* m_pNodeFree;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 655
656 class CountedObj : public ObjClass { 656 class CountedObj : public ObjClass {
657 public: 657 public:
658 CountedObj() {} 658 CountedObj() {}
659 659
660 CountedObj(const CountedObj& src) : ObjClass(src) {} 660 CountedObj(const CountedObj& src) : ObjClass(src) {}
661 661
662 int m_RefCount; 662 int m_RefCount;
663 }; 663 };
664 664
665 CFX_CountRef() { m_pObject = NULL; } 665 CFX_CountRef() { m_pObject = nullptr; }
666 666
667 CFX_CountRef(const Ref& ref) { 667 CFX_CountRef(const Ref& ref) {
668 m_pObject = ref.m_pObject; 668 m_pObject = ref.m_pObject;
669 if (m_pObject) { 669 if (m_pObject) {
670 m_pObject->m_RefCount++; 670 m_pObject->m_RefCount++;
671 } 671 }
672 } 672 }
673 673
674 ~CFX_CountRef() { SetNull(); } 674 ~CFX_CountRef() { SetNull(); }
675 675
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 } 709 }
710 710
711 void SetNull() { 711 void SetNull() {
712 if (!m_pObject) { 712 if (!m_pObject) {
713 return; 713 return;
714 } 714 }
715 m_pObject->m_RefCount--; 715 m_pObject->m_RefCount--;
716 if (m_pObject->m_RefCount <= 0) { 716 if (m_pObject->m_RefCount <= 0) {
717 delete m_pObject; 717 delete m_pObject;
718 } 718 }
719 m_pObject = NULL; 719 m_pObject = nullptr;
720 } 720 }
721 721
722 bool operator==(const Ref& ref) const { return m_pObject == ref.m_pObject; } 722 bool operator==(const Ref& ref) const { return m_pObject == ref.m_pObject; }
723 723
724 protected: 724 protected:
725 CountedObj* m_pObject; 725 CountedObj* m_pObject;
726 }; 726 };
727 class IFX_Pause { 727 class IFX_Pause {
728 public: 728 public:
729 virtual ~IFX_Pause() {} 729 virtual ~IFX_Pause() {}
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 list.start = nStart; 778 list.start = nStart;
779 list.count = temp_count; 779 list.count = temp_count;
780 Append(list); 780 Append(list);
781 nCount -= temp_count; 781 nCount -= temp_count;
782 nStart += temp_count; 782 nStart += temp_count;
783 } 783 }
784 } 784 }
785 785
786 uint8_t* GetAt(int32_t nIndex) { 786 uint8_t* GetAt(int32_t nIndex) {
787 if (nIndex < 0) { 787 if (nIndex < 0) {
788 return NULL; 788 return nullptr;
789 } 789 }
790 if (m_CurList < 0 || m_CurList >= m_DataLists.GetSize()) { 790 if (m_CurList < 0 || m_CurList >= m_DataLists.GetSize()) {
791 return NULL; 791 return nullptr;
792 } 792 }
793 DataList* pCurList = m_DataLists.GetDataPtr(m_CurList); 793 DataList* pCurList = m_DataLists.GetDataPtr(m_CurList);
794 if (!pCurList || nIndex < pCurList->start || 794 if (!pCurList || nIndex < pCurList->start ||
795 nIndex >= pCurList->start + pCurList->count) { 795 nIndex >= pCurList->start + pCurList->count) {
796 pCurList = NULL; 796 pCurList = nullptr;
797 int32_t iStart = 0; 797 int32_t iStart = 0;
798 int32_t iEnd = m_DataLists.GetUpperBound(); 798 int32_t iEnd = m_DataLists.GetUpperBound();
799 int32_t iMid = 0; 799 int32_t iMid = 0;
800 while (iStart <= iEnd) { 800 while (iStart <= iEnd) {
801 iMid = (iStart + iEnd) / 2; 801 iMid = (iStart + iEnd) / 2;
802 DataList* list = m_DataLists.GetDataPtr(iMid); 802 DataList* list = m_DataLists.GetDataPtr(iMid);
803 if (nIndex < list->start) { 803 if (nIndex < list->start) {
804 iEnd = iMid - 1; 804 iEnd = iMid - 1;
805 } else if (nIndex >= list->start + list->count) { 805 } else if (nIndex >= list->start + list->count) {
806 iStart = iMid + 1; 806 iStart = iMid + 1;
807 } else { 807 } else {
808 pCurList = list; 808 pCurList = list;
809 m_CurList = iMid; 809 m_CurList = iMid;
810 break; 810 break;
811 } 811 }
812 } 812 }
813 } 813 }
814 return pCurList ? pCurList->data + (nIndex - pCurList->start) * unit : NULL; 814 return pCurList ? pCurList->data + (nIndex - pCurList->start) * unit
815 : nullptr;
815 } 816 }
816 817
817 protected: 818 protected:
818 void Append(const DataList& list) { 819 void Append(const DataList& list) {
819 int32_t iStart = 0; 820 int32_t iStart = 0;
820 int32_t iEnd = m_DataLists.GetUpperBound(); 821 int32_t iEnd = m_DataLists.GetUpperBound();
821 int32_t iFind = 0; 822 int32_t iFind = 0;
822 while (iStart <= iEnd) { 823 while (iStart <= iEnd) {
823 int32_t iMid = (iStart + iEnd) / 2; 824 int32_t iMid = (iStart + iEnd) / 2;
824 DataList* cur_list = m_DataLists.GetDataPtr(iMid); 825 DataList* cur_list = m_DataLists.GetDataPtr(iMid);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 FX_FLOAT e; 925 FX_FLOAT e;
925 FX_FLOAT f; 926 FX_FLOAT f;
926 FX_FLOAT g; 927 FX_FLOAT g;
927 FX_FLOAT h; 928 FX_FLOAT h;
928 FX_FLOAT i; 929 FX_FLOAT i;
929 }; 930 };
930 931
931 uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits); 932 uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits);
932 933
933 #endif // CORE_FXCRT_INCLUDE_FX_BASIC_H_ 934 #endif // CORE_FXCRT_INCLUDE_FX_BASIC_H_
OLDNEW
« no previous file with comments | « core/fxcrt/fxcrt_windows.cpp ('k') | core/fxcrt/include/fx_ext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698