From 52d78564a61fad5d435f3c95a3a6c0df142e50cf Mon Sep 17 00:00:00 2001 From: tsepez Date: Mon, 6 Jun 2016 12:57:44 -0700 Subject: 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 --- xfa/fxbarcode/cbc_code128.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'xfa/fxbarcode/cbc_code128.cpp') diff --git a/xfa/fxbarcode/cbc_code128.cpp b/xfa/fxbarcode/cbc_code128.cpp index 85d7afbbe8..c3614bee90 100644 --- a/xfa/fxbarcode/cbc_code128.cpp +++ b/xfa/fxbarcode/cbc_code128.cpp @@ -27,19 +27,15 @@ #include "xfa/fxbarcode/oned/BC_OnedCode128Reader.h" #include "xfa/fxbarcode/oned/BC_OnedCode128Writer.h" -CBC_Code128::CBC_Code128(BC_TYPE type) { - m_pBCReader = (CBC_Reader*)new (CBC_OnedCode128Reader); - m_pBCWriter = (CBC_Writer*)new CBC_OnedCode128Writer(type); -} +CBC_Code128::CBC_Code128(BC_TYPE type) + : CBC_OneCode(new CBC_OnedCode128Reader, new CBC_OnedCode128Writer(type)) {} -CBC_Code128::~CBC_Code128() { - delete (m_pBCReader); - delete (m_pBCWriter); -} +CBC_Code128::~CBC_Code128() {} FX_BOOL CBC_Code128::SetTextLocation(BC_TEXT_LOC location) { if (m_pBCWriter) - return ((CBC_OnedCode128Writer*)m_pBCWriter)->SetTextLocation(location); + return static_cast(m_pBCWriter.get()) + ->SetTextLocation(location); return FALSE; } @@ -55,17 +51,19 @@ FX_BOOL CBC_Code128::Encode(const CFX_WideStringC& contents, int32_t outHeight = 0; CFX_WideString content(contents); if (contents.GetLength() % 2 && - ((CBC_OnedCode128Writer*)m_pBCWriter)->GetType() == BC_CODE128_C) { + static_cast(m_pBCWriter.get())->GetType() == + BC_CODE128_C) { content += '0'; } - CFX_WideString encodeContents = ((CBC_OnedCode128Writer*)m_pBCWriter) - ->FilterContents(content.AsStringC()); + CFX_WideString encodeContents = + static_cast(m_pBCWriter.get()) + ->FilterContents(content.AsStringC()); m_renderContents = encodeContents; CFX_ByteString byteString = encodeContents.UTF8Encode(); - uint8_t* data = static_cast(m_pBCWriter) + uint8_t* data = static_cast(m_pBCWriter.get()) ->Encode(byteString, format, outWidth, outHeight, e); BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - ((CBC_OneDimWriter*)m_pBCWriter) + static_cast(m_pBCWriter.get()) ->RenderResult(encodeContents.AsStringC(), data, outWidth, isDevice, e); FX_Free(data); BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); @@ -75,14 +73,14 @@ FX_BOOL CBC_Code128::Encode(const CFX_WideStringC& contents, FX_BOOL CBC_Code128::RenderDevice(CFX_RenderDevice* device, const CFX_Matrix* matrix, int32_t& e) { - ((CBC_OneDimWriter*)m_pBCWriter) + static_cast(m_pBCWriter.get()) ->RenderDeviceResult(device, matrix, m_renderContents.AsStringC(), e); BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); return TRUE; } FX_BOOL CBC_Code128::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { - ((CBC_OneDimWriter*)m_pBCWriter) + static_cast(m_pBCWriter.get()) ->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e); BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); return TRUE; -- cgit v1.2.3