From 6020e45b406e7a130024de87101b4493543f9deb Mon Sep 17 00:00:00 2001 From: tsepez Date: Mon, 2 May 2016 13:47:17 -0700 Subject: Replace CFX_PtrArray with typesafe CFX_ArrayTemplate, part 11 Last part. Remove CFX_PtrArray typedef. Review-Url: https://codereview.chromium.org/1941863002 --- xfa/fxbarcode/qrcode/BC_QRCoderEncoder.cpp | 120 ++++++++++++----------------- xfa/fxbarcode/qrcode/BC_QRCoderEncoder.h | 21 +++-- xfa/fxbarcode/qrcode/BC_QRCoderVersion.cpp | 23 +++--- xfa/fxbarcode/qrcode/BC_QRCoderVersion.h | 2 +- 4 files changed, 77 insertions(+), 89 deletions(-) (limited to 'xfa/fxbarcode/qrcode') diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.cpp index ded0df694b..eb7642649d 100644 --- a/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.cpp +++ b/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.cpp @@ -88,7 +88,7 @@ void CBC_QRCoderEncoder::Encode(const CFX_ByteString& content, } void CBC_QRCoderEncoder::AppendECI(CBC_QRCoderBitVector* bits) {} void CBC_QRCoderEncoder::AppendDataModeLenghInfo( - CFX_PtrArray& splitResult, + const CFX_ArrayTemplate& splitResult, CBC_QRCoderBitVector& headerAndDataBits, CBC_QRCoderMode* tempMode, CBC_QRCoder* qrCode, @@ -141,7 +141,7 @@ void CBC_QRCoderEncoder::AppendDataModeLenghInfo( } } void CBC_QRCoderEncoder::SplitString(const CFX_ByteString& content, - CFX_PtrArray& result) { + CFX_ArrayTemplate* result) { int32_t index = 0, flag = 0; while ( (((uint8_t)content[index] >= 0xA1 && (uint8_t)content[index] <= 0xAA) || @@ -150,7 +150,7 @@ void CBC_QRCoderEncoder::SplitString(const CFX_ByteString& content, index += 2; } if (index != flag) { - result.Add( + result->Add( new Make_Pair(CBC_QRCoderMode::sGBK, content.Mid(flag, index - flag))); } flag = index; @@ -174,7 +174,7 @@ void CBC_QRCoderEncoder::SplitString(const CFX_ByteString& content, } } if (index != flag) { - result.Add( + result->Add( new Make_Pair(CBC_QRCoderMode::sBYTE, content.Mid(flag, index - flag))); } flag = index; @@ -186,8 +186,8 @@ void CBC_QRCoderEncoder::SplitString(const CFX_ByteString& content, index++; } if (index != flag) { - result.Add(new Make_Pair(CBC_QRCoderMode::sNUMERIC, - content.Mid(flag, index - flag))); + result->Add(new Make_Pair(CBC_QRCoderMode::sNUMERIC, + content.Mid(flag, index - flag))); } flag = index; if (index >= content.GetLength()) { @@ -198,15 +198,14 @@ void CBC_QRCoderEncoder::SplitString(const CFX_ByteString& content, index++; } if (index != flag) { - result.Add(new Make_Pair(CBC_QRCoderMode::sALPHANUMERIC, - content.Mid(flag, index - flag))); + result->Add(new Make_Pair(CBC_QRCoderMode::sALPHANUMERIC, + content.Mid(flag, index - flag))); } flag = index; - if (index >= content.GetLength()) { - return; - } - SplitString(content.Mid(index, content.GetLength() - index), result); + if (index < content.GetLength()) + SplitString(content.Mid(index, content.GetLength() - index), result); } + int32_t CBC_QRCoderEncoder::GetSpanByVersion(CBC_QRCoderMode* modeFirst, CBC_QRCoderMode* modeSecond, int32_t versionNum, @@ -253,16 +252,17 @@ int32_t CBC_QRCoderEncoder::GetSpanByVersion(CBC_QRCoderMode* modeFirst, } return -1; } -void CBC_QRCoderEncoder::MergeString(CFX_PtrArray& result, + +void CBC_QRCoderEncoder::MergeString(CFX_ArrayTemplate* result, int32_t versionNum, int32_t& e) { Make_Pair* first = NULL; Make_Pair* second = NULL; size_t mergeNum = 0; int32_t i; - for (i = 0; ((i < result.GetSize()) && (i + 1 < result.GetSize())); i++) { - first = (Make_Pair*)result[i]; - second = (Make_Pair*)result[i + 1]; + for (i = 0; ((i < result->GetSize()) && (i + 1 < result->GetSize())); i++) { + first = (*result)[i]; + second = (*result)[i + 1]; if (first->m_mode == CBC_QRCoderMode::sALPHANUMERIC) { int32_t tmp = GetSpanByVersion(CBC_QRCoderMode::sALPHANUMERIC, CBC_QRCoderMode::sBYTE, versionNum, e); @@ -272,7 +272,7 @@ void CBC_QRCoderEncoder::MergeString(CFX_PtrArray& result, CFX_ByteString str = first->m_string + second->m_string; second->m_string = str; delete first; - result.RemoveAt(i); + result->RemoveAt(i); i--; mergeNum++; } @@ -280,7 +280,7 @@ void CBC_QRCoderEncoder::MergeString(CFX_PtrArray& result, if (second->m_mode == CBC_QRCoderMode::sBYTE) { first->m_string += second->m_string; delete second; - result.RemoveAt(i + 1); + result->RemoveAt(i + 1); i--; mergeNum++; } @@ -293,7 +293,7 @@ void CBC_QRCoderEncoder::MergeString(CFX_PtrArray& result, CFX_ByteString str = first->m_string + second->m_string; second->m_string = str; delete first; - result.RemoveAt(i); + result->RemoveAt(i); i--; mergeNum++; } @@ -305,7 +305,7 @@ void CBC_QRCoderEncoder::MergeString(CFX_PtrArray& result, CFX_ByteString str = first->m_string + second->m_string; second->m_string = str; delete first; - result.RemoveAt(i); + result->RemoveAt(i); i--; mergeNum++; } @@ -353,20 +353,18 @@ void CBC_QRCoderEncoder::EncodeWithSpecifyVersion( int32_t& e) { CFX_ByteString encoding = "utf8"; CBC_QRCoderMode* mode = CBC_QRCoderMode::sBYTE; - CFX_PtrArray splitResult; + CFX_ArrayTemplate splitResult; CBC_QRCoderBitVector dataBits; dataBits.Init(); - SplitString(content, splitResult); - MergeString(splitResult, versionSpecify, e); + SplitString(content, &splitResult); + MergeString(&splitResult, versionSpecify, e); BC_EXCEPTION_CHECK_ReturnVoid(e) CBC_QRCoderMode* tempMode = NULL; for (int32_t i = 0; i < splitResult.GetSize(); i++) { - AppendBytes(((Make_Pair*)splitResult[i])->m_string, - ((Make_Pair*)splitResult[i])->m_mode, &dataBits, encoding, e); + AppendBytes(splitResult[i]->m_string, splitResult[i]->m_mode, &dataBits, + encoding, e); if (e != BCExceptionNO) { - for (int32_t y = 0; y < splitResult.GetSize(); y++) { - delete (Make_Pair*)splitResult[y]; - } - splitResult.RemoveAll(); + for (int32_t y = 0; y < splitResult.GetSize(); y++) + delete splitResult[y]; return; } } @@ -375,34 +373,25 @@ void CBC_QRCoderEncoder::EncodeWithSpecifyVersion( headerAndDataBits.Init(); InitQRCode(numInputBytes, versionSpecify, ecLevel, mode, qrCode, e); if (e != BCExceptionNO) { - for (int32_t k = 0; k < splitResult.GetSize(); k++) { - delete (Make_Pair*)splitResult[k]; - } - splitResult.RemoveAll(); + for (int32_t k = 0; k < splitResult.GetSize(); k++) + delete splitResult[k]; return; } AppendDataModeLenghInfo(splitResult, headerAndDataBits, tempMode, qrCode, encoding, e); if (e != BCExceptionNO) { - for (int32_t k = 0; k < splitResult.GetSize(); k++) { - delete (Make_Pair*)splitResult[k]; - } - splitResult.RemoveAll(); + for (int32_t k = 0; k < splitResult.GetSize(); k++) + delete splitResult[k]; return; } numInputBytes = headerAndDataBits.sizeInBytes(); TerminateBits(qrCode->GetNumDataBytes(), &headerAndDataBits, e); - if (e != BCExceptionNO) { - for (int32_t k = 0; k < splitResult.GetSize(); k++) { - delete (Make_Pair*)splitResult[k]; - } - splitResult.RemoveAll(); - return; - } for (int32_t j = 0; j < splitResult.GetSize(); j++) { - delete (Make_Pair*)splitResult[j]; + delete splitResult[j]; } - splitResult.RemoveAll(); + if (e != BCExceptionNO) + return; + CBC_QRCoderBitVector finalBits; finalBits.Init(); InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(), @@ -433,21 +422,19 @@ void CBC_QRCoderEncoder::EncodeWithAutoVersion( int32_t& e) { CFX_ByteString encoding = "utf8"; CBC_QRCoderMode* mode = CBC_QRCoderMode::sBYTE; - CFX_PtrArray splitResult; + CFX_ArrayTemplate splitResult; CBC_QRCoderBitVector dataBits; dataBits.Init(); - SplitString(content, splitResult); - MergeString(splitResult, 8, e); + SplitString(content, &splitResult); + MergeString(&splitResult, 8, e); BC_EXCEPTION_CHECK_ReturnVoid(e); CBC_QRCoderMode* tempMode = NULL; for (int32_t i = 0; i < splitResult.GetSize(); i++) { - AppendBytes(((Make_Pair*)splitResult[i])->m_string, - ((Make_Pair*)splitResult[i])->m_mode, &dataBits, encoding, e); + AppendBytes(splitResult[i]->m_string, splitResult[i]->m_mode, &dataBits, + encoding, e); if (e != BCExceptionNO) { - for (int32_t l = 0; l < splitResult.GetSize(); l++) { - delete (Make_Pair*)splitResult[l]; - } - splitResult.RemoveAll(); + for (int32_t l = 0; l < splitResult.GetSize(); l++) + delete splitResult[l]; return; } } @@ -482,17 +469,14 @@ catchException: e = BCExceptionNO; goto sign; } else { - for (int32_t j = 0; j < splitResult.GetSize(); j++) { - delete (Make_Pair*)splitResult[j]; - } - splitResult.RemoveAll(); + for (int32_t j = 0; j < splitResult.GetSize(); j++) + delete splitResult[j]; return; } } - for (int32_t k = 0; k < splitResult.GetSize(); k++) { - delete (Make_Pair*)splitResult[k]; - } - splitResult.RemoveAll(); + for (int32_t k = 0; k < splitResult.GetSize(); k++) + delete splitResult[k]; + CBC_QRCoderBitVector finalBits; finalBits.Init(); InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(), @@ -863,7 +847,7 @@ void CBC_QRCoderEncoder::InterleaveWithECBytes(CBC_QRCoderBitVector* bits, int32_t dataBytesOffset = 0; int32_t maxNumDataBytes = 0; int32_t maxNumEcBytes = 0; - CFX_PtrArray blocks; + CFX_ArrayTemplate blocks; int32_t i; for (i = 0; i < numRSBlocks; i++) { int32_t numDataBytesInBlock; @@ -887,8 +871,7 @@ void CBC_QRCoderEncoder::InterleaveWithECBytes(CBC_QRCoderBitVector* bits, } for (int32_t x = 0; x < maxNumDataBytes; x++) { for (int32_t j = 0; j < blocks.GetSize(); j++) { - CBC_CommonByteArray* dataBytes = - ((CBC_QRCoderBlockPair*)blocks[j])->GetDataBytes(); + CBC_CommonByteArray* dataBytes = blocks[j]->GetDataBytes(); if (x < dataBytes->Size()) { result->AppendBits(dataBytes->At(x), 8, e); BC_EXCEPTION_CHECK_ReturnVoid(e); @@ -897,8 +880,7 @@ void CBC_QRCoderEncoder::InterleaveWithECBytes(CBC_QRCoderBitVector* bits, } for (int32_t y = 0; y < maxNumEcBytes; y++) { for (int32_t l = 0; l < blocks.GetSize(); l++) { - CBC_CommonByteArray* ecBytes = - ((CBC_QRCoderBlockPair*)blocks[l])->GetErrorCorrectionBytes(); + CBC_CommonByteArray* ecBytes = blocks[l]->GetErrorCorrectionBytes(); if (y < ecBytes->Size()) { result->AppendBits(ecBytes->At(y), 8, e); BC_EXCEPTION_CHECK_ReturnVoid(e); @@ -906,7 +888,7 @@ void CBC_QRCoderEncoder::InterleaveWithECBytes(CBC_QRCoderBitVector* bits, } } for (int32_t k = 0; k < blocks.GetSize(); k++) { - delete (CBC_QRCoderBlockPair*)blocks[k]; + delete blocks[k]; } if (numTotalBytes != result->sizeInBytes()) { e = BCExceptionSizeInBytesDiffer; diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.h b/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.h index bbdec5bf1e..be0a76c337 100644 --- a/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.h +++ b/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.h @@ -16,6 +16,7 @@ class CBC_QRCoderMode; class CBC_QRCoderBitVector; class CBC_CommonByteArray; class CBC_CommonByteMatrix; +class Make_Pair; class CBC_QRCoderEncoder { private: @@ -120,14 +121,18 @@ class CBC_QRCoderEncoder { CBC_QRCoderMode* modeSecond, int32_t versionNum, int32_t& e); - static void MergeString(CFX_PtrArray& result, int32_t versionNum, int32_t& e); - static void SplitString(const CFX_ByteString& content, CFX_PtrArray& result); - static void AppendDataModeLenghInfo(CFX_PtrArray& splitResult, - CBC_QRCoderBitVector& headerAndDataBits, - CBC_QRCoderMode* tempMode, - CBC_QRCoder* qrCode, - CFX_ByteString& encoding, - int32_t& e); + static void MergeString(CFX_ArrayTemplate* result, + int32_t versionNum, + int32_t& e); + static void SplitString(const CFX_ByteString& content, + CFX_ArrayTemplate* result); + static void AppendDataModeLenghInfo( + const CFX_ArrayTemplate& splitResult, + CBC_QRCoderBitVector& headerAndDataBits, + CBC_QRCoderMode* tempMode, + CBC_QRCoder* qrCode, + CFX_ByteString& encoding, + int32_t& e); }; #endif // XFA_FXBARCODE_QRCODE_BC_QRCODERENCODER_H_ diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderVersion.cpp b/xfa/fxbarcode/qrcode/BC_QRCoderVersion.cpp index e92267819c..9c3a1cc138 100644 --- a/xfa/fxbarcode/qrcode/BC_QRCoderVersion.cpp +++ b/xfa/fxbarcode/qrcode/BC_QRCoderVersion.cpp @@ -35,17 +35,18 @@ const int32_t CBC_QRCoderVersion::VERSION_DECODE_INFO[] = { 0x15683, 0x168C9, 0x177EC, 0x18EC4, 0x191E1, 0x1AFAB, 0x1B08E, 0x1CC1A, 0x1D33F, 0x1ED75, 0x1F250, 0x209D5, 0x216F0, 0x228BA, 0x2379F, 0x24B0B, 0x2542E, 0x26A64, 0x27541, 0x28C69}; -CFX_PtrArray* CBC_QRCoderVersion::VERSION = NULL; + +CFX_ArrayTemplate* CBC_QRCoderVersion::VERSION = nullptr; void CBC_QRCoderVersion::Initialize() { - VERSION = new CFX_PtrArray(); + VERSION = new CFX_ArrayTemplate(); } void CBC_QRCoderVersion::Finalize() { - for (int32_t i = 0; i < VERSION->GetSize(); i++) { - CBC_QRCoderVersion* v = (CBC_QRCoderVersion*)(VERSION->GetAt(i)); - delete v; - } + for (int32_t i = 0; i < VERSION->GetSize(); i++) + delete VERSION->GetAt(i); + delete VERSION; + VERSION = nullptr; } CBC_QRCoderVersion::CBC_QRCoderVersion(int32_t versionNumber, CBC_QRCoderECBlocks* ecBlocks1, @@ -755,11 +756,11 @@ CBC_QRCoderVersion* CBC_QRCoderVersion::GetVersionForNumber( e = BCExceptionIllegalArgument; BC_EXCEPTION_CHECK_ReturnValue(e, NULL); } - return (CBC_QRCoderVersion*)(*VERSION)[versionNumber - 1]; + return (*VERSION)[versionNumber - 1]; } + void CBC_QRCoderVersion::Destroy() { - int32_t i; - for (i = 0; i < VERSION->GetSize(); i++) { - delete ((CBC_QRCoderVersion*)(*VERSION)[i]); - } + for (int32_t i = 0; i < VERSION->GetSize(); i++) + delete (*VERSION)[i]; + VERSION->RemoveAll(); } diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderVersion.h b/xfa/fxbarcode/qrcode/BC_QRCoderVersion.h index 05bd71934d..deae8933e6 100644 --- a/xfa/fxbarcode/qrcode/BC_QRCoderVersion.h +++ b/xfa/fxbarcode/qrcode/BC_QRCoderVersion.h @@ -44,7 +44,7 @@ class CBC_QRCoderVersion { CBC_QRCoderECBlocks* ecBlocks4); static const int32_t VERSION_DECODE_INFO[34]; - static CFX_PtrArray* VERSION; + static CFX_ArrayTemplate* VERSION; int32_t m_versionNumber; int32_t m_totalCodeWords; -- cgit v1.2.3