Buffer.h 542 B

123456789101112131415161718192021222324252627282930313233
  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. void clear();
  22. private:
  23. void swap(Buffer& other);
  24. };
  25. #endif