Public Member Functions

CdcBuffer Class Reference

CdcBuffer is a class that makes a buffer to store t_buff_unit (char) data. More...

#include <DcBuffer.h>

List of all members.

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 CdcBufferoperator= (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.
CdcBufferAppend (const t_buff_unit data) throw (CdcException)
 Append functions.
CdcBufferAppend (CdcString &data) throw (CdcException)
CdcBufferAppend (const CdcBuffer &data) throw (CdcException)
CdcBufferAppend (int data) throw (CdcException)
CdcBufferAppend (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.
CdcBufferAppend (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_unitGetPointer () 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.

Detailed Description

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.

Author:
Erez Bibi
Version:
1.0

Definition at line 70 of file DcBuffer.h.


Constructor & Destructor Documentation

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.

Parameters:
sizeThe initial size of the buffer.
growThe amount to increase the buffer space each time it needs to grow.
Exceptions:
(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.

Parameters:
buffThe 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.


Member Function Documentation

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.

Parameters:
dataThe data to append.
Returns:
(CdcBuffer&) A reference to the buffer (this).
Exceptions:
(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.

Parameters:
strPointer to the string to find (or CdcString).
startThe index in the buffer to start to look for str. 0 is the default.
stopThe index in the buffer to stop the searchat . 0 is the default and mean to search the entire buffer.
Returns:
(int) The first index of str inside the buffer. If str is not in the buffer the function returns -1.

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.

Returns:
(int) The number of elements 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!

Returns:
(t_buff_unit) A pointer to the inner buffer array.

Definition at line 212 of file DcBuffer.cpp.

int CdcBuffer::GetSize (  ) const

Get the maximum size of the buffer (without another allocation).

Returns:
(int) The size of the buffer (array).

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.

Parameters:
startThe place to start the scan (0 is the default)
stopThe place to stop the scan (0 is the default and will scan to the end of the buffer).
Returns:
True if the entire section is white spaces, otherwise False.

Definition at line 311 of file DcBuffer.cpp.

const CdcBuffer & CdcBuffer::operator= ( const CdcBuffer buff )

Assignment Operator - Shallow copy one buffer into the other.

Parameters:
buffThe buffer to copy.
Returns:
(CdcBuffer&) A reference to the buffer (this).

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.

Parameters:
indexThe index to read form.
Returns:
(t_buff_unit) Read only value of specific cell.
Exceptions:
(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.

Parameters:
stroldPointer to the string to find and replace.
strnewPointer to the new string to insert.
stroldlenThe length of the string to find and replace -1 is the default and mean string until NULL.
strnewlenThe length of the new string to insert. -1 is the default and mean string until NULL.
startThe place to start looking for strold. 0 is the default.
stopThe place t stop looking for strold. 0 is the default and mean 'stop at the end of buffer'.
Returns:
(int) The number of replacements that took place.

Definition at line 255 of file DcBuffer.cpp.


The documentation for this class was generated from the following files: