Public Member Functions | |
GBuffer (unsigned int size, unsigned int growDelta=STANDARD_GROW_DELTA) | |
Creates a new GBuffer with a given initial site. | |
~GBuffer (void) | |
Destroys the buffer and the data in it. | |
void | add (unsigned char *data, unsigned int size) |
Adds data to the buffer at the end of the buffer. | |
unsigned char * | addPtr (unsigned int size) |
Returns a pointer to the end of the buffer which can be used in library routines that require a buffer as a target (read(...) ) for example, ensuring that enough space is left in the buffer. | |
void | added (unsigned int size) |
Moves the end of the buffer by size bytes. | |
unsigned int | get (unsigned char *buffer, unsigned int size) |
Stores up to size bytes of data starting at the current position in a target buffer buffer . | |
const unsigned char * | getPtr (void) const |
Returns a pointer to the current position. | |
unsigned char * | readLine (void) |
Returns a line of text, starting at the current position, ending at the next newline character, in a string. | |
void | shrink (void) |
Reallocates the memory block occupied by the buffer such that the maximal size is equal to the current size, for more efficient memory usage. | |
unsigned int | getSize (void) |
Returns the size of the data currently stored in the buffer. | |
Private Member Functions | |
void | ensureSize (unsigned int size) |
Makes sure that data of the size given can be inserted into the buffer without a buffer overflow. | |
Private Attributes | |
unsigned char * | data |
The data. | |
unsigned int | pos |
The current read position. | |
unsigned int | size |
The current size of the buffer. | |
unsigned int | maxSize |
The maximal size of the buffer. | |
unsigned int | growDelta |
The amount of bytes the buffer grows when necessary. |
The buffer provides a readLine
method to simplify the retrieval of text data stored in the buffer.
|
Creates a new GBuffer with a given initial site.
|
|
Destroys the buffer and the data in it.
|
|
Adds data to the buffer at the end of the buffer. Necessary space is allocated automatically.
|
|
Moves the end of the buffer by
Must and must only be used after data was added to the buffer using an external function like the C library's
|
|
Returns a pointer to the end of the buffer which can be used in library routines that require a buffer as a target (
Handle with care! It is up to the caller to make sure that no more data than
After adding data to the buffer with an external function,
|
|
Makes sure that data of the size given can be inserted into the buffer without a buffer overflow. There are two strategies to achieve this: If the distance of the current position (the read position) is greater than the new size needed, the contents in the buffer up to the current position are deleted and all subsequent data is moved to the beginning of the buffer. Otherwise, a larger memory block is allocated.
|
|
Stores up to The current position is increased by the amount of data read. Note that the data remains unchanged in the buffer.
|
|
Returns a pointer to the current position.
|
|
Returns the size of the data currently stored in the buffer.
|
|
Returns a line of text, starting at the current position, ending at the next newline character, in a string.
If no newline character can be found up to the end of the buffer,
|
|
Reallocates the memory block occupied by the buffer such that the maximal size is equal to the current size, for more efficient memory usage.
|
|
The data.
|
|
The amount of bytes the buffer grows when necessary.
|
|
The maximal size of the buffer. The maximal size is always kept greater or equal than the current size. |
|
The current read position.
|
|
The current size of the buffer.
|