From e801d4e064690fbe1815d25d220cfbca79976a4f Mon Sep 17 00:00:00 2001 From: tsepez Date: Fri, 29 Apr 2016 13:45:14 -0700 Subject: Replace CFX_PtrArray with typesafe CFX_ArrayTemplate, part 9 Converted one place to unique_ptr to avoid redundant cleanup. Review-Url: https://codereview.chromium.org/1937593002 --- xfa/fxbarcode/qrcode/BC_QRDetector.cpp | 18 ++++++++---------- xfa/fxbarcode/qrcode/BC_QRDetectorResult.cpp | 24 ++++++++++++------------ xfa/fxbarcode/qrcode/BC_QRDetectorResult.h | 24 +++++++++++++++--------- 3 files changed, 35 insertions(+), 31 deletions(-) (limited to 'xfa/fxbarcode/qrcode') diff --git a/xfa/fxbarcode/qrcode/BC_QRDetector.cpp b/xfa/fxbarcode/qrcode/BC_QRDetector.cpp index 030ee43c20..15ae3e26f1 100644 --- a/xfa/fxbarcode/qrcode/BC_QRDetector.cpp +++ b/xfa/fxbarcode/qrcode/BC_QRDetector.cpp @@ -28,6 +28,7 @@ #include "xfa/fxbarcode/BC_ResultPoint.h" #include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" #include "xfa/fxbarcode/qrcode/BC_FinderPatternInfo.h" +#include "xfa/fxbarcode/qrcode/BC_QRAlignmentPattern.h" #include "xfa/fxbarcode/qrcode/BC_QRAlignmentPatternFinder.h" #include "xfa/fxbarcode/qrcode/BC_QRCoderVersion.h" #include "xfa/fxbarcode/qrcode/BC_QRDetectorResult.h" @@ -90,17 +91,14 @@ CBC_QRDetectorResult* CBC_QRDetector::ProcessFinderPatternInfo( SampleGrid(m_image, topLeft.get(), topRight.get(), bottomLeft.get(), (CBC_ResultPoint*)(alignmentPattern), dimension, e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); - CFX_PtrArray* points = new CFX_PtrArray; - if (alignmentPattern == NULL) { - points->Add(bottomLeft.release()); - points->Add(topLeft.release()); - points->Add(topRight.release()); - } else { - points->Add(bottomLeft.release()); - points->Add(topLeft.release()); - points->Add(topRight.release()); + + CFX_ArrayTemplate* points = + new CFX_ArrayTemplate(); + points->Add(bottomLeft.release()); + points->Add(topLeft.release()); + points->Add(topRight.release()); + if (alignmentPattern) points->Add(alignmentPattern); - } return new CBC_QRDetectorResult(bits, points); } CBC_CommonBitMatrix* CBC_QRDetector::SampleGrid( diff --git a/xfa/fxbarcode/qrcode/BC_QRDetectorResult.cpp b/xfa/fxbarcode/qrcode/BC_QRDetectorResult.cpp index 18e5d9ad4c..5ce2e75762 100644 --- a/xfa/fxbarcode/qrcode/BC_QRDetectorResult.cpp +++ b/xfa/fxbarcode/qrcode/BC_QRDetectorResult.cpp @@ -24,20 +24,20 @@ #include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" #include "xfa/fxbarcode/qrcode/BC_QRDetectorResult.h" -CBC_QRDetectorResult::CBC_QRDetectorResult(CBC_CommonBitMatrix* bits, - CFX_PtrArray* points) +CBC_QRDetectorResult::CBC_QRDetectorResult( + CBC_CommonBitMatrix* bits, + CFX_ArrayTemplate* points) : m_bits(bits), m_points(points) {} + CBC_QRDetectorResult::~CBC_QRDetectorResult() { - for (int32_t i = 0; i < m_points->GetSize(); i++) { - delete (CBC_ResultPoint*)(*m_points)[i]; - } - m_points->RemoveAll(); - delete m_points; - delete m_bits; + for (int32_t i = 0; i < m_points->GetSize(); i++) + delete (*m_points)[i]; } -CBC_CommonBitMatrix* CBC_QRDetectorResult::GetBits() { - return m_bits; + +CBC_CommonBitMatrix* CBC_QRDetectorResult::GetBits() const { + return m_bits.get(); } -CFX_PtrArray* CBC_QRDetectorResult::GetPoints() { - return m_points; + +CFX_ArrayTemplate* CBC_QRDetectorResult::GetPoints() const { + return m_points.get(); } diff --git a/xfa/fxbarcode/qrcode/BC_QRDetectorResult.h b/xfa/fxbarcode/qrcode/BC_QRDetectorResult.h index 1570777afe..5948c2a01c 100644 --- a/xfa/fxbarcode/qrcode/BC_QRDetectorResult.h +++ b/xfa/fxbarcode/qrcode/BC_QRDetectorResult.h @@ -7,20 +7,26 @@ #ifndef XFA_FXBARCODE_QRCODE_BC_QRDETECTORRESULT_H_ #define XFA_FXBARCODE_QRCODE_BC_QRDETECTORRESULT_H_ +#include + #include "core/fxcrt/include/fx_basic.h" class CBC_CommonBitMatrix; +class CBC_ResultPoint; -class CBC_QRDetectorResult { - private: - CBC_CommonBitMatrix* m_bits; - CFX_PtrArray* m_points; - +class CBC_QRDetectorResult final { public: - CBC_QRDetectorResult(CBC_CommonBitMatrix* bits, CFX_PtrArray* points); - virtual ~CBC_QRDetectorResult(); - CBC_CommonBitMatrix* GetBits(); - CFX_PtrArray* GetPoints(); + // Takes ownership of |bits| and |points|. + CBC_QRDetectorResult(CBC_CommonBitMatrix* bits, + CFX_ArrayTemplate* points); + ~CBC_QRDetectorResult(); + + CBC_CommonBitMatrix* GetBits() const; + CFX_ArrayTemplate* GetPoints() const; + + private: + std::unique_ptr m_bits; + std::unique_ptr> m_points; }; #endif // XFA_FXBARCODE_QRCODE_BC_QRDETECTORRESULT_H_ -- cgit v1.2.3