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_code39.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_code39.cpp')
-rw-r--r-- | xfa/fxbarcode/cbc_code39.cpp | 50 |
1 files changed, 23 insertions, 27 deletions
diff --git a/xfa/fxbarcode/cbc_code39.cpp b/xfa/fxbarcode/cbc_code39.cpp index 5d00d772e4..03e618e188 100644 --- a/xfa/fxbarcode/cbc_code39.cpp +++ b/xfa/fxbarcode/cbc_code39.cpp @@ -27,26 +27,18 @@ #include "xfa/fxbarcode/oned/BC_OnedCode39Reader.h" #include "xfa/fxbarcode/oned/BC_OnedCode39Writer.h" -CBC_Code39::CBC_Code39() { - m_pBCReader = (CBC_Reader*)new (CBC_OnedCode39Reader); - m_pBCWriter = (CBC_Writer*)new (CBC_OnedCode39Writer); -} +CBC_Code39::CBC_Code39() + : CBC_OneCode(new CBC_OnedCode39Reader, new CBC_OnedCode39Writer) {} -CBC_Code39::CBC_Code39(FX_BOOL usingCheckDigit) { - m_pBCReader = (CBC_Reader*)new CBC_OnedCode39Reader(usingCheckDigit); - m_pBCWriter = (CBC_Writer*)new CBC_OnedCode39Writer; -} +CBC_Code39::CBC_Code39(FX_BOOL usingCheckDigit) + : CBC_OneCode(new CBC_OnedCode39Reader(usingCheckDigit), + new CBC_OnedCode39Writer) {} -CBC_Code39::CBC_Code39(FX_BOOL usingCheckDigit, FX_BOOL extendedMode) { - m_pBCReader = - (CBC_Reader*)new CBC_OnedCode39Reader(usingCheckDigit, extendedMode); - m_pBCWriter = (CBC_Writer*)new CBC_OnedCode39Writer(extendedMode); -} +CBC_Code39::CBC_Code39(FX_BOOL usingCheckDigit, FX_BOOL extendedMode) + : CBC_OneCode(new CBC_OnedCode39Reader(usingCheckDigit, extendedMode), + new CBC_OnedCode39Writer(extendedMode)) {} -CBC_Code39::~CBC_Code39() { - delete (m_pBCReader); - delete (m_pBCWriter); -} +CBC_Code39::~CBC_Code39() {} FX_BOOL CBC_Code39::Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, @@ -59,15 +51,17 @@ FX_BOOL CBC_Code39::Encode(const CFX_WideStringC& contents, int32_t outWidth = 0; int32_t outHeight = 0; CFX_WideString filtercontents = - ((CBC_OnedCode39Writer*)m_pBCWriter)->FilterContents(contents); + static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) + ->FilterContents(contents); CFX_WideString renderContents = - ((CBC_OnedCode39Writer*)m_pBCWriter)->RenderTextContents(contents); + static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) + ->RenderTextContents(contents); m_renderContents = renderContents; CFX_ByteString byteString = filtercontents.UTF8Encode(); - uint8_t* data = static_cast<CBC_OnedCode39Writer*>(m_pBCWriter) + uint8_t* data = static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) ->Encode(byteString, format, outWidth, outHeight, e); BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - ((CBC_OneDimWriter*)m_pBCWriter) + static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) ->RenderResult(renderContents.AsStringC(), data, outWidth, isDevice, e); FX_Free(data); BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); @@ -78,9 +72,9 @@ FX_BOOL CBC_Code39::RenderDevice(CFX_RenderDevice* device, const CFX_Matrix* matrix, int32_t& e) { CFX_WideString renderCon = - ((CBC_OnedCode39Writer*)m_pBCWriter) + static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) ->encodedContents(m_renderContents.AsStringC(), e); - ((CBC_OneDimWriter*)m_pBCWriter) + static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) ->RenderDeviceResult(device, matrix, renderCon.AsStringC(), e); BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); return TRUE; @@ -88,9 +82,9 @@ FX_BOOL CBC_Code39::RenderDevice(CFX_RenderDevice* device, FX_BOOL CBC_Code39::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { CFX_WideString renderCon = - ((CBC_OnedCode39Writer*)m_pBCWriter) + static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) ->encodedContents(m_renderContents.AsStringC(), e); - ((CBC_OneDimWriter*)m_pBCWriter) + static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) ->RenderBitmapResult(pOutBitmap, renderCon.AsStringC(), e); BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); return TRUE; @@ -115,12 +109,14 @@ CFX_WideString CBC_Code39::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { FX_BOOL CBC_Code39::SetTextLocation(BC_TEXT_LOC location) { if (m_pBCWriter) - return ((CBC_OnedCode39Writer*)m_pBCWriter)->SetTextLocation(location); + return static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) + ->SetTextLocation(location); return FALSE; } FX_BOOL CBC_Code39::SetWideNarrowRatio(int32_t ratio) { if (m_pBCWriter) - return ((CBC_OnedCode39Writer*)m_pBCWriter)->SetWideNarrowRatio(ratio); + return static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) + ->SetWideNarrowRatio(ratio); return FALSE; } |