X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=GrowingBuffer.h;fp=GrowingBuffer.h;h=894267df659b1c8902c1c48e7852ed6331b464e6;hb=b24b03abb90553821d627e87dac5ec07d81fd09c;hp=0000000000000000000000000000000000000000;hpb=fd659a52cdf9259e8a04b0ecb5e3b5fb0d9f06b4;p=ecparse.git diff --git a/GrowingBuffer.h b/GrowingBuffer.h new file mode 100644 index 0000000..894267d --- /dev/null +++ b/GrowingBuffer.h @@ -0,0 +1,51 @@ +/** + * © 2008 by David ‘Bombe’ Roden + */ + +#pragma once + +/** + * A buffer that will grow to accomodate the data being put into it. + */ +class GrowingBuffer { + +public: + + /** + * Empty constructor. Creates a buffer with a default size of 1024 bytes. + * + * @param initialSize The initial size of the buffer in bytes + */ + GrowingBuffer(size_t initialSize = 1024); + + /** + * Destructor. Frees all used resources. + */ + ~GrowingBuffer(); + + size_t getPosition(); + size_t getLimit(); + size_t getSize(); + + /** + * Sets the position of the buffer. The next {@link read(void*, size_t)} or + * {@link write(const void*, size_t)} operation will be applied at the new + * position. + * + * @param position The position to seek to + */ + void seek(size_t position); + void* read(void* buffer, size_t length); + void write(const void* buffer, size_t length); + void truncate(); + void clear(); + void resize(double factor = 1.0); + +private: + void* data; + size_t size; + size_t limit; + size_t position; + +}; +