diff options
author | tsepez <tsepez@chromium.org> | 2016-06-06 12:57:44 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-06-06 12:57:44 -0700 |
commit | 52d78564a61fad5d435f3c95a3a6c0df142e50cf (patch) | |
tree | 209840b7f578c0e35722984b789a2e9e84d5d428 /xfa/fxbarcode/cbc_qrcode.cpp | |
parent | fe433f15d60f92ccde7a928160c2e7cc77dcb8bf (diff) | |
download | pdfium-52d78564a61fad5d435f3c95a3a6c0df142e50cf.tar.xz |
Clean up C-Style casts in CBC_CodeBase and subclasses
Make the parent class own the reader/writer via unique_ptrs.
De-virtualize some methods with no overrides.
Review-Url: https://codereview.chromium.org/2037573005
Diffstat (limited to 'xfa/fxbarcode/cbc_qrcode.cpp')
-rw-r--r-- | xfa/fxbarcode/cbc_qrcode.cpp | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/xfa/fxbarcode/cbc_qrcode.cpp b/xfa/fxbarcode/cbc_qrcode.cpp index 6f93b4415e..9ea20a6820 100644 --- a/xfa/fxbarcode/cbc_qrcode.cpp +++ b/xfa/fxbarcode/cbc_qrcode.cpp @@ -27,31 +27,27 @@ #include "xfa/fxbarcode/qrcode/BC_QRCodeReader.h" #include "xfa/fxbarcode/qrcode/BC_QRCodeWriter.h" -CBC_QRCode::CBC_QRCode() { - m_pBCReader = (CBC_Reader*)new (CBC_QRCodeReader); - ((CBC_QRCodeReader*)m_pBCReader)->Init(); - m_pBCWriter = (CBC_Writer*)new (CBC_QRCodeWriter); +CBC_QRCode::CBC_QRCode() + : CBC_CodeBase(new CBC_QRCodeReader, new CBC_QRCodeWriter) { + static_cast<CBC_QRCodeReader*>(m_pBCReader.get())->Init(); } -CBC_QRCode::~CBC_QRCode() { - delete (m_pBCReader); - delete (m_pBCWriter); -} +CBC_QRCode::~CBC_QRCode() {} FX_BOOL CBC_QRCode::SetVersion(int32_t version) { if (version < 0 || version > 40) return FALSE; - if (!m_pBCWriter) - return FALSE; - return ((CBC_QRCodeWriter*)m_pBCWriter)->SetVersion(version); + return m_pBCWriter && + static_cast<CBC_QRCodeWriter*>(m_pBCWriter.get())->SetVersion(version); } FX_BOOL CBC_QRCode::SetErrorCorrectionLevel(int32_t level) { if (level < 0 || level > 3) return FALSE; - if (!m_pBCWriter) - return FALSE; - return ((CBC_TwoDimWriter*)m_pBCWriter)->SetErrorCorrectionLevel(level); + + return m_pBCWriter && + static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) + ->SetErrorCorrectionLevel(level); } FX_BOOL CBC_QRCode::Encode(const CFX_WideStringC& contents, @@ -59,13 +55,12 @@ FX_BOOL CBC_QRCode::Encode(const CFX_WideStringC& contents, int32_t& e) { int32_t outWidth = 0; int32_t outHeight = 0; - uint8_t* data = - ((CBC_QRCodeWriter*)m_pBCWriter) - ->Encode(CFX_WideString(contents), - ((CBC_QRCodeWriter*)m_pBCWriter)->GetErrorCorrectionLevel(), - outWidth, outHeight, e); + CBC_QRCodeWriter* pWriter = static_cast<CBC_QRCodeWriter*>(m_pBCWriter.get()); + uint8_t* data = pWriter->Encode(CFX_WideString(contents), + pWriter->GetErrorCorrectionLevel(), outWidth, + outHeight, e); BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - ((CBC_TwoDimWriter*)m_pBCWriter)->RenderResult(data, outWidth, outHeight, e); + pWriter->RenderResult(data, outWidth, outHeight, e); FX_Free(data); BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); return TRUE; @@ -74,12 +69,14 @@ FX_BOOL CBC_QRCode::Encode(const CFX_WideStringC& contents, FX_BOOL CBC_QRCode::RenderDevice(CFX_RenderDevice* device, const CFX_Matrix* matrix, int32_t& e) { - ((CBC_TwoDimWriter*)m_pBCWriter)->RenderDeviceResult(device, matrix); + static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) + ->RenderDeviceResult(device, matrix); return TRUE; } FX_BOOL CBC_QRCode::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { - ((CBC_TwoDimWriter*)m_pBCWriter)->RenderBitmapResult(pOutBitmap, e); + static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) + ->RenderBitmapResult(pOutBitmap, e); BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); return TRUE; } |