27 class TBits :
public TObject {
35 void ReserveBytes(UInt_t nbytes);
36 void DoAndEqual(
const TBits& rhs);
37 void DoOrEqual (
const TBits& rhs);
38 void DoXorEqual(
const TBits& rhs);
39 void DoLeftShift(UInt_t shift);
40 void DoRightShift(UInt_t shift);
42 void Resize(UInt_t newlen);
45 TBits(UInt_t nbits = 8);
47 TBits& operator=(
const TBits&);
59 TReference(TBits& bit, UInt_t pos) : fBits(bit),fPos(pos) { }
63 TReference& operator=(Bool_t val);
66 TReference& operator=(
const TReference& rhs);
69 Bool_t operator~()
const;
72 operator Bool_t()
const;
77 void ResetAllBits(Bool_t value=kFALSE);
78 void ResetBitNumber(UInt_t bitnumber);
79 void SetBitNumber(UInt_t bitnumber, Bool_t value = kTRUE);
80 Bool_t TestBitNumber(UInt_t bitnumber)
const;
83 TBits::TReference operator[](UInt_t bitnumber) {
return TReference(*
this,bitnumber); }
84 Bool_t operator[](UInt_t bitnumber)
const;
86 TBits& operator&=(
const TBits& rhs) { DoAndEqual(rhs);
return *
this; }
87 TBits& operator|=(
const TBits& rhs) { DoOrEqual(rhs);
return *
this; }
88 TBits& operator^=(
const TBits& rhs) { DoXorEqual(rhs);
return *
this; }
89 TBits& operator<<=(UInt_t rhs) { DoLeftShift(rhs);
return *
this; }
90 TBits& operator>>=(UInt_t rhs) { DoRightShift(rhs);
return *
this; }
91 TBits operator<<(UInt_t rhs) {
return TBits(*
this)<<= rhs; }
92 TBits operator>>(UInt_t rhs) {
return TBits(*
this)>>= rhs; }
93 TBits operator~()
const { TBits res(*
this); res.DoFlip();
return res; }
99 void Set(UInt_t nbits,
const Char_t *array);
100 void Set(UInt_t nbits,
const UChar_t *array) { Set(nbits, (
const Char_t*)array); }
101 void Set(UInt_t nbits,
const Short_t *array);
102 void Set(UInt_t nbits,
const UShort_t *array) { Set(nbits, (
const Short_t*)array); }
103 void Set(UInt_t nbits,
const Int_t *array);
104 void Set(UInt_t nbits,
const UInt_t *array) { Set(nbits, (
const Int_t*)array); }
105 void Set(UInt_t nbits,
const Long64_t *array);
106 void Set(UInt_t nbits,
const ULong64_t *array) { Set(nbits, (
const Long64_t*)array); }
117 void Get(Char_t *array)
const;
118 void Get(UChar_t *array)
const { Get((Char_t*)array); }
119 void Get(Short_t *array)
const;
120 void Get(UShort_t *array)
const { Get((Short_t*)array); }
121 void Get(Int_t *array)
const;
122 void Get(UInt_t *array)
const { Get((Int_t*)array); }
123 void Get(Long64_t *array)
const;
124 void Get(ULong64_t *array)
const { Get((Long64_t*)array); }
127 void Clear(Option_t *option=
"");
129 UInt_t CountBits(UInt_t startBit=0)
const ;
130 UInt_t FirstNullBit(UInt_t startBit=0)
const;
131 UInt_t FirstSetBit(UInt_t startBit=0)
const;
132 UInt_t LastNullBit(UInt_t startBit=999999999)
const;
133 UInt_t LastSetBit(UInt_t startBit=999999999)
const;
134 UInt_t GetNbits()
const {
return fNbits; }
135 UInt_t GetNbytes()
const {
return fNbytes; }
137 Bool_t operator==(
const TBits &other)
const;
138 Bool_t operator!=(
const TBits &other)
const {
return !(*
this==other); }
140 void Paint(Option_t *option=
"");
141 void Print(Option_t *option=
"")
const;
142 void Output(std::ostream &)
const;
148 inline Bool_t operator&(
const TBits::TReference& lhs,
const TBits::TReference& rhs)
150 return (Bool_t)lhs & rhs;
153 inline Bool_t operator|(
const TBits::TReference& lhs,
const TBits::TReference& rhs)
155 return (Bool_t)lhs | rhs;
158 inline Bool_t operator^(
const TBits::TReference& lhs,
const TBits::TReference& rhs)
160 return (Bool_t)lhs ^ rhs;
163 inline TBits operator&(
const TBits& lhs,
const TBits& rhs)
170 inline TBits operator|(
const TBits& lhs,
const TBits& rhs)
177 inline TBits operator^(
const TBits& lhs,
const TBits& rhs)
184 inline std::ostream &operator<<(std::ostream& os,
const TBits& rhs)
186 rhs.Output(os);
return os;
191 inline void TBits::Resize(UInt_t newbitnumber)
194 UInt_t new_size = (newbitnumber / 8) + 1;
195 if (new_size > fNbytes) {
197 UChar_t *old_location = fAllBits;
198 fAllBits =
new UChar_t[new_size];
199 memcpy(fAllBits, old_location, fNbytes);
200 memset(fAllBits + fNbytes, 0, new_size - fNbytes);
202 delete[] old_location;
206 inline void TBits::SetBitNumber(UInt_t bitnumber, Bool_t value)
210 if (bitnumber >= fNbits) {
212 fNbits = bitnumber+1;
214 UInt_t loc = bitnumber/8;
215 UChar_t bit = bitnumber%8;
217 fAllBits[loc] |= (1<<bit);
219 fAllBits[loc] &= (0xFF ^ (1<<bit));
222 inline Bool_t TBits::TestBitNumber(UInt_t bitnumber)
const
226 if (bitnumber >= fNbits)
return kFALSE;
227 UInt_t loc = bitnumber/8;
228 UChar_t value = fAllBits[loc];
229 UChar_t bit = bitnumber%8;
230 Bool_t result = (value & (1<<bit)) != 0;
235 inline void TBits::ResetBitNumber(UInt_t bitnumber)
237 SetBitNumber(bitnumber,kFALSE);
240 inline Bool_t TBits::operator[](UInt_t bitnumber)
const
242 return TestBitNumber(bitnumber);
245 inline TBits::TReference& TBits::TReference::operator=(Bool_t val)
249 fBits.SetBitNumber(fPos,val);
return *
this;
252 inline TBits::TReference& TBits::TReference::operator=(
const TReference& rhs)
256 fBits.SetBitNumber(fPos,rhs.fBits.TestBitNumber(rhs.fPos));
return *
this;
259 inline Bool_t TBits::TReference::operator~()
const
263 return !fBits.TestBitNumber(fPos);
266 inline TBits::TReference::operator Bool_t()
const
270 return fBits.TestBitNumber(fPos);