Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa / src / fxbarcode / src / BC_QRCoderErrorCorrectionLevel.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #include "barcode.h"\r
8 #include "include/BC_QRCoderErrorCorrectionLevel.h"\r
9 CBC_QRCoderErrorCorrectionLevel* CBC_QRCoderErrorCorrectionLevel::L = NULL;\r
10 CBC_QRCoderErrorCorrectionLevel* CBC_QRCoderErrorCorrectionLevel::M = NULL;\r
11 CBC_QRCoderErrorCorrectionLevel* CBC_QRCoderErrorCorrectionLevel::Q = NULL;\r
12 CBC_QRCoderErrorCorrectionLevel* CBC_QRCoderErrorCorrectionLevel::H = NULL;\r
13 CBC_QRCoderErrorCorrectionLevel::CBC_QRCoderErrorCorrectionLevel(FX_INT32 ordinal, FX_INT32 bits, FX_CHAR* name)\r
14 {\r
15     m_name += name;\r
16     m_ordinal = ordinal;\r
17     m_bits = bits;\r
18 }\r
19 CBC_QRCoderErrorCorrectionLevel::~CBC_QRCoderErrorCorrectionLevel()\r
20 {\r
21 }\r
22 void CBC_QRCoderErrorCorrectionLevel::Initialize()\r
23 {\r
24     L = FX_NEW CBC_QRCoderErrorCorrectionLevel(0, 0x01, (FX_CHAR*)"L");\r
25     M = FX_NEW CBC_QRCoderErrorCorrectionLevel(1, 0x00, (FX_CHAR*)"M");\r
26     Q = FX_NEW CBC_QRCoderErrorCorrectionLevel(2, 0x03, (FX_CHAR*)"Q");\r
27     H = FX_NEW CBC_QRCoderErrorCorrectionLevel(3, 0x02, (FX_CHAR*)"H");\r
28 }\r
29 void CBC_QRCoderErrorCorrectionLevel::Finalize()\r
30 {\r
31     delete L;\r
32     delete M;\r
33     delete Q;\r
34     delete H;\r
35 }\r
36 FX_INT32 CBC_QRCoderErrorCorrectionLevel::Ordinal()\r
37 {\r
38     return m_ordinal;\r
39 }\r
40 FX_INT32 CBC_QRCoderErrorCorrectionLevel::GetBits()\r
41 {\r
42     return m_bits;\r
43 }\r
44 CFX_ByteString CBC_QRCoderErrorCorrectionLevel::GetName()\r
45 {\r
46     return m_name;\r
47 }\r
48 CBC_QRCoderErrorCorrectionLevel* CBC_QRCoderErrorCorrectionLevel::ForBits(FX_INT32 bits)\r
49 {\r
50     switch(bits) {\r
51         case 0x00:\r
52             return M;\r
53         case 0x01:\r
54             return L;\r
55         case 0x02:\r
56             return H;\r
57         case 0x03:\r
58             return Q;\r
59         default:\r
60             return NULL;\r
61     }\r
62 }\r
63 void CBC_QRCoderErrorCorrectionLevel::Destroy()\r
64 {\r
65     if(L) {\r
66         delete CBC_QRCoderErrorCorrectionLevel::L;\r
67         L = NULL;\r
68     }\r
69     if(M) {\r
70         delete CBC_QRCoderErrorCorrectionLevel::M;\r
71         M = NULL;\r
72     }\r
73     if(H) {\r
74         delete CBC_QRCoderErrorCorrectionLevel::H;\r
75         H = NULL;\r
76     }\r
77     if(Q) {\r
78         delete CBC_QRCoderErrorCorrectionLevel::Q;\r
79         Q = NULL;\r
80     }\r
81 }\r