BitArray.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef CORE_BIT_ARRAY_HPP
  2. #define CORE_BIT_ARRAY_HPP
  3. #include "core/utils/ArrayString.hpp"
  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. check_return Error copyFrom(const BitArray& other);
  17. BitArray& set(int index, int value);
  18. int get(int index) const;
  19. int getLength() const;
  20. int getBits() const;
  21. int getInternalByteSize() const;
  22. int select(int index) const;
  23. check_return Error resize(int newLength, int newBits);
  24. void fill(int value);
  25. template<typename String>
  26. check_return Error toString(String& s) const {
  27. CORE_RETURN_ERROR(s.append("["));
  28. for(int i = 0; i < length - 1; i++) {
  29. CORE_RETURN_ERROR(s.append(get(i)));
  30. CORE_RETURN_ERROR(s.append(", "));
  31. }
  32. if(length > 0) {
  33. CORE_RETURN_ERROR(s.append(get(length - 1)));
  34. }
  35. return s.append("]");
  36. }
  37. void swap(BitArray& other);
  38. };
  39. }
  40. #endif