MCPcopy Create free account
hub / github.com/devosoft/avida / cBitArray

Class cBitArray

avida-core/source/tools/cBitArray.h:236–447  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

234};
235
236class cBitArray {
237private:
238 cRawBitArray bit_array;
239 int array_size;
240
241 // Setup a bit proxy so that we can use operator[] on bit arrays as a lvalue.
242 class cBitProxy {
243 private:
244 cBitArray & array;
245 int index;
246 public:
247 cBitProxy(cBitArray & _array, int _idx) : array(_array), index(_idx) {;}
248
249 inline cBitProxy & operator=(bool b); // lvalue handling...
250 inline operator bool() const; // rvalue handling...
251 };
252 friend class cBitProxy;
253public:
254 cBitArray() : array_size(0) { ; }
255 cBitArray(int in_size) : bit_array(in_size), array_size(in_size) { ; }
256 cBitArray(const cBitArray & in_array)
257 : bit_array(in_array.bit_array, in_array.array_size)
258 , array_size(in_array.array_size) { ; }
259 cBitArray(const cRawBitArray & in_array, int in_size)
260 : bit_array(in_array, in_size)
261 , array_size(in_size) { ; }
262
263 cBitArray & operator=(const cBitArray & in_array) {
264 bit_array.Copy(in_array.bit_array, in_array.array_size);
265 array_size = in_array.array_size;
266 return *this;
267 }
268
269 bool operator==(const cBitArray & in_array) const {
270 if (array_size != in_array.array_size) return false;
271 return bit_array.IsEqual(in_array.bit_array, array_size);
272 }
273
274 int GetSize() const { return array_size; }
275
276 void Set(int index, bool value) {
277 assert(index < array_size);
278 bit_array.SetBit(index, value);
279 }
280
281 bool Get(int index) const {
282 assert(index < array_size);
283 return bit_array.GetBit(index);
284 }
285
286 bool operator[](int index) const { return Get(index); }
287 cBitProxy operator[](int index) { return cBitProxy(*this, index); }
288
289 void Clear() { bit_array.Zero(array_size); }
290 void SetAll() { bit_array.Ones(array_size); }
291
292
293 void Print(ostream & out=cout) const { bit_array.Print(array_size, out); }

Callers

nothing calls this directly

Calls 10

INCREMENTMethod · 0.80
CopyMethod · 0.45
NOTMethod · 0.45
ANDMethod · 0.45
ORMethod · 0.45
NANDMethod · 0.45
NORMethod · 0.45
XORMethod · 0.45
EQUMethod · 0.45
SHIFTMethod · 0.45

Tested by

no test coverage detected