MCS
0.3.3-alpha7
|
High level buffer. More...
#include <mcs.hh>
Public Member Functions | |
Buffer (enum BufferFreeOnDestroy freeBuffer=AUTO_FREE) | |
Constructor, buffer allocation is handled internally. More... | |
Buffer (void *extbuf, unsigned int size, enum BufferFreeOnDestroy freeBuffer=DONT_FREE) | |
Constructor, buffer allocation handled by user. More... | |
Buffer (const Buffer &) | |
Declared to avoid using of default copy constructor. More... | |
void | free () |
Free allocated buffer. More... | |
operator void * () const | |
Buffer & | operator() (unsigned int start, unsigned int len) |
Select a "window" in the buffer. More... | |
Buffer & | operator() (unsigned int len) |
Select a "window" in the buffer. More... | |
Buffer & | operator<< (const void *extbuf) |
Copy data from an external buffer. More... | |
Buffer & | operator<< (istream &stream) |
Buffer & | operator= (const Buffer &) |
Declared to avoid using of default assignment operator. More... | |
Buffer & | operator>> (void *extbuf) |
Copy data into an external buffer. More... | |
Buffer & | operator>> (ostream &stream) |
char * | operator[] (unsigned int pos) |
Use the Buffer class an an array of pointers to char. More... | |
void | resize (unsigned int size) |
Check size, and eventually enlarge allocated memory. More... | |
void | set (void *extbuf, unsigned int size, enum BufferFreeOnDestroy freeBuffer) |
unsigned int | size () |
Return size of the buffer. More... | |
~Buffer () | |
Destructor, will free the buffer if "freeBuffer" is true. More... | |
Private Attributes | |
char * | buf |
Pointer to internal buffer. More... | |
unsigned int | bufsize |
Size of the buffer. More... | |
bool | extbuffer |
Tell if we are handling a user allocated buffer. More... | |
enum BufferFreeOnDestroy | freebuffer |
Tell if the buffer should be freed once the object is destroyed. More... | |
bool | select |
If a window has been selected. More... | |
unsigned int | wlen |
Length of the window. More... | |
unsigned int | wstart |
Beginning of the window (0-based). More... | |
High level buffer.
This class provide a buffer with several facilities:
This class can be used in two different way, each corresponding to a different constructor:
In the first case the allocation is performed automatically by the object, in the second case user must provide the pointer to the buffer and its size.
An example of its usage follows:
mcs::Buffer::Buffer | ( | enum BufferFreeOnDestroy | freeBuffer = AUTO_FREE | ) |
mcs::Buffer::Buffer | ( | void * | extbuf, |
unsigned int | size, | ||
enum BufferFreeOnDestroy | freeBuffer = DONT_FREE |
||
) |
mcs::Buffer::Buffer | ( | const Buffer & | ) |
Declared to avoid using of default copy constructor.
mcs::Buffer::~Buffer | ( | ) |
void mcs::Buffer::free | ( | ) |
Buffer & mcs::Buffer::operator() | ( | unsigned int | start, |
unsigned int | len | ||
) |
Select a "window" in the buffer.
A "window" is a part of the buffer which is to be read or written using a succesive call to the "<<" or ">>" operators.
This operator is used to define such a window.
start | Beginning of the window (0-based); |
len | Length of the window. |
Buffer & mcs::Buffer::operator() | ( | unsigned int | len | ) |
Select a "window" in the buffer.
This operator is similar to operator()(unsigned int, unsigned int) with the exception that in this case the start of the window is assumed to be at the end of the buffer when using the "<<" operator, at the beginning when using the ">>" operator.
Buffer & mcs::Buffer::operator<< | ( | const void * | extbuf | ) |
Declared to avoid using of default assignment operator.
Buffer & mcs::Buffer::operator>> | ( | void * | extbuf | ) |
char * mcs::Buffer::operator[] | ( | unsigned int | pos | ) |
void mcs::Buffer::resize | ( | unsigned int | size | ) |
Check size, and eventually enlarge allocated memory.
If the buffer is handled internally then this method will check if it has enough space to hold "size" bytes, if not it reallocates the buffer to a bigger size.
If the buffer used is handled by the user then it perform the same check but if the size is not enough an exception will be thrown.
You usually don't need to call this method since it is automatically called by operators.
Size | of the buffer. |
unsigned int mcs::Buffer::size | ( | ) |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
![]() |
MCS (My Customizable Server) ver. 0.3.3-alpha7
|