TypedBuffer.h 599 B

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