rssoft  0.0.0
Reed-Solomon codes library with soft decision decoding
/shared/development/google_code/rssoft/library/lib/GFq_Element.h
Go to the documentation of this file.
00001 /*
00002      Copyright 2013 Edouard Griffiths <f4exb at free dot fr>
00003 
00004      This file is part of RSSoft. A Reed-Solomon Soft Decoding library
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 51 Franklin Street, Boston, MA  02110-1301  USA
00019 
00020          Original from Arash Partow (see original copytight notice).
00021          Modified and included in RSSoft in gf sub-namespace.
00022 
00023          Element in Galois Field GF(q=2^m) class
00024 
00025 */
00026 /*
00027  *********************************************************************
00028  *                                                                   *
00029  *        Galois Field Arithmetic Library (version 0.0.1)            *
00030  *                                                                   *
00031  * Class: Galois Field Element                                       *
00032  * Version: 0.0.1                                                    *
00033  * Author: Arash Partow - 2000                                       *
00034  * URL: http://www.partow.net/projects/galois/index.html             *
00035  *                                                                   *
00036  * Copyright Notice:                                                 *
00037  * Free use of this library is permitted under the guidelines and    *
00038  * in accordance with the most current version of the Common Public  *
00039  * License.                                                          *
00040  * http://www.opensource.org/licenses/cpl.php                        *
00041  *                                                                   *
00042  *********************************************************************
00043  */
00044 
00045 #ifndef __GFQ_ELEMENT_H__
00046 #define __GFQ_ELEMENT_H__
00047 
00048 #include <iostream>
00049 #include <vector>
00050 #include "GFq.h"
00051 
00052 namespace rssoft
00053 {
00054 namespace gf
00055 {
00056 
00057 class GFq_Element
00058 {
00059 
00060 public:
00061 
00062         GFq_Element(const GFq& _gf, GFq_Symbol v = 0);
00063         GFq_Element(const GFq_Element& gfe);
00064         ~GFq_Element()
00065         {
00066         }
00067 
00068         inline GFq_Element& operator=(const GFq_Element& gfe)
00069         {
00070                 if (this == &gfe)
00071                         return *this;
00072 
00073                 const_cast<GFq&>(gf) = gfe.gf;
00074                 poly_value = gfe.poly_value;
00075 
00076                 return *this;
00077         }
00078 
00079         inline GFq_Element& operator=(const GFq_Symbol& v)
00080         {
00081                 poly_value = v & gf.size();
00082                 return *this;
00083         }
00084 
00085         inline GFq_Element& operator+=(const GFq_Element& gfe)
00086         {
00087                 poly_value ^= gfe.poly_value;
00088                 return *this;
00089         }
00090 
00091         inline GFq_Element& operator+=(const GFq_Symbol& v)
00092         {
00093                 poly_value ^= v;
00094                 return *this;
00095         }
00096 
00097         inline GFq_Element& operator-=(const GFq_Element& gfe)
00098         {
00099                 *this += gfe;
00100                 return *this;
00101         }
00102 
00103         inline GFq_Element& operator-=(const GFq_Symbol& v)
00104         {
00105                 *this += v;
00106                 return *this;
00107         }
00108 
00109         inline GFq_Element& operator*=(const GFq_Element& gfe)
00110         {
00111                 poly_value = gf.mul(poly_value, gfe.poly_value);
00112                 return *this;
00113         }
00114 
00115         inline GFq_Element& operator*=(const GFq_Symbol& v)
00116         {
00117                 poly_value = gf.mul(poly_value, v);
00118                 return *this;
00119         }
00120 
00121         inline GFq_Element& operator/=(const GFq_Element& gfe)
00122         {
00123                 poly_value = gf.div(poly_value, gfe.poly_value);
00124                 return *this;
00125         }
00126 
00127         inline GFq_Element& operator/=(const GFq_Symbol& v)
00128         {
00129                 poly_value = gf.div(poly_value, v);
00130                 return *this;
00131         }
00132 
00133         inline GFq_Element& operator^=(const int& n)
00134         {
00135                 poly_value = gf.exp(poly_value, n);
00136                 return *this;
00137         }
00138 
00139         inline bool operator==(const GFq_Element& gfe) const
00140         {
00141                 return ((gf == gfe.gf) && (poly_value == gfe.poly_value));
00142         }
00143 
00144         inline bool operator==(const GFq_Symbol& v) const
00145         {
00146                 return (poly_value == v);
00147         }
00148 
00149         inline bool operator!=(const GFq_Element& gfe) const
00150         {
00151                 return ((gf != gfe.gf) || (poly_value != gfe.poly_value));
00152         }
00153 
00154         inline bool operator!=(const GFq_Symbol& v) const
00155         {
00156                 return (poly_value != v);
00157         }
00158 
00159         inline bool operator<(const GFq_Element& gfe) const
00160         {
00161                 return (poly_value < gfe.poly_value);
00162         }
00163 
00164         inline bool operator<(const GFq_Symbol& v) const
00165         {
00166                 return (poly_value < v);
00167         }
00168 
00169         inline bool operator>(const GFq_Element& gfe) const
00170         {
00171                 return (poly_value > gfe.poly_value);
00172         }
00173 
00174         inline bool operator>(const GFq_Symbol& v) const
00175         {
00176                 return (poly_value > v);
00177         }
00178 
00179         inline GFq_Symbol index() const
00180         {
00181                 return gf.index(poly_value);
00182         }
00183 
00184         inline GFq_Symbol poly() const
00185         {
00186                 return poly_value;
00187         }
00188 
00189         inline const GFq& field() const
00190         {
00191                 return gf;
00192         }
00193 
00194         inline GFq_Symbol inverse() const
00195         {
00196                 return gf.inverse(poly_value);
00197         }
00198 
00199         inline bool is_zero() const
00200         {
00201                 return poly_value == 0;
00202         }
00203 
00204         inline bool is_one() const
00205         {
00206                 return poly_value == 1;
00207         }
00208     
00209         friend std::ostream& operator <<(std::ostream& os,
00210                         const GFq_Element& gfe);
00211             
00212 private:
00213 
00214         const GFq& gf;
00215         GFq_Symbol poly_value;
00216 };
00217 
00218 GFq_Element operator +(const GFq_Element& a, const GFq_Element& b);
00219 GFq_Element operator -(const GFq_Element& a, const GFq_Element& b);
00220 GFq_Element operator *(const GFq_Element& a, const GFq_Element& b);
00221 GFq_Element operator *(const GFq_Element& a, const GFq_Symbol& b);
00222 GFq_Element operator *(const GFq_Symbol& a, const GFq_Element& b);
00223 GFq_Element operator /(const GFq_Element& a, const GFq_Element& b);
00224 GFq_Element operator ^(const GFq_Element& a, const int& b);
00225 
00226 GFq_Symbol gfq_element_to_symbol(const GFq_Element& gfe);
00227 
00228 } // namespace gf
00229 } // namespace rssoft
00230 
00231 #endif // __GFQ_ELEMENT_H__
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines