TypedBuffer.h 536 B

1234567891011121314151617181920212223242526272829303132333435
  1. #ifndef TYPEBUFFER_H
  2. #define TYPEBUFFER_H
  3. #include <iostream>
  4. #include "data/List.h"
  5. template<typename T>
  6. class TypedBuffer {
  7. List<T> data;
  8. public:
  9. TypedBuffer& add(const T& t) {
  10. data.add(t);
  11. return *this;
  12. }
  13. int getLength() const {
  14. return data.getLength();
  15. }
  16. int getByteLength() const {
  17. return data.getLength() * static_cast<int>(sizeof(T));
  18. }
  19. operator const T*() const {
  20. return data.begin();
  21. }
  22. void clear() {
  23. data.clear();
  24. }
  25. };
  26. #endif