syntax help and some cmd-line parsing
[ecparse.git] / GrowingBuffer.h
1 /**
2  * © 2008 by David ‘Bombe’ Roden <bombe@pterodactylus.net>
3  */
4
5 #pragma once
6
7 /**
8  * A buffer that will grow to accomodate the data being put into it.
9  */
10 class GrowingBuffer {
11
12 public:
13
14         /**
15          * Empty constructor. Creates a buffer with a default size of 1024 bytes.
16          *
17          * @param initialSize The initial size of the buffer in bytes
18          */
19         GrowingBuffer(size_t initialSize = 1024);
20
21         /**
22          * Destructor. Frees all used resources.
23          */
24         ~GrowingBuffer();
25
26         size_t getPosition();
27         size_t getLimit();
28         size_t getSize();
29
30         /**
31          * Sets the position of the buffer. The next {@link read(void*, size_t)} or
32          * {@link write(const void*, size_t)} operation will be applied at the new
33          * position.
34          *
35          * @param position The position to seek to
36          */
37         void seek(size_t position);
38         void* read(void* buffer, size_t length);
39         void write(const void* buffer, size_t length);
40         void truncate();
41         void clear();
42         void resize(double factor = 1.0);
43
44 private:
45         void* data;
46         size_t size;
47         size_t limit;
48         size_t position;
49
50 };
51