3638318fd00e1924dc384a0a24643ebef053ad00
[zxing.git] / cpp / core / src / zxing / oned / UPCAReader.cpp
1 /*
2  *  UPCAReader.cpp
3  *  ZXing
4  *
5  *  Created by Lukasz Warchol on 10-01-25.
6  *  Copyright 2010 ZXing authors All rights reserved.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20
21 #include "UPCAReader.h"
22 #include <zxing/ReaderException.h>
23
24 namespace zxing {
25         namespace oned {
26                 UPCAReader::UPCAReader() : ean13Reader() {
27                 }
28                 
29                 Ref<Result> UPCAReader::decodeRow(int rowNumber, Ref<BitArray> row){
30                         return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row)); 
31                 }
32                 Ref<Result> UPCAReader::decodeRow(int rowNumber, Ref<BitArray> row, int startGuardRange[]){
33                         return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, startGuardRange));
34                 }
35                 Ref<Result> UPCAReader::decode(Ref<BinaryBitmap> image, DecodeHints hints){
36                         return maybeReturnResult(ean13Reader.decode(image, hints));
37                 }
38                 
39                 int UPCAReader::decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen, std::string& resultString){
40                         return ean13Reader.decodeMiddle(row, startRange, startRangeLen, resultString);
41                 }
42                 
43                 Ref<Result> UPCAReader::maybeReturnResult(Ref<Result> result){
44                         const std::string& text = (result->getText())->getText();
45                         if (text[0] == '0') {
46                                 Ref<String> resultString(new String(text.substr(1)));
47                                 Ref<Result> res(new Result(resultString, result->getRawBytes(), result->getResultPoints(), BarcodeFormat_UPC_A));
48                                 return res;
49                         } else {
50                                 throw ReaderException("Not UPC-A barcode.");
51                         }
52                 }
53
54                 
55                 BarcodeFormat UPCAReader::getBarcodeFormat(){
56                         return BarcodeFormat_UPC_A;
57                 }
58         }
59 }