Small style stuff
[zxing.git] / cpp / core / src / zxing / common / reedsolomon / GF256.h
1 #ifndef __GF256_H__
2 #define __GF256_H__
3
4 /*
5  *  GF256.h
6  *  zxing
7  *
8  *  Copyright 2010 ZXing authors All rights reserved.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22
23 #include <memory>
24 #include <vector>
25 #include <zxing/common/Counted.h>
26
27 namespace zxing {
28 class GF256Poly;
29
30 class GF256 {
31   /**
32    * <p>This class contains utility methods for performing mathematical
33    * operations over the Galois Field GF(256). Operations use a given
34    * primitive polynomial in calculations.</p>
35    *
36    * <p>Throughout this package, elements of GF(256) are represented as an
37    * <code>int</code> for convenience and speed (but at the cost of memory).
38    * Only the bottom 8 bits are really used.</p>
39    *
40    * @author srowen@google.com (Sean Owen)
41    * @author christian.brunschen@gmail.com (Christian Brunschen)
42    */
43 private:
44   std::vector<int> exp_;
45   std::vector<int> log_;
46   Ref<GF256Poly> zero_;
47   Ref<GF256Poly> one_;
48
49   GF256(int primitive);
50
51 public:
52   Ref<GF256Poly> getZero();
53   Ref<GF256Poly> getOne();
54   Ref<GF256Poly> buildMonomial(int degree, int coefficient);
55   static int addOrSubtract(int a, int b);
56   int exp(int a);
57   int log(int a);
58   int inverse(int a);
59   int multiply(int a, int b);
60
61   static GF256 QR_CODE_FIELD;
62   static GF256 DATA_MATRIX_FIELD;
63
64   friend std::ostream& operator<<(std::ostream& out, const GF256& field);
65 };
66 }
67
68 #endif // __GF256_H__