Buffer.h 559 B

123456789101112131415161718192021222324252627282930313233
  1. #ifndef BUFFER_H
  2. #define BUFFER_H
  3. #include "memory/StackAllocator.h"
  4. class Buffer {
  5. int length;
  6. int capacity;
  7. char* buffer;
  8. public:
  9. Buffer(int initialSize);
  10. Buffer(const Buffer& other);
  11. Buffer(Buffer&& other);
  12. ~Buffer();
  13. Buffer& operator=(Buffer other);
  14. Buffer& add(const void* data, int size);
  15. template<typename T>
  16. Buffer& add(const T& t) {
  17. add(&t, sizeof(T));
  18. return *this;
  19. }
  20. int getLength() const;
  21. operator const char*() const;
  22. private:
  23. void swap(Buffer& other);
  24. };
  25. #endif