rssoft  0.0.0
Reed-Solomon codes library with soft decision decoding
/shared/development/google_code/rssoft/library/lib/GF2_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(2) class
00024 
00025 */
00026 #ifndef __GF2_ELEMENT_H__
00027 #define __GF2_ELEMENT_H__
00028 
00029 #include "GF_Exception.h"
00030 #include <iostream>
00031 
00032 namespace rssoft
00033 {
00034 namespace gf
00035 {
00036 typedef unsigned char GF2_Symbol; 
00037 
00038 class GF2_Element
00039 {
00040 
00041 public:
00042 
00043         GF2_Element(GF2_Symbol v = 0);
00044         GF2_Element(const GF2_Element& gfe);
00045         ~GF2_Element()
00046         {
00047         }
00048 
00049         inline unsigned int uint_value() const
00050         {
00051                 return (unsigned int) bin_value;
00052         }
00053 
00054         inline GF2_Element& operator=(const GF2_Element& gfe)
00055         {
00056                 if (this != &gfe)
00057                 {
00058                         bin_value = gfe.bin_value;
00059                 }
00060 
00061                 return *this;
00062         }
00063 
00064         inline GF2_Element& operator=(const GF2_Symbol& v)
00065         {
00066                 bin_value = (v ? 1 : 0);
00067                 return *this;
00068         }
00069 
00070         inline GF2_Element& operator+=(const GF2_Element& gfe)
00071         {
00072                 bin_value ^= gfe.bin_value;
00073                 return *this;
00074         }
00075 
00076         inline GF2_Element& operator+=(const GF2_Symbol& v)
00077         {
00078                 bin_value ^= (v ? 1 : 0);
00079                 return *this;
00080         }
00081 
00082         inline GF2_Element& operator-=(const GF2_Element& gfe)
00083         {
00084                 *this += gfe;
00085                 return *this;
00086         }
00087 
00088         inline GF2_Element& operator-=(const GF2_Symbol& v)
00089         {
00090                 *this += (v ? 1 : 0);
00091                 return *this;
00092         }
00093 
00094         inline GF2_Element& operator*=(const GF2_Element& gfe)
00095         {
00096                 bin_value *= gfe.bin_value;
00097                 return *this;
00098         }
00099 
00100         inline GF2_Element& operator*=(const GF2_Symbol& v)
00101         {
00102                 bin_value *= (v ? 1 : 0);
00103                 return *this;
00104         }
00105 
00106         inline GF2_Element& operator/=(const GF2_Element& gfe)
00107         {
00108                 if (gfe.bin_value == 0)
00109                 {
00110                         throw GF_Exception("Division by zero");
00111                 }
00112 
00113                 return *this;
00114         }
00115 
00116         inline GF2_Element& operator/=(const GF2_Symbol& v)
00117         {
00118                 if (!v)
00119                 {
00120                         throw GF_Exception("Division by zero");
00121                 }
00122 
00123                 return *this;
00124         }
00125 
00126         inline GF2_Element& operator^=(const int& n)
00127         {
00128                 return *this;
00129         }
00130 
00131         inline bool operator==(const GF2_Element& gfe) const
00132         {
00133                 return (bin_value == gfe.bin_value);
00134         }
00135 
00136         inline bool operator==(const GF2_Symbol& v) const
00137         {
00138                 return (bin_value == (v ? 1 : 0));
00139         }
00140 
00141         inline bool operator!=(const GF2_Element& gfe) const
00142         {
00143                 return (bin_value != gfe.bin_value);
00144         }
00145 
00146         inline bool operator!=(const GF2_Symbol& v) const
00147         {
00148                 return (bin_value != (v ? 1 : 0));
00149         }
00150 
00151         inline bool operator<(const GF2_Element& gfe)
00152         {
00153                 return (bin_value < gfe.bin_value);
00154         }
00155 
00156         inline bool operator<(const GF2_Symbol& v)
00157         {
00158                 return (bin_value < (v ? 1 : 0));
00159         }
00160 
00161         inline bool operator>(const GF2_Element& gfe)
00162         {
00163                 return (bin_value > gfe.bin_value);
00164         }
00165 
00166         inline bool operator>(const GF2_Symbol& v)
00167         {
00168                 return (bin_value > (v ? 1 : 0));
00169         }
00170 
00171         friend std::ostream& operator <<(std::ostream& os,
00172                         const GF2_Element& gfe);
00173 
00174 private:
00175         unsigned char bin_value; 
00176 };
00177 
00178 GF2_Element operator +(const GF2_Element& a, const GF2_Element& b);
00179 GF2_Element operator -(const GF2_Element& a, const GF2_Element& b);
00180 GF2_Element operator *(const GF2_Element& a, const GF2_Element& b);
00181 GF2_Element operator *(const GF2_Element& a, const GF2_Symbol& b);
00182 GF2_Element operator *(const GF2_Symbol& a, const GF2_Element& b);
00183 GF2_Element operator /(const GF2_Element& a, const GF2_Element& b);
00184 GF2_Element operator ^(const GF2_Element& a, const int& b);
00185 
00186 } // namespacegf
00187 } // namespace rssoft
00188 
00189 #endif // __GF2_ELEMENT_H__
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines