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_ean8.cpp | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'xfa/fxbarcode/cbc_ean8.cpp') diff --git a/xfa/fxbarcode/cbc_ean8.cpp b/xfa/fxbarcode/cbc_ean8.cpp index 418ef87c1f..3f32d2274c 100644 --- a/xfa/fxbarcode/cbc_ean8.cpp +++ b/xfa/fxbarcode/cbc_ean8.cpp @@ -27,27 +27,23 @@ #include "xfa/fxbarcode/oned/BC_OnedEAN8Reader.h" #include "xfa/fxbarcode/oned/BC_OnedEAN8Writer.h" -CBC_EAN8::CBC_EAN8() { - m_pBCReader = (CBC_Reader*)new (CBC_OnedEAN8Reader); - m_pBCWriter = (CBC_Writer*)new (CBC_OnedEAN8Writer); -} +CBC_EAN8::CBC_EAN8() + : CBC_OneCode(new CBC_OnedEAN8Reader, new CBC_OnedEAN8Writer) {} -CBC_EAN8::~CBC_EAN8() { - delete (m_pBCReader); - delete (m_pBCWriter); -} +CBC_EAN8::~CBC_EAN8() {} CFX_WideString CBC_EAN8::Preprocess(const CFX_WideStringC& contents) { CFX_WideString encodeContents = - ((CBC_OnedEAN8Writer*)m_pBCWriter)->FilterContents(contents); + static_cast(m_pBCWriter.get()) + ->FilterContents(contents); int32_t length = encodeContents.GetLength(); if (length <= 7) { for (int32_t i = 0; i < 7 - length; i++) encodeContents = FX_WCHAR('0') + encodeContents; CFX_ByteString byteString = encodeContents.UTF8Encode(); - int32_t checksum = - ((CBC_OnedEAN8Writer*)m_pBCWriter)->CalcChecksum(byteString); + int32_t checksum = static_cast(m_pBCWriter.get()) + ->CalcChecksum(byteString); encodeContents += FX_WCHAR(checksum - 0 + '0'); } if (length > 8) @@ -69,10 +65,10 @@ FX_BOOL CBC_EAN8::Encode(const CFX_WideStringC& contents, CFX_WideString encodeContents = Preprocess(contents); CFX_ByteString byteString = encodeContents.UTF8Encode(); m_renderContents = encodeContents; - 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); @@ -82,14 +78,14 @@ FX_BOOL CBC_EAN8::Encode(const CFX_WideStringC& contents, FX_BOOL CBC_EAN8::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_EAN8::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