Buffer.hpp 914 B

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