initialize valarrays with explicit contents (zero)
[zxing.git] / cpp / core / src / common / reedsolomon / GF256.h
1 #ifndef __GF256_H__
2 #define __GF256_H__
3
4 /*
5  *  GF256.h
6  *  zxing
7  *
8  *  Created by Christian Brunschen on 05/05/2008.
9  *  Copyright 2008 Google UK. 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 <memory>
25 #include <valarray>
26 #include "../Counted.h"
27 using namespace std;
28 using namespace common;
29
30 namespace reedsolomon {
31   class GF256Poly;
32   
33         class GF256 {
34     /**
35      * <p>This class contains utility methods for performing mathematical
36      * operations over the Galois Field GF(256). Operations use a given
37      * primitive polynomial in calculations.</p>
38      *
39      * <p>Throughout this package, elements of GF(256) are represented as an
40      * <code>int</code> for convenience and speed (but at the cost of memory).
41      * Only the bottom 8 bits are really used.</p>
42      *
43      * @author srowen@google.com (Sean Owen)
44      * @author christian.brunschen@gmail.com (Christian Brunschen)
45      */
46   private:
47     valarray<int> exp_;
48     valarray<int> log_;
49     Ref<GF256Poly> zero_;
50     Ref<GF256Poly> one_;
51     
52     GF256(int primitive);
53     
54   public:
55     Ref<GF256Poly> getZero();
56     Ref<GF256Poly> getOne();
57     Ref<GF256Poly> buildMonomial(int degree, int coefficient);
58     static int addOrSubtract(int a, int b);
59     int exp(int a);
60     int log(int a);
61     int inverse(int a);
62     int multiply(int a, int b);
63     
64     static GF256 QR_CODE_FIELD;
65     static GF256 DATA_MATRIX_FIELD;
66
67     friend ostream& operator<<(ostream& out, const GF256& field);
68   };
69 }
70
71 #endif // __GF256_H__