BitArray.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef CORE_BIT_ARRAY_H
  2. #define CORE_BIT_ARRAY_H
  3. #include "utils/ArrayString.h"
  4. namespace Core {
  5. class BitArray final {
  6. int length;
  7. int bits;
  8. int* data;
  9. public:
  10. BitArray();
  11. BitArray(const BitArray& other) = delete;
  12. BitArray(BitArray&& other);
  13. ~BitArray();
  14. BitArray& operator=(const BitArray& other) = delete;
  15. BitArray& operator=(BitArray&& other);
  16. // returns true on error
  17. check_return bool copyFrom(const BitArray& other);
  18. BitArray& set(int index, int value);
  19. int get(int index) const;
  20. int getLength() const;
  21. int getBits() const;
  22. int getInternalByteSize() const;
  23. int select(int index) const;
  24. // returns true on error
  25. check_return bool resize(int newLength, int newBits);
  26. void fill(int value);
  27. // returns true on error
  28. template<int L>
  29. check_return bool toString(ArrayString<L>& s) const {
  30. if(s.append("[")) {
  31. return true;
  32. }
  33. for(int i = 0; i < length - 1; i++) {
  34. if(s.append(get(i)) || s.append(", ")) {
  35. return true;
  36. }
  37. }
  38. if(length > 0 && s.append(get(length - 1))) {
  39. return true;
  40. }
  41. return s.append("]");
  42. }
  43. private:
  44. void swap(BitArray& other);
  45. };
  46. }
  47. #endif