1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 // Original code is licensed as follows:
7 /*
8 * Copyright 2007 ZXing authors
9 *
10 * Licensed under the Apache License, Version 2.0 (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
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 */
22
23 #include "fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h"
24
25 CBC_QRCoderErrorCorrectionLevel* CBC_QRCoderErrorCorrectionLevel::L = nullptr;
26 CBC_QRCoderErrorCorrectionLevel* CBC_QRCoderErrorCorrectionLevel::M = nullptr;
27 CBC_QRCoderErrorCorrectionLevel* CBC_QRCoderErrorCorrectionLevel::Q = nullptr;
28 CBC_QRCoderErrorCorrectionLevel* CBC_QRCoderErrorCorrectionLevel::H = nullptr;
29
CBC_QRCoderErrorCorrectionLevel(int32_t ordinal,int32_t bits,const char * name)30 CBC_QRCoderErrorCorrectionLevel::CBC_QRCoderErrorCorrectionLevel(
31 int32_t ordinal,
32 int32_t bits,
33 const char* name)
34 : m_ordinal(ordinal), m_bits(bits), m_name(name) {}
35
~CBC_QRCoderErrorCorrectionLevel()36 CBC_QRCoderErrorCorrectionLevel::~CBC_QRCoderErrorCorrectionLevel() {}
37
Initialize()38 void CBC_QRCoderErrorCorrectionLevel::Initialize() {
39 L = new CBC_QRCoderErrorCorrectionLevel(0, 0x01, "L");
40 M = new CBC_QRCoderErrorCorrectionLevel(1, 0x00, "M");
41 Q = new CBC_QRCoderErrorCorrectionLevel(2, 0x03, "Q");
42 H = new CBC_QRCoderErrorCorrectionLevel(3, 0x02, "H");
43 }
44
Finalize()45 void CBC_QRCoderErrorCorrectionLevel::Finalize() {
46 delete L;
47 delete M;
48 delete Q;
49 delete H;
50 }
51
ForBits(int32_t bits)52 CBC_QRCoderErrorCorrectionLevel* CBC_QRCoderErrorCorrectionLevel::ForBits(
53 int32_t bits) {
54 switch (bits) {
55 case 0x00:
56 return M;
57 case 0x01:
58 return L;
59 case 0x02:
60 return H;
61 case 0x03:
62 return Q;
63 default:
64 return nullptr;
65 }
66 }
Destroy()67 void CBC_QRCoderErrorCorrectionLevel::Destroy() {
68 if (L) {
69 delete CBC_QRCoderErrorCorrectionLevel::L;
70 L = nullptr;
71 }
72 if (M) {
73 delete CBC_QRCoderErrorCorrectionLevel::M;
74 M = nullptr;
75 }
76 if (H) {
77 delete CBC_QRCoderErrorCorrectionLevel::H;
78 H = nullptr;
79 }
80 if (Q) {
81 delete CBC_QRCoderErrorCorrectionLevel::Q;
82 Q = nullptr;
83 }
84 }
85