123456789101112131415161718192021222324252627282930313233 |
- #ifndef BUFFER_H
- #define BUFFER_H
- #include <cstring>
- #include "memory/StackAllocator.h"
- class Buffer {
- StackAllocator::Array<char> data;
- int length = 0;
- public:
- Buffer(int n);
- template<typename T>
- Buffer& add(const T& t) {
- int bytes = data.getLength() - length;
- if(bytes > static_cast<int> (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
|