ONPOSIX
2.0
|
Very simple buffer with control on overflow. More...
#include <Buffer.hpp>
Public Member Functions | |
Buffer (unsigned long int size) | |
Constructor. It checks size and allocates memory. | |
virtual | ~Buffer () |
char & | operator[] (unsigned long int p) |
Method to access a specific byte of the buffer. | |
unsigned long int | fill (const char *src, unsigned long int size) |
Method to fill the buffer. | |
unsigned long int | fill (Buffer *b, unsigned long int size) |
Method to fill the buffer with the content of another buffer. | |
bool | compare (Buffer *b, unsigned long int size) |
Method to compare two buffers' content. | |
bool | compare (const char *s, unsigned long int size) |
Method to compare the content of the buffer against a buffer in memory. | |
char * | getBuffer () |
Method to get a pointer to the buffer. | |
unsigned long int | getSize () const |
Method to get the size of the buffer. | |
unsigned long int | fill (char *src, unsigned long int size) |
Private Member Functions | |
Buffer (const Buffer &) |
Private Attributes | |
unsigned long int | size_ |
Current size of the buffer. | |
char * | data_ |
Pointer to the allocated memory. |
Very simple buffer with control on overflow.
This is a simple buffer, internally allocated as a char buffer with new and delete. With respect to hand-made buffers, it adds the check on boundaries.
Definition at line 35 of file Buffer.hpp.
|
explicit |
Constructor. It checks size and allocates memory.
size | size of the buffer |
invalid_argument | in case of wrong size |
Definition at line 34 of file Buffer.cpp.
|
virtual |
Destructor. It deallocates memory.
Definition at line 46 of file Buffer.cpp.
bool compare | ( | Buffer * | b, |
unsigned long int | size | ||
) |
Method to compare two buffers' content.
It compares the content of this buffer with the content of another buffer
b | the buffer against whose content it must be compared |
size | size of bytes to be compared |
out_of_range | in case the given size is greater than the size of one of the two buffers |
Definition at line 123 of file Buffer.cpp.
bool compare | ( | const char * | s, |
unsigned long int | size | ||
) |
Method to compare the content of the buffer against a buffer in memory.
It compares the content of this buffer with the content at a specified memory address
s | pointer to the memory address against whose content it must be compared |
size | size of bytes to be compared |
out_of_range | in case the given size is greater than the buffer buffers |
Definition at line 142 of file Buffer.cpp.
unsigned long int fill | ( | const char * | src, |
unsigned long int | size | ||
) |
Method to fill the buffer.
It takes the content from a specified address.
src | source of the content used to fill the buffer |
size | number of bytes to be copied |
out_of_range | in case the size is greater than the size of the buffer |
invalid_argument | in case the source points to NULL |
Definition at line 79 of file Buffer.cpp.
unsigned long int fill | ( | Buffer * | b, |
unsigned long int | size | ||
) |
Method to fill the buffer with the content of another buffer.
The number of bytes copied is the minimum between the size of the buffer and the size provided as argument.
b | pointer to the buffer whose data must be used to fill this buffer |
size | size of bytes to be copied |
Definition at line 101 of file Buffer.cpp.
|
inline |
|
inline |
Method to get a pointer to the buffer.
Definition at line 63 of file Buffer.hpp.
|
inline |
Method to get the size of the buffer.
Definition at line 72 of file Buffer.hpp.
char & operator[] | ( | unsigned long int | p | ) |
Method to access a specific byte of the buffer.
It checks the argument and throws an exception in case of out of range.
p | position in the buffer |
out_of_range | in case the position is out of boundary |
Definition at line 60 of file Buffer.cpp.
|
private |
Pointer to the allocated memory.
Definition at line 44 of file Buffer.hpp.
|
private |
Current size of the buffer.
Definition at line 39 of file Buffer.hpp.