Buffer.h 1.0 KB

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