Standardize and update all copyright statements to name "ZXing authors" as suggested...
[zxing.git] / cpp / core / src / qrcode / decoder / Version.h
1 #ifndef __VERSION_H__
2 #define __VERSION_H__
3
4 /*
5  *  Version.h
6  *  zxing
7  *
8  *  Created by Christian Brunschen on 14/05/2008.
9  *  Copyright 2008 ZXing authors All rights reserved.
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23
24 #include "../../common/Counted.h"
25 #include "ErrorCorrectionLevel.h"
26 #include "../../ReaderException.h"
27 #include "../../common/BitMatrix.h"
28 #include <vector>
29 #include <valarray>
30
31 namespace qrcode {
32   namespace decoder {
33     using namespace std;
34     using namespace common;
35         
36     class Version : public Counted {
37     public:
38       class ECB {
39       private:
40         int count_;
41         int dataCodewords_;
42       public:
43         ECB(int count, int dataCodewords) : 
44         count_(count), dataCodewords_(dataCodewords) { }
45         int getCount() { return count_; }
46         int getDataCodewords() { return dataCodewords_; }
47       };
48       
49       class ECBlocks { 
50       private:
51         int ecCodewords_;
52         vector<ECB*> ecBlocks_;
53       public:
54         ECBlocks(int ecCodewords, ECB *ecBlocks) : ecCodewords_(ecCodewords) {
55           ecBlocks_.push_back(ecBlocks);
56         }
57         ECBlocks(int ecCodewords, ECB *ecBlocks1, ECB *ecBlocks2) : 
58         ecCodewords_(ecCodewords) {
59           ecBlocks_.push_back(ecBlocks1);
60           ecBlocks_.push_back(ecBlocks2);
61         }
62         int getECCodewords() { return ecCodewords_; }
63         vector<ECB*>& getECBlocks() { return ecBlocks_; }
64       };
65       
66       
67     private:      
68       int versionNumber_;
69       valarray<int> &alignmentPatternCenters_;
70       vector<ECBlocks*> ecBlocks_;
71       int totalCodewords_;
72       Version(int versionNumber,
73               valarray<int> *alignmentPatternCenters,
74               ECBlocks *ecBlocks1,
75               ECBlocks *ecBlocks2,
76               ECBlocks *ecBlocks3,
77               ECBlocks *ecBlocks4);
78       
79     public:
80       static unsigned int VERSION_DECODE_INFO[];
81       static int N_VERSION_DECODE_INFOS;
82       static vector<Version*> VERSIONS;
83       
84       int getVersionNumber();
85       valarray<int> &getAlignmentPatternCenters();
86       int getTotalCodewords();
87       int getDimensionForVersion();
88       ECBlocks &getECBlocksForLevel(ErrorCorrectionLevel &ecLevel);
89       static Version *getProvisionalVersionForDimension(int dimension);
90       static Version *getVersionForNumber(int versionNumber);
91       static Version *decodeVersionInformation(unsigned int versionBits);
92       Ref<BitMatrix> buildFunctionPattern();
93       static int buildVersions();
94     };
95   }
96 }
97
98 #endif // __VERSION_H__