#ifndef BUFFER_H #define BUFFER_H #include #include "memory/StackAllocator.h" class Buffer { StackAllocator::Array data; int length = 0; public: Buffer(int n); template Buffer& add(const T& t) { int bytes = data.getLength() - length; if(bytes > static_cast (sizeof (T))) { bytes = sizeof (T); } else if(data.grow(data.getLength()) > 0) { return add(t); } memcpy(data + length, &t, bytes); length += bytes; return *this; } int getLength() const; operator const char*() const; }; #endif