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_upca.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_upca.cpp')
-rw-r--r-- | xfa/fxbarcode/cbc_upca.cpp | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/xfa/fxbarcode/cbc_upca.cpp b/xfa/fxbarcode/cbc_upca.cpp index 886525ab54..525612257a 100644 --- a/xfa/fxbarcode/cbc_upca.cpp +++ b/xfa/fxbarcode/cbc_upca.cpp @@ -27,28 +27,24 @@ #include "xfa/fxbarcode/oned/BC_OnedUPCAReader.h" #include "xfa/fxbarcode/oned/BC_OnedUPCAWriter.h" -CBC_UPCA::CBC_UPCA() { - m_pBCReader = (CBC_Reader*)new (CBC_OnedUPCAReader); - ((CBC_OnedUPCAReader*)m_pBCReader)->Init(); - m_pBCWriter = (CBC_Writer*)new (CBC_OnedUPCAWriter); +CBC_UPCA::CBC_UPCA() + : CBC_OneCode(new CBC_OnedUPCAReader, new CBC_OnedUPCAWriter) { + static_cast<CBC_OnedUPCAReader*>(m_pBCReader.get())->Init(); } -CBC_UPCA::~CBC_UPCA() { - delete (m_pBCReader); - delete (m_pBCWriter); -} +CBC_UPCA::~CBC_UPCA() {} CFX_WideString CBC_UPCA::Preprocess(const CFX_WideStringC& contents) { - CFX_WideString encodeContents = - ((CBC_OnedUPCAWriter*)m_pBCWriter)->FilterContents(contents); + CBC_OnedUPCAWriter* pWriter = + static_cast<CBC_OnedUPCAWriter*>(m_pBCWriter.get()); + CFX_WideString encodeContents = pWriter->FilterContents(contents); int32_t length = encodeContents.GetLength(); if (length <= 11) { for (int32_t i = 0; i < 11 - length; i++) encodeContents = FX_WCHAR('0') + encodeContents; CFX_ByteString byteString = encodeContents.UTF8Encode(); - int32_t checksum = - ((CBC_OnedUPCAWriter*)m_pBCWriter)->CalcChecksum(byteString); + int32_t checksum = pWriter->CalcChecksum(byteString); byteString += checksum - 0 + '0'; encodeContents = byteString.UTF8Decode(); } @@ -71,12 +67,15 @@ FX_BOOL CBC_UPCA::Encode(const CFX_WideStringC& contents, CFX_WideString encodeContents = Preprocess(contents); CFX_ByteString byteString = encodeContents.UTF8Encode(); m_renderContents = encodeContents; - ((CBC_OnedUPCAWriter*)m_pBCWriter)->Init(); - uint8_t* data = static_cast<CBC_OnedUPCAWriter*>(m_pBCWriter) - ->Encode(byteString, format, outWidth, outHeight, e); + + CBC_OnedUPCAWriter* pWriter = + static_cast<CBC_OnedUPCAWriter*>(m_pBCWriter.get()); + + pWriter->Init(); + uint8_t* data = pWriter->Encode(byteString, format, outWidth, outHeight, e); BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - ((CBC_OneDimWriter*)m_pBCWriter) - ->RenderResult(encodeContents.AsStringC(), data, outWidth, isDevice, e); + pWriter->RenderResult(encodeContents.AsStringC(), data, outWidth, isDevice, + e); FX_Free(data); BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); return TRUE; @@ -85,14 +84,14 @@ FX_BOOL CBC_UPCA::Encode(const CFX_WideStringC& contents, FX_BOOL CBC_UPCA::RenderDevice(CFX_RenderDevice* device, const CFX_Matrix* matrix, int32_t& e) { - ((CBC_OneDimWriter*)m_pBCWriter) + static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) ->RenderDeviceResult(device, matrix, m_renderContents.AsStringC(), e); BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); return TRUE; } FX_BOOL CBC_UPCA::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { - ((CBC_OneDimWriter*)m_pBCWriter) + static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) ->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e); BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); return TRUE; |