IT++ Logo Newcom Logo

binary.h

Go to the documentation of this file.
00001 
00033 #ifndef BINARY_H
00034 #define BINARY_H
00035 
00036 #include <itpp/base/itassert.h>
00037 
00038 
00039 namespace itpp {
00040 
00059   class bin {
00060   public:
00062     bin() { b=0; }
00063     
00065     bin(const short value) {
00066       it_assert0(value==0 || value==1, "bin(value): value must be 0 or 1");
00067       b = static_cast<char>(value);
00068     }
00069 
00071     bin(const bin &inbin) { b=inbin.b; }
00072 
00074     void operator=(const short &value) {
00075       it_assert0(value==0 || value==1, "bin(value): value must be 0 or 1");
00076       b = static_cast<char>(value);
00077     }
00078 
00080     void operator=(const bin &inbin)   { b=inbin.b; }
00081 
00083     void operator/=(const bin &inbin) { b=b|inbin.b; }
00084 
00086     void operator|=(const bin &inbin) { b=b|inbin.b; }
00088     bin operator/(const bin &inbin) const { return bin(b|inbin.b); }
00090     bin operator|(const bin &inbin) const { return bin(b|inbin.b); }
00091 
00093     void operator+=(const bin &inbin) { b=b^inbin.b; }
00095     void operator^=(const bin &inbin) { b=b^inbin.b; }
00097     bin operator+(const bin &inbin) const { return bin(b^inbin.b); }
00099     bin operator^(const bin &inbin) const { return bin(b^inbin.b); }
00101     void operator-=(const bin &inbin) { b=b^inbin.b; }
00103     bin operator-(const bin &inbin) const {return bin(b^inbin.b); }
00105     bin operator-() const { return bin(b); }
00106         
00108     void operator*=(const bin &inbin) { b=b&inbin.b; }
00110     void operator&=(const bin &inbin) { b=b&inbin.b; }
00112     bin operator*(const bin &inbin) const { return bin(b&inbin.b); }
00114     bin operator&(const bin &inbin) const { return bin(b&inbin.b); }
00115         
00117     bin operator!(void) const { return bin(b^1); }
00119     bin operator~(void) const { return bin(b^1); }
00120 
00122     bool operator==(const bin &inbin) const { return b == inbin.b; }
00124     bool operator==(const int &inbin) const { return b == inbin; }
00125 
00127     bool operator!=(const bin &inbin) const { return b != inbin.b; }
00129     bool operator!=(const int &inbin) const { return b != inbin; }
00130 
00132     bool operator<(const bin &inbin) const  { return b < inbin.b; }
00134     bool operator<=(const bin &inbin) const { return b <= inbin.b; }
00135 
00137     bool operator>(const bin &inbin) const  { return b > inbin.b; }
00139     bool operator>=(const bin &inbin) const { return b >= inbin.b; }
00140         
00142     operator short() const  { return static_cast<short>(b); }
00144     operator int() const    { return static_cast<int>(b); }
00146     operator bool() const   { return b!=0; }
00148     operator float() const  { return static_cast<float>(b); }
00150     operator double() const { return static_cast<double>(b); }
00151 
00153     char value() const { return b; }
00154 
00155   protected:
00156 
00157   private:
00158     char b;
00159   };
00160 
00165   std::ostream &operator<<(std::ostream &output, const bin &inbin);
00166 
00171   std::istream &operator>>(std::istream &input, bin &outbin);
00172 
00177   inline bin abs(const bin &inbin) { return inbin; }
00178 
00179 } // namespace itpp
00180 
00181 namespace std{     // added 11/2005, EGL
00186   inline short abs(const itpp::bin &inbin) { return inbin; }
00187 }
00188 
00189 #endif // #ifndef BINARY_H
00190 
00191 
SourceForge Logo

Generated on Thu Apr 19 14:23:56 2007 for IT++ by Doxygen 1.4.6