BitArray.h 905 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef BITARRAY_H
  2. #define BITARRAY_H
  3. #include "utils/StringBuffer.h"
  4. class BitArray final {
  5. int length;
  6. int bits;
  7. int* data;
  8. public:
  9. BitArray(int length, int bits);
  10. ~BitArray();
  11. BitArray(const BitArray& other);
  12. BitArray(BitArray&& other);
  13. BitArray& operator=(const BitArray& other);
  14. BitArray& operator=(BitArray&& other);
  15. BitArray& set(int index, int value);
  16. int get(int index) const;
  17. int getLength() const;
  18. int getBits() const;
  19. void resize(int newBits);
  20. template<int L>
  21. void toString(StringBuffer<L>& s) const {
  22. s.append("[");
  23. for(int i = 0; i < length - 1; i++) {
  24. s.append(get(i));
  25. s.append(", ");
  26. }
  27. if(length > 0) {
  28. s.append(get(length - 1));
  29. }
  30. s.append("]");
  31. }
  32. private:
  33. void copyData(const BitArray& other);
  34. void reset();
  35. };
  36. #endif