00001 #ifndef BITS_HEADER
00002 #define BITS_HEADER
00003
00004
00005
00011
00012
00013
00014
00015 #include <stddef.h>
00016 #include <string.h>
00017
00018 #ifdef _STANDARD_C_PLUS_PLUS
00019 #include <iostream>
00020 #include <iomanip>
00021 #include <climits>
00022 using namespace std;
00023 #else
00024 #include <iostream.h>
00025 #include <iomanip.h>
00026 #include <limits.h>
00027 #endif
00028
00029
00030
00031 #include "Rangedimexc.hh"
00032
00033
00034
00035 namespace RazorBack {
00036
00042 class Bits_
00043 {
00044
00045 private:
00046
00047 static const size_t BITS_PER_CHAR;
00048 static const size_t BITS_PER_UINT;
00049
00050 unsigned int *B;
00051 size_t Cs, Bs;
00052
00053
00054 public:
00055
00060 explicit Bits_(unsigned int N=0, bool Val=false);
00061
00063 Bits_(const Bits_& Bits);
00064
00072 explicit Bits_(const char *Str);
00073
00075 ~Bits_() { delete [] B; }
00076
00078 Bits_& operator=(const Bits_& Rhs);
00079
00084 bool operator==(const Bits_& Other) const;
00085
00087 bool operator!=(const Bits_& Other) const;
00088
00090 unsigned int cno() const { return(Cs); }
00091
00097 bool get_bit(unsigned int Idx) const;
00098
00105 bool set_bit(unsigned int Idx, bool Value=true);
00106
00108 void set_values(bool Value=true);
00109
00111 unsigned int len() const { return(Bs); }
00119 unsigned int len(unsigned int Len);
00120
00122 unsigned int on_no() const;
00123
00125 unsigned int off_no() const;
00126
00128
00135 Bits_& operator~();
00136 Bits_& operator&=(const Bits_& Bits);
00137 Bits_& operator|=(const Bits_& Bits);
00138 Bits_& operator^=(const Bits_& Bits);
00139 Bits_ operator&(const Bits_& Bits) const;
00140 Bits_ operator|(const Bits_& Bits) const;
00141 Bits_ operator^(const Bits_& Bits) const;
00142
00143
00144
00151 Bits_& operator<<=(unsigned int Shift);
00152 Bits_& operator>>=(unsigned int Shift);
00153 Bits_ operator<<(unsigned int Shift) const;
00154 Bits_ operator>>(unsigned int Shift) const;
00155
00156
00157
00169 friend istream& operator>>(istream& In, Bits_& Bits);
00170
00172 friend ostream& operator<<(ostream& Out, const Bits_& Bits);
00173
00175 protected:
00176
00177 static unsigned int uints_needed(unsigned int Bitno);
00178 static unsigned int get_mask(unsigned int Idx, unsigned int& Offs);
00179 static unsigned int* alloc_arr(unsigned int Size, const unsigned int *Arr=NULL);
00180 unsigned int zero_mask() const;
00181
00182 private:
00183 unsigned int read_dataline(istream& In, char *Buffer);
00184
00185 };
00186
00187
00188 }
00189
00190
00191
00192 #endif // BITS_HEADER