00001 00030 #ifndef BINARY_H 00031 #define BINARY_H 00032 00033 #include <itpp/base/itassert.h> 00034 00035 00036 namespace itpp { 00037 00056 class bin { 00057 public: 00059 bin(): b(0) {} 00060 00062 bin(const int &value): b(static_cast<char>(value)) { 00063 it_assert_debug((value == 0) || (value == 1), 00064 "bin::bin(): value must be 0 or 1"); 00065 } 00066 00068 bin(const bin &inbin): b(inbin.b) {} 00069 00071 void operator=(const int &value) { 00072 it_assert_debug((value == 0) || (value == 1), 00073 "bin::operator=(): value must be 0 or 1"); 00074 b = static_cast<char>(value); 00075 } 00076 00078 void operator=(const bin &inbin) { b = inbin.b; } 00079 00081 void operator/=(const bin &inbin) { b |= inbin.b; } 00082 00084 void operator|=(const bin &inbin) { b |= inbin.b; } 00086 bin operator/(const bin &inbin) const { return bin(b | inbin.b); } 00088 bin operator|(const bin &inbin) const { return bin(b | inbin.b); } 00089 00091 void operator+=(const bin &inbin) { b ^= inbin.b; } 00093 void operator^=(const bin &inbin) { b ^= inbin.b; } 00095 bin operator+(const bin &inbin) const { return bin(b ^ inbin.b); } 00097 bin operator^(const bin &inbin) const { return bin(b ^ inbin.b); } 00099 void operator-=(const bin &inbin) { b ^= inbin.b; } 00101 bin operator-(const bin &inbin) const { return bin(b ^ inbin.b); } 00103 bin operator-() const { return bin(b); } 00104 00106 void operator*=(const bin &inbin) { b &= inbin.b; } 00108 void operator&=(const bin &inbin) { b &= inbin.b; } 00110 bin operator*(const bin &inbin) const { return bin(b & inbin.b); } 00112 bin operator&(const bin &inbin) const { return bin(b & inbin.b); } 00113 00115 bin operator!(void) const { return bin(b^1); } 00117 bin operator~(void) const { return bin(b^1); } 00118 00120 bool operator==(const bin &inbin) const { return b == inbin.b; } 00122 bool operator==(const int &i) const { return b == i; } 00123 00125 bool operator!=(const bin &inbin) const { return b != inbin.b; } 00127 bool operator!=(const int &i) const { return b != i; } 00128 00130 bool operator<(const bin &inbin) const { return b < inbin.b; } 00132 bool operator<=(const bin &inbin) const { return b <= inbin.b; } 00133 00135 bool operator>(const bin &inbin) const { return b > inbin.b; } 00137 bool operator>=(const bin &inbin) const { return b >= inbin.b; } 00138 00140 operator short() const { return static_cast<short>(b); } 00142 operator int() const { return static_cast<int>(b); } 00144 operator bool() const { return b != 0; } 00146 operator float() const { return static_cast<float>(b); } 00148 operator double() const { return static_cast<double>(b); } 00149 00151 char value() const { return b; } 00152 00153 private: 00154 char b; 00155 }; 00156 00161 std::ostream &operator<<(std::ostream &output, const bin &inbin); 00162 00167 std::istream &operator>>(std::istream &input, bin &outbin); 00168 00173 inline bin abs(const bin &inbin) { return inbin; } 00174 00175 } // namespace itpp 00176 00177 00178 namespace std { // added 11/2005, EGL 00179 00184 inline int abs(const itpp::bin &inbin) { return inbin; } 00185 00186 } // namespace std 00187 00188 #endif // #ifndef BINARY_H 00189
Generated on Sat Apr 19 10:41:54 2008 for IT++ by Doxygen 1.5.5