Buffer.hpp 906 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. private:
  28. void swap(Buffer& other);
  29. };
  30. }
  31. #endif