Buffer.hpp 893 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef CORE_BUFFER_HPP
  2. #define CORE_BUFFER_HPP
  3. #include "core/utils/Check.hpp"
  4. #include "core/utils/Error.hpp"
  5. namespace Core {
  6. class Buffer final {
  7. int length;
  8. int capacity;
  9. char* buffer;
  10. public:
  11. Buffer(int initialSize = 32);
  12. Buffer(const Buffer& other) = delete;
  13. Buffer(Buffer&& other);
  14. ~Buffer();
  15. Buffer& operator=(const Buffer& other) = delete;
  16. Buffer& operator=(Buffer&& other);
  17. check_return Error copyFrom(const Buffer& other);
  18. check_return Error add(const void* data, int size);
  19. template<typename T>
  20. check_return Error add(const T& t) {
  21. return add(&t, sizeof(T));
  22. }
  23. int getLength() const;
  24. operator const char*() const;
  25. const char* getData() const;
  26. void clear();
  27. void swap(Buffer& other);
  28. };
  29. }
  30. #endif