Buffer.h 865 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef CORE_BUFFER_H
  2. #define CORE_BUFFER_H
  3. #include "utils/Utility.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. check_return Error copyFrom(const Buffer& other);
  17. check_return Error add(const void* data, int size);
  18. template<typename T>
  19. check_return Error add(const T& t) {
  20. return add(&t, sizeof(T));
  21. }
  22. int getLength() const;
  23. operator const char*() const;
  24. const char* getData() const;
  25. void clear();
  26. private:
  27. void swap(Buffer& other);
  28. };
  29. }
  30. #endif