Converted tabs to spaces.
[zxing.git] / cpp / core / src / zxing / oned / MultiFormatOneDReader.cpp
1 /*
2  *  MultiFormatOneDReader.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 "MultiFormatOneDReader.h"
21
22 #include <zxing/oned/MultiFormatUPCEANReader.h>
23 #include <zxing/oned/Code39Reader.h>
24 #include <zxing/oned/Code128Reader.h>
25 #include <zxing/oned/ITFReader.h>
26 #include <zxing/ReaderException.h>
27
28 namespace zxing {
29   namespace oned {
30     MultiFormatOneDReader::MultiFormatOneDReader(DecodeHints hints) : readers() {
31       if (hints.containsFormat(BarcodeFormat_EAN_13) ||
32           hints.containsFormat(BarcodeFormat_EAN_8) ||
33           hints.containsFormat(BarcodeFormat_UPC_A) ||
34           hints.containsFormat(BarcodeFormat_UPC_E)) {
35         readers.push_back(Ref<OneDReader>(new MultiFormatUPCEANReader(hints)));
36       }
37       if (hints.containsFormat(BarcodeFormat_CODE_39)) {
38         readers.push_back(Ref<OneDReader>(new Code39Reader()));
39       }
40       if (hints.containsFormat(BarcodeFormat_CODE_128)) {
41         readers.push_back(Ref<OneDReader>(new Code128Reader()));
42       }
43       if (hints.containsFormat(BarcodeFormat_ITF)) {
44         readers.push_back(Ref<OneDReader>(new ITFReader()));
45       }
46       if (readers.size() == 0) {
47         readers.push_back(Ref<OneDReader>(new MultiFormatUPCEANReader(hints)));
48         readers.push_back(Ref<OneDReader>(new Code39Reader()));
49         readers.push_back(Ref<OneDReader>(new Code128Reader()));
50         readers.push_back(Ref<OneDReader>(new ITFReader()));
51       }
52     }
53
54     Ref<Result> MultiFormatOneDReader::decodeRow(int rowNumber, Ref<BitArray> row) {
55       int size = readers.size();
56       for (int i = 0; i < size; i++) {
57         OneDReader* reader = readers[i];
58         Ref<Result> result = reader->decodeRow(rowNumber, row);
59         if (!result.empty()) {
60           return result;
61         }
62       }
63       return Ref<Result>();
64     }
65   }
66 }