libUTL++
BitArray.h
1 #pragma once
2 
4 
5 #include <libutl/Vector.h>
6 
8 
9 UTL_NS_BEGIN;
10 
12 
13 class BitArrayElem;
14 
16 
34 
36 class BitArray : public Object
37 {
39 
40 public:
46  BitArray(uint64_t size, uint_t numBits = 1)
47  {
48  init();
49  initialize(size, numBits);
50  }
51 
52  virtual size_t innerAllocatedSize() const;
53 
54  virtual int compare(const Object& rhs) const;
55 
56  virtual void copy(const Object& rhs);
57 
58  virtual void steal(Object& rhs);
59 
60  virtual void dump(Stream& os, uint_t level = uint_t_max) const;
61 
62  virtual void serialize(Stream& stream, uint_t io, uint_t mode = ser_default);
63 
64  void clear();
65 
67  void initialize(uint64_t size, uint_t numBits = 1);
68 
70  uint64_t
71  size() const
72  {
73  return _size;
74  }
75 
77  void
78  grow(uint64_t size)
79  {
80  if (size > this->size()) setSize(size);
81  }
82 
84  void setSize(uint64_t size);
85 
87  uint64_t get(uint64_t pos) const;
88 
90  void set(uint64_t idx, uint64_t val);
91 
93  void setAll(uint64_t val);
94 
97  {
98  return get((uint64_t)idx);
99  }
100 
102  uint64_t operator[](int idx) const
103  {
104  return get((uint64_t)idx);
105  }
106 
109  {
110  return get((uint64_t)idx);
111  }
112 
115  {
116  return get((uint64_t)idx);
117  }
118 
120  BitArrayElem operator[](uint_t idx);
121 
123  BitArrayElem operator[](int idx);
124 
126  BitArrayElem operator[](uint64_t idx);
127 
129  BitArrayElem operator[](int64_t idx);
130 
131 private:
132  void init();
133  void deInit();
134 
135 private:
136  uint_t _numBits;
137  uint64_t _size;
138  size_t _arraySize;
139  uint64_t* _array;
140 };
141 
143 
144 UTL_NS_END;
145 
147 
148 #include <libutl/BitArrayElem.h>
uint64_t size() const
Get the array size.
Definition: BitArray.h:71
void grow(uint64_t size)
Grow to the given size.
Definition: BitArray.h:78
Reference to a value stored in a BitArray.
Definition: BitArrayElem.h:27
void serialize(bool &b, Stream &stream, uint_t io, uint_t mode=ser_default)
Serialize a boolean.
BitArray(uint64_t size, uint_t numBits=1)
Constructor.
Definition: BitArray.h:46
void deInit()
De-initialize UTL++.
default representation (via getSerializeMode())
Definition: util.h:75
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
uint64_t operator[](uint64_t idx) const
Return the value at the given index.
Definition: BitArray.h:108
long int64_t
Signed 64-bit integer.
Definition: types.h:164
void copy(T *dest, const T *src, size_t len)
Copy one array of objects to another.
Definition: util_inl.h:690
uint64_t operator[](int idx) const
Return the value at the given index.
Definition: BitArray.h:102
unsigned long uint64_t
Unsigned 64-bit integer.
Definition: types.h:154
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
const uint_t uint_t_max
Maximum uint_t value.
Stream I/O abstraction.
Definition: Stream.h:68
uint64_t operator[](uint_t idx) const
Return the value at the given index.
Definition: BitArray.h:96
Root of UTL++ class hierarchy.
Definition: Object.h:52
int compare(bool lhs, bool rhs)
Compare two boolean values.
uint64_t operator[](int64_t idx) const
Return the value at the given index.
Definition: BitArray.h:114
void dump(const FwdIt &begin, const FwdIt &end, Stream &os, uint_t level=uint_t_max, bool key=false, bool printClassName=false, uint_t indent=0, const char *separator=nullptr)
Dump objects to the given stream (with Object::dump()).
void init()
Initialize UTL++.
Array of n-bit values.
Definition: BitArray.h:36