Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: xfa/fxbarcode/qrcode/BC_QRCoder.cpp

Issue 2221023003: Use smart pointers for class owned pointers in xfa/fxbarcode (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: address comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fxbarcode/qrcode/BC_QRCoder.h ('k') | xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 // Original code is licensed as follows: 6 // Original code is licensed as follows:
7 /* 7 /*
8 * Copyright 2008 ZXing authors 8 * Copyright 2008 ZXing authors
9 * 9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License. 11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at 12 * You may obtain a copy of the License at
13 * 13 *
14 * http://www.apache.org/licenses/LICENSE-2.0 14 * http://www.apache.org/licenses/LICENSE-2.0
15 * 15 *
16 * Unless required by applicable law or agreed to in writing, software 16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, 17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and 19 * See the License for the specific language governing permissions and
20 * limitations under the License. 20 * limitations under the License.
21 */ 21 */
22 22
23 #include <utility>
24
23 #include "xfa/fxbarcode/common/BC_CommonByteMatrix.h" 25 #include "xfa/fxbarcode/common/BC_CommonByteMatrix.h"
24 #include "xfa/fxbarcode/qrcode/BC_QRCoder.h" 26 #include "xfa/fxbarcode/qrcode/BC_QRCoder.h"
25 #include "xfa/fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h" 27 #include "xfa/fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h"
26 #include "xfa/fxbarcode/qrcode/BC_QRCoderMode.h" 28 #include "xfa/fxbarcode/qrcode/BC_QRCoderMode.h"
27 #include "xfa/fxbarcode/utils.h" 29 #include "xfa/fxbarcode/utils.h"
28 30
29 CBC_QRCoder::CBC_QRCoder() { 31 CBC_QRCoder::CBC_QRCoder()
30 m_mode = nullptr; 32 : m_mode(nullptr),
31 m_ecLevel = nullptr; 33 m_ecLevel(nullptr),
32 m_version = -1; 34 m_version(-1),
33 m_matrixWidth = -1; 35 m_matrixWidth(-1),
34 m_maskPattern = -1; 36 m_maskPattern(-1),
35 m_numTotalBytes = -1; 37 m_numTotalBytes(-1),
36 m_numDataBytes = -1; 38 m_numDataBytes(-1),
37 m_numECBytes = -1; 39 m_numECBytes(-1),
38 m_numRSBlocks = -1; 40 m_numRSBlocks(-1) {}
39 m_matrix = nullptr; 41
40 } 42 CBC_QRCoder::~CBC_QRCoder() {}
41 CBC_QRCoder::~CBC_QRCoder() { 43
42 delete m_matrix; 44 CBC_QRCoderMode* CBC_QRCoder::GetMode() const {
43 }
44 CBC_QRCoderMode* CBC_QRCoder::GetMode() {
45 return m_mode; 45 return m_mode;
46 } 46 }
47 CBC_QRCoderErrorCorrectionLevel* CBC_QRCoder::GetECLevel() { 47
48 CBC_QRCoderErrorCorrectionLevel* CBC_QRCoder::GetECLevel() const {
48 return m_ecLevel; 49 return m_ecLevel;
49 } 50 }
50 int32_t CBC_QRCoder::GetVersion() { 51
52 int32_t CBC_QRCoder::GetVersion() const {
51 return m_version; 53 return m_version;
52 } 54 }
53 int32_t CBC_QRCoder::GetMatrixWidth() { 55
56 int32_t CBC_QRCoder::GetMatrixWidth() const {
54 return m_matrixWidth; 57 return m_matrixWidth;
55 } 58 }
56 int32_t CBC_QRCoder::GetMaskPattern() { 59
60 int32_t CBC_QRCoder::GetMaskPattern() const {
57 return m_maskPattern; 61 return m_maskPattern;
58 } 62 }
59 int32_t CBC_QRCoder::GetNumTotalBytes() { 63
64 int32_t CBC_QRCoder::GetNumTotalBytes() const {
60 return m_numTotalBytes; 65 return m_numTotalBytes;
61 } 66 }
62 int32_t CBC_QRCoder::GetNumDataBytes() { 67
68 int32_t CBC_QRCoder::GetNumDataBytes() const {
63 return m_numDataBytes; 69 return m_numDataBytes;
64 } 70 }
65 int32_t CBC_QRCoder::GetNumECBytes() { 71
72 int32_t CBC_QRCoder::GetNumECBytes() const {
66 return m_numECBytes; 73 return m_numECBytes;
67 } 74 }
68 int32_t CBC_QRCoder::GetNumRSBlocks() { 75
76 int32_t CBC_QRCoder::GetNumRSBlocks() const {
69 return m_numRSBlocks; 77 return m_numRSBlocks;
70 } 78 }
71 CBC_CommonByteMatrix* CBC_QRCoder::GetMatrix() { 79
72 return m_matrix; 80 CBC_CommonByteMatrix* CBC_QRCoder::GetMatrix() const {
81 return m_matrix.get();
73 } 82 }
83
74 int32_t CBC_QRCoder::At(int32_t x, int32_t y, int32_t& e) { 84 int32_t CBC_QRCoder::At(int32_t x, int32_t y, int32_t& e) {
75 int32_t value = m_matrix->Get(x, y); 85 int32_t value = m_matrix->Get(x, y);
76 if (!(value == 0 || value == 1)) { 86 if (!(value == 0 || value == 1)) {
77 e = BCExceptionValueMustBeEither0or1; 87 e = BCExceptionValueMustBeEither0or1;
78 BC_EXCEPTION_CHECK_ReturnValue(e, 0); 88 BC_EXCEPTION_CHECK_ReturnValue(e, 0);
79 } 89 }
80 return value; 90 return value;
81 } 91 }
92
82 FX_BOOL CBC_QRCoder::IsValid() { 93 FX_BOOL CBC_QRCoder::IsValid() {
83 return m_mode && m_ecLevel && m_version != -1 && m_matrixWidth != -1 && 94 return m_mode && m_ecLevel && m_version != -1 && m_matrixWidth != -1 &&
84 m_maskPattern != -1 && m_numTotalBytes != -1 && m_numDataBytes != -1 && 95 m_maskPattern != -1 && m_numTotalBytes != -1 && m_numDataBytes != -1 &&
85 m_numECBytes != -1 && m_numRSBlocks != -1 && 96 m_numECBytes != -1 && m_numRSBlocks != -1 &&
86 IsValidMaskPattern(m_maskPattern) && 97 IsValidMaskPattern(m_maskPattern) &&
87 m_numTotalBytes == m_numDataBytes + m_numECBytes && m_matrix && 98 m_numTotalBytes == m_numDataBytes + m_numECBytes && m_matrix &&
88 m_matrixWidth == m_matrix->GetWidth() && 99 m_matrixWidth == m_matrix->GetWidth() &&
89 m_matrix->GetWidth() == m_matrix->GetHeight(); 100 m_matrix->GetWidth() == m_matrix->GetHeight();
90 } 101 }
102
91 void CBC_QRCoder::SetMode(CBC_QRCoderMode* value) { 103 void CBC_QRCoder::SetMode(CBC_QRCoderMode* value) {
92 m_mode = value; 104 m_mode = value;
93 } 105 }
106
94 void CBC_QRCoder::SetECLevel(CBC_QRCoderErrorCorrectionLevel* ecLevel) { 107 void CBC_QRCoder::SetECLevel(CBC_QRCoderErrorCorrectionLevel* ecLevel) {
95 m_ecLevel = ecLevel; 108 m_ecLevel = ecLevel;
96 } 109 }
110
97 void CBC_QRCoder::SetVersion(int32_t version) { 111 void CBC_QRCoder::SetVersion(int32_t version) {
98 m_version = version; 112 m_version = version;
99 } 113 }
114
100 void CBC_QRCoder::SetMatrixWidth(int32_t width) { 115 void CBC_QRCoder::SetMatrixWidth(int32_t width) {
101 m_matrixWidth = width; 116 m_matrixWidth = width;
102 } 117 }
118
103 void CBC_QRCoder::SetMaskPattern(int32_t pattern) { 119 void CBC_QRCoder::SetMaskPattern(int32_t pattern) {
104 m_maskPattern = pattern; 120 m_maskPattern = pattern;
105 } 121 }
122
106 void CBC_QRCoder::SetNumDataBytes(int32_t bytes) { 123 void CBC_QRCoder::SetNumDataBytes(int32_t bytes) {
107 m_numDataBytes = bytes; 124 m_numDataBytes = bytes;
108 } 125 }
126
109 void CBC_QRCoder::SetNumTotalBytes(int32_t value) { 127 void CBC_QRCoder::SetNumTotalBytes(int32_t value) {
110 m_numTotalBytes = value; 128 m_numTotalBytes = value;
111 } 129 }
130
112 void CBC_QRCoder::SetNumRSBlocks(int32_t block) { 131 void CBC_QRCoder::SetNumRSBlocks(int32_t block) {
113 m_numRSBlocks = block; 132 m_numRSBlocks = block;
114 } 133 }
134
115 void CBC_QRCoder::SetNumECBytes(int32_t value) { 135 void CBC_QRCoder::SetNumECBytes(int32_t value) {
116 m_numECBytes = value; 136 m_numECBytes = value;
117 } 137 }
118 FX_BOOL CBC_QRCoder::IsValidMaskPattern(int32_t maskPattern) { 138
119 return maskPattern >= 0 && maskPattern < NUM_MASK_PATTERNS; 139 bool CBC_QRCoder::IsValidMaskPattern(int32_t maskPattern) {
140 return maskPattern >= 0 && maskPattern < kNumMaskPatterns;
120 } 141 }
121 void CBC_QRCoder::SetMatrix(CBC_CommonByteMatrix* value) { 142
122 m_matrix = value; 143 void CBC_QRCoder::SetMatrix(std::unique_ptr<CBC_CommonByteMatrix> pMatrix) {
144 m_matrix = std::move(pMatrix);
123 } 145 }
124 const int32_t CBC_QRCoder::NUM_MASK_PATTERNS = 8;
OLDNEW
« no previous file with comments | « xfa/fxbarcode/qrcode/BC_QRCoder.h ('k') | xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698