1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #ifndef CORE_BIT_ARRAY_H
- #define CORE_BIT_ARRAY_H
- #include "utils/ArrayString.h"
- namespace Core {
- class BitArray final {
- int length;
- int bits;
- int* data;
- public:
- BitArray();
- BitArray(const BitArray& other) = delete;
- BitArray(BitArray&& other);
- ~BitArray();
- BitArray& operator=(const BitArray& other) = delete;
- BitArray& operator=(BitArray&& other);
- // returns true on error and calls the error callback
- check_return bool copyFrom(const BitArray& other);
- BitArray& set(int index, int value);
- int get(int index) const;
- int getLength() const;
- int getBits() const;
- int getInternalByteSize() const;
- int select(int index) const;
- // returns true on error and calls the error callback
- check_return bool resize(int newLength, int newBits);
- void fill(int value);
- // returns true on error and calls the error callback
- template<int L>
- check_return bool toString(ArrayString<L>& s) const {
- if(s.append("[")) {
- return true;
- }
- for(int i = 0; i < length - 1; i++) {
- if(s.append(get(i)) || s.append(", ")) {
- return true;
- }
- }
- if(length > 0 && s.append(get(length - 1))) {
- return true;
- }
- return s.append("]");
- }
- private:
- void swap(BitArray& other);
- };
- }
- #endif
|