Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

binary.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*
00002  *                                   IT++                                    *
00003  *---------------------------------------------------------------------------*
00004  * Copyright (c) 1995-2001 by Tony Ottosson, Thomas Eriksson, Pål Frenger,   *
00005  * Tobias Ringström, and Jonas Samuelsson.                                   *
00006  *                                                                           *
00007  * Permission to use, copy, modify, and distribute this software and its     *
00008  * documentation under the terms of the GNU General Public License is hereby *
00009  * granted. No representations are made about the suitability of this        *
00010  * software for any purpose. It is provided "as is" without expressed or     *
00011  * implied warranty. See the GNU General Public License for more details.    *
00012  *---------------------------------------------------------------------------*/
00013 // 
00014 //  SPUC - Signal processing using C++ - A DSP library
00025 #ifndef __binary_h
00026 #define __binary_h
00027 
00028 #include <iostream>
00029 #include <cassert>
00030 using namespace std;
00031 //#include "spucassert.h"
00032 namespace SPUC {
00051 class bin {
00052  public:
00054   bin() { b=0; }
00055     
00057   bin(const short value) {
00058 //    it_assert0(value==0 || value==1, "bin(value): value must be 0 or 1");
00059     b = (char)value;
00060   }
00061 
00062   // Copy constructor
00063   bin(const bin &inbin) { b=inbin.b; }
00064 
00066   void operator=(const short &value) {
00067 //    it_assert0(value==0 || value==1, "bin(value): value must be 0 or 1");
00068     b = (char)value;
00069   }
00070 
00072   void operator=(const bin &inbin)   { b=inbin.b; }
00073 
00075   void operator/=(const bin &inbin) { b=b|inbin.b; }
00076 
00078   void operator|=(const bin &inbin) { b=b|inbin.b; }
00080   bin operator/(const bin &inbin) const { return bin(b|inbin.b); }
00082   bin operator|(const bin &inbin) const { return bin(b|inbin.b); }
00083 
00085   void operator+=(const bin &inbin) { b=b^inbin.b; }
00087   void operator^=(const bin &inbin) { b=b^inbin.b; }
00089   bin operator+(const bin &inbin) const { return bin(b^inbin.b); }
00091   bin operator^(const bin &inbin) const { return bin(b^inbin.b); }
00093   void operator-=(const bin &inbin) { b=b^inbin.b; }
00095   bin operator-(const bin &inbin) const {return bin(b^inbin.b); }
00097   bin operator-() const { return bin(b); }
00098         
00100   void operator*=(const bin &inbin) { b=b&inbin.b; }
00102   void operator&=(const bin &inbin) { b=b&inbin.b; }
00104   bin operator*(const bin &inbin) const { return bin(b&inbin.b); }
00106   bin operator&(const bin &inbin) const { return bin(b&inbin.b); }
00107         
00109   bin operator!(void) const { return bin(b^1); }
00111   bin operator~(void) const { return bin(b^1); }
00112 
00114   bool operator==(const bin &inbin) const { return b == inbin.b; }
00116   bool operator==(const int &inbin) const { return b == inbin; }
00117 
00119   bool operator!=(const bin &inbin) const { return b != inbin.b; }
00121   bool operator!=(const int &inbin) const { return b != inbin; }
00122 
00124   bool operator<(const bin &inbin) const  { return b < inbin.b; }
00126   bool operator<=(const bin &inbin) const { return b <= inbin.b; }
00127 
00129   bool operator>(const bin &inbin) const  { return b > inbin.b; }
00131   bool operator>=(const bin &inbin) const { return b >= inbin.b; }
00132         
00134   operator short() const  { return short(b); }
00136   operator int() const    { return int(b); }
00138   operator bool() const   { return b!=0; }
00140   operator float() const  { return float(b); }
00142   operator double() const { return double(b); }
00143 
00145   char value() const { return b; }
00146 
00147  protected:
00148 
00149  private:
00150   char b;
00151 };
00152 
00158 ostream &operator<<(ostream &output, const bin &inbin);
00159 
00164 istream &operator>>(istream &input, bin &outbin);
00165 } //namespace SPUC 
00166 
00167 #endif // __binary_h

Generated on Fri Sep 16 11:02:25 2005 for spuc by  doxygen 1.4.4