CdcBuffer is a class that makes a buffer to store t_buff_unit (char) data. More...
#include <DcBuffer.h>
Public Member Functions | |
CdcBuffer () | |
Constructor that construct an empty buffer. | |
CdcBuffer (unsigned int size, int grow=DEFAULT_SIZE) throw (CdcException) | |
Constructor that construct a buffer with initial size, and a grow step. | |
CdcBuffer (const CdcBuffer &buff) | |
Copy constructor - Shallow copy one buffer into the other. | |
virtual | ~CdcBuffer () |
Destructor - Free the dynamic allocated memory. | |
const CdcBuffer & | operator= (const CdcBuffer &buff) |
Assignment Operator - Shallow copy one buffer into the other. | |
t_buff_unit | operator[] (int index) const throw (CdcException) |
Operator [] for reading the content of one cell in the buffer. | |
CdcBuffer & | Append (const t_buff_unit data) throw (CdcException) |
Append functions. | |
CdcBuffer & | Append (CdcString &data) throw (CdcException) |
CdcBuffer & | Append (const CdcBuffer &data) throw (CdcException) |
CdcBuffer & | Append (int data) throw (CdcException) |
CdcBuffer & | Append (const t_buff_unit *data, int length=-1) throw (CdcException) |
Here if 'length' > 0 it copies 'length' cells from the array, if 'length' = -1 it copies the array until the first 0. | |
CdcBuffer & | Append (const string &data) |
void | RemoveAll () |
Remove all data from the buffer. | |
int | GetSize () const |
Get the maximum size of the buffer (without another allocation). | |
int | GetDataSize () const |
Get the current number of cells in the buffer. | |
t_buff_unit * | GetPointer () const |
Get a pointer to the inner array of the buffer. | |
int | Find (const char *str, int start=0, int stop=0) const |
This function tries to find a C style string inside the buffer. | |
int | Find (CdcString &str, int start=0, int stop=0) const |
int | Find (char chr, int start=0, int stop=0) const |
This find function finds the first specific char in a buffer. | |
int | ReplaceAll (const char *strold, const char *strnew, int stroldlen=-1, int strnewlen=-1, int start=0, int stop=0) |
This function will replace all the occurrences of the C style string strold with the string strnew. | |
int | ReplaceAll (char old_chr, char new_chr) |
This is the ReplaceAll version for chars. | |
bool | IsWhiteSpaces (int start=0, int stop=0) |
This function returns True if all chars in sections are white-spaces. |
CdcBuffer is a class that makes a buffer to store t_buff_unit (char) data.
The user can append the data in the end of the buffer, and then get a read only pointer to the inner array.
This buffer is working with the principles of "Copy On Write" and "Reference Counting". The copy constructor and the assignment operator will copy just the value of the pointers (shallow copy). Copying of the entire array will occur just when one object is going to write into the array.
This is dynamic allocated t_buff_unit array. The array can grow as necessary, but it cannot get smaller.
It is very important that the user use the pointer to the buffer as a READ ONLY buffer.
There is also an option for direct accessing every cell by the read only '[]' operator.
This class is thread safe. You can work with one object from several different threads.
I added two functions that doesn't directly connected to a buffer. Find and ReplaceAll are in use just with HTML pages that will be stored in the buffer. They will allow the system to manipulate HTML pages before sending them to the client.
Definition at line 70 of file DcBuffer.h.
CdcBuffer::CdcBuffer | ( | ) |
Constructor that construct an empty buffer.
CdcBuffer.cpp: implementation of the CdcBuffer class.
for documentation see the header file.
Definition at line 27 of file DcBuffer.cpp.
CdcBuffer::CdcBuffer | ( | unsigned int | size, |
int | grow = DEFAULT_SIZE |
||
) | throw (CdcException) |
Constructor that construct a buffer with initial size, and a grow step.
size | The initial size of the buffer. |
grow | The amount to increase the buffer space each time it needs to grow. |
(CdcException) | Out of memory exception. |
Definition at line 33 of file DcBuffer.cpp.
CdcBuffer::CdcBuffer | ( | const CdcBuffer & | buff ) | [inline] |
Copy constructor - Shallow copy one buffer into the other.
buff | The buffer to copy. |
Definition at line 144 of file DcBuffer.h.
virtual CdcBuffer::~CdcBuffer | ( | ) | [inline, virtual] |
Destructor - Free the dynamic allocated memory.
Definition at line 150 of file DcBuffer.h.
CdcBuffer & CdcBuffer::Append | ( | const t_buff_unit | data ) | throw (CdcException) |
Append functions.
Append some data to the end of the buffer.
This is a set of overloaded functions.
data | The data to append. |
(CdcException) | Out of memory exception. |
Definition at line 157 of file DcBuffer.cpp.
CdcBuffer & CdcBuffer::Append | ( | CdcString & | data ) | throw (CdcException) |
Definition at line 164 of file DcBuffer.cpp.
CdcBuffer& CdcBuffer::Append | ( | const string & | data ) | [inline] |
Definition at line 188 of file DcBuffer.h.
CdcBuffer & CdcBuffer::Append | ( | const CdcBuffer & | data ) | throw (CdcException) |
Definition at line 173 of file DcBuffer.cpp.
CdcBuffer & CdcBuffer::Append | ( | int | data ) | throw (CdcException) |
Definition at line 181 of file DcBuffer.cpp.
CdcBuffer & CdcBuffer::Append | ( | const t_buff_unit * | data, |
int | length = -1 |
||
) | throw (CdcException) |
Here if 'length' > 0 it copies 'length' cells from the array, if 'length' = -1 it copies the array until the first 0.
Definition at line 189 of file DcBuffer.cpp.
int CdcBuffer::Find | ( | CdcString & | str, |
int | start = 0 , |
||
int | stop = 0 |
||
) | const [inline] |
Definition at line 235 of file DcBuffer.h.
int CdcBuffer::Find | ( | const char * | str, |
int | start = 0 , |
||
int | stop = 0 |
||
) | const |
This function tries to find a C style string inside the buffer.
This is a Read Only operation. It does not lock the buffer.
str | Pointer to the string to find (or CdcString). |
start | The index in the buffer to start to look for str. 0 is the default. |
stop | The index in the buffer to stop the searchat . 0 is the default and mean to search the entire buffer. |
Definition at line 218 of file DcBuffer.cpp.
int CdcBuffer::Find | ( | char | chr, |
int | start = 0 , |
||
int | stop = 0 |
||
) | const |
This find function finds the first specific char in a buffer.
All parameters and return value are the same as Find for strings.
Definition at line 239 of file DcBuffer.cpp.
int CdcBuffer::GetDataSize | ( | ) | const |
Get the current number of cells in the buffer.
Definition at line 207 of file DcBuffer.cpp.
t_buff_unit * CdcBuffer::GetPointer | ( | ) | const |
Get a pointer to the inner array of the buffer.
Use this pointer as read only pointer!
Definition at line 212 of file DcBuffer.cpp.
int CdcBuffer::GetSize | ( | ) | const |
Get the maximum size of the buffer (without another allocation).
Definition at line 202 of file DcBuffer.cpp.
bool CdcBuffer::IsWhiteSpaces | ( | int | start = 0 , |
int | stop = 0 |
||
) |
This function returns True if all chars in sections are white-spaces.
start | The place to start the scan (0 is the default) |
stop | The place to stop the scan (0 is the default and will scan to the end of the buffer). |
Definition at line 311 of file DcBuffer.cpp.
Assignment Operator - Shallow copy one buffer into the other.
buff | The buffer to copy. |
Definition at line 136 of file DcBuffer.cpp.
t_buff_unit CdcBuffer::operator[] | ( | int | index ) | const throw (CdcException) |
Operator [] for reading the content of one cell in the buffer.
index | The index to read form. |
(CdcException) | Index out of bounds. |
Definition at line 148 of file DcBuffer.cpp.
void CdcBuffer::RemoveAll | ( | ) | [inline] |
Remove all data from the buffer.
Does not change the length of the buffer.
Definition at line 195 of file DcBuffer.h.
int CdcBuffer::ReplaceAll | ( | char | old_chr, |
char | new_chr | ||
) |
This is the ReplaceAll version for chars.
Much more simple... The returned value is the same as in ReplaceAll for strings.
Definition at line 295 of file DcBuffer.cpp.
int CdcBuffer::ReplaceAll | ( | const char * | strold, |
const char * | strnew, | ||
int | stroldlen = -1 , |
||
int | strnewlen = -1 , |
||
int | start = 0 , |
||
int | stop = 0 |
||
) |
This function will replace all the occurrences of the C style string strold with the string strnew.
This function writes into the buffer.
strold | Pointer to the string to find and replace. |
strnew | Pointer to the new string to insert. |
stroldlen | The length of the string to find and replace -1 is the default and mean string until NULL. |
strnewlen | The length of the new string to insert. -1 is the default and mean string until NULL. |
start | The place to start looking for strold. 0 is the default. |
stop | The place t stop looking for strold. 0 is the default and mean 'stop at the end of buffer'. |
Definition at line 255 of file DcBuffer.cpp.