5a9da76f02343747c6018386fad5065544a2bd7e
[zxing.git] / cpp / core / src / zxing / DecodeHints.cpp
1 /*
2  *  DecodeHintType.cpp
3  *  zxing
4  *
5  *  Copyright 2010 ZXing authors All rights reserved.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <zxing/DecodeHints.h>
21 #include <zxing/common/IllegalArgumentException.h>
22 namespace zxing {
23
24 DecodeHints::DecodeHints() {
25   hints = 0;
26 }
27
28 DecodeHints::DecodeHints(DecodeHintType init) {
29   hints = init;
30 }
31
32 DecodeHints::~DecodeHints() {
33   // if DecodeHintType requires a destructor in the future, call it here
34 }
35
36 void DecodeHints::addFormat(BarcodeFormat toadd) {
37   switch (toadd) {
38     case BarcodeFormat_QR_CODE: hints |= BARCODEFORMAT_QR_CODE_HINT; break;
39     case BarcodeFormat_DATA_MATRIX: hints |= BARCODEFORMAT_DATA_MATRIX_HINT; break;
40     case BarcodeFormat_UPC_E: hints |= BARCODEFORMAT_UPC_E_HINT; break;
41     case BarcodeFormat_UPC_A: hints |= BARCODEFORMAT_UPC_A_HINT; break;
42     case BarcodeFormat_EAN_8: hints |= BARCODEFORMAT_EAN_8_HINT; break;
43     case BarcodeFormat_EAN_13: hints |= BARCODEFORMAT_EAN_13_HINT; break;
44     case BarcodeFormat_CODE_128: hints |= BARCODEFORMAT_CODE_128_HINT; break;
45     case BarcodeFormat_CODE_39: hints |= BARCODEFORMAT_CODE_39_HINT; break;
46     case BarcodeFormat_ITF: hints |= BARCODEFORMAT_ITF_HINT; break;
47     default: throw IllegalArgumentException("Unrecognizd barcode format");
48   }
49 }
50
51 bool DecodeHints::containsFormat(BarcodeFormat tocheck) const {
52   DecodeHintType checkAgainst;
53   switch (tocheck) {
54     case BarcodeFormat_QR_CODE: checkAgainst = BARCODEFORMAT_QR_CODE_HINT; break;
55     case BarcodeFormat_DATA_MATRIX: checkAgainst = BARCODEFORMAT_DATA_MATRIX_HINT; break;
56     case BarcodeFormat_UPC_E: checkAgainst = BARCODEFORMAT_UPC_E_HINT; break;
57     case BarcodeFormat_UPC_A: checkAgainst = BARCODEFORMAT_UPC_A_HINT; break;
58     case BarcodeFormat_EAN_8: checkAgainst = BARCODEFORMAT_EAN_8_HINT; break;
59     case BarcodeFormat_EAN_13: checkAgainst = BARCODEFORMAT_EAN_13_HINT; break;
60     case BarcodeFormat_CODE_128: checkAgainst = BARCODEFORMAT_CODE_128_HINT; break;
61     case BarcodeFormat_CODE_39: checkAgainst = BARCODEFORMAT_CODE_39_HINT; break;
62     case BarcodeFormat_ITF: checkAgainst = BARCODEFORMAT_ITF_HINT; break;
63     default: throw IllegalArgumentException("Unrecognizd barcode format");
64   }
65   return (hints & checkAgainst);
66 }
67
68 void DecodeHints::setTryHarder(bool toset) {
69   if (toset) {
70     hints |= TRYHARDER_HINT;
71   } else {
72     hints &= ~TRYHARDER_HINT;
73   }
74 }
75
76 bool DecodeHints::getTryHarder() const {
77   return (hints & TRYHARDER_HINT);
78 }
79
80 } /* namespace */