00001 00029 #ifndef BINARY_H 00030 #define BINARY_H 00031 00032 #include <itpp/base/itassert.h> 00033 00034 00035 namespace itpp 00036 { 00037 00056 class bin 00057 { 00058 public: 00060 bin(): b(0) {} 00061 00063 bin(const int &value): b(static_cast<char>(value)) { 00064 it_assert_debug((value == 0) || (value == 1), 00065 "bin::bin(): value must be 0 or 1"); 00066 } 00067 00069 bin(const bin &inbin): b(inbin.b) {} 00070 00072 void operator=(const int &value) { 00073 it_assert_debug((value == 0) || (value == 1), 00074 "bin::operator=(): value must be 0 or 1"); 00075 b = static_cast<char>(value); 00076 } 00077 00079 void operator=(const bin &inbin) { b = inbin.b; } 00080 00082 void operator/=(const bin &inbin) { b |= inbin.b; } 00083 00085 void operator|=(const bin &inbin) { b |= inbin.b; } 00087 bin operator/(const bin &inbin) const { return bin(b | inbin.b); } 00089 bin operator|(const bin &inbin) const { return bin(b | inbin.b); } 00090 00092 void operator+=(const bin &inbin) { b ^= inbin.b; } 00094 void operator^=(const bin &inbin) { b ^= inbin.b; } 00096 bin operator+(const bin &inbin) const { return bin(b ^ inbin.b); } 00098 bin operator^(const bin &inbin) const { return bin(b ^ inbin.b); } 00100 void operator-=(const bin &inbin) { b ^= inbin.b; } 00102 bin operator-(const bin &inbin) const { return bin(b ^ inbin.b); } 00104 bin operator-() const { return bin(b); } 00105 00107 void operator*=(const bin &inbin) { b &= inbin.b; } 00109 void operator&=(const bin &inbin) { b &= inbin.b; } 00111 bin operator*(const bin &inbin) const { return bin(b & inbin.b); } 00113 bin operator&(const bin &inbin) const { return bin(b & inbin.b); } 00114 00116 bin operator!(void) const { return bin(b ^ 1); } 00118 bin operator~(void) const { return bin(b ^ 1); } 00119 00121 bool operator==(const bin &inbin) const { return b == inbin.b; } 00123 bool operator==(const int &i) const { return b == i; } 00124 00126 bool operator!=(const bin &inbin) const { return b != inbin.b; } 00128 bool operator!=(const int &i) const { return b != i; } 00129 00131 bool operator<(const bin &inbin) const { return b < inbin.b; } 00133 bool operator<=(const bin &inbin) const { return b <= inbin.b; } 00134 00136 bool operator>(const bin &inbin) const { return b > inbin.b; } 00138 bool operator>=(const bin &inbin) const { return b >= inbin.b; } 00139 00141 operator short() const { return static_cast<short>(b); } 00143 operator int() const { return static_cast<int>(b); } 00145 operator bool() const { return b != 0; } 00147 operator float() const { return static_cast<float>(b); } 00149 operator double() const { return static_cast<double>(b); } 00150 00152 char value() const { return b; } 00153 00154 private: 00155 char b; 00156 }; 00157 00162 std::ostream &operator<<(std::ostream &output, const bin &inbin); 00163 00168 std::istream &operator>>(std::istream &input, bin &outbin); 00169 00174 inline bin abs(const bin &inbin) { return inbin; } 00175 00176 } // namespace itpp 00177 00178 00179 namespace std // added 11/2005, EGL 00180 { 00181 00186 inline int abs(const itpp::bin &inbin) { return inbin; } 00187 00188 } // namespace std 00189 00190 #endif // #ifndef BINARY_H 00191