Buffer.h 523 B

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