CharBuffer Class Reference

## Public Member Functions

| CharBuffer (int32_t initialSize)
| CharBuffer (const CharBuffer &buffer)
CharBuffer & | operator= (const CharBuffer &buffer)
CharBuffer & | operator= (const std::string &stringBuffer)
bool | copy (const CharBuffer &buffer)
void | reset ()
int | readFromFile (IFILE filePtr, int32_t length)
const char * | c_str () const
int32_t | length () const

## Detailed Description

Definition at line 24 of file CharBuffer.h.

## Constructor & Destructor Documentation

## CharBuffer() [1/3]

CharBuffer::CharBuffer | ( |  | ) |

Definition at line 21 of file CharBuffer.cpp.

: myBuffer(NULL)
{
myBuffer = (char *) malloc(DEFAULT_BUFFER_SIZE);
myBufferAllocatedLen = DEFAULT_BUFFER_SIZE;
reset();
}

## CharBuffer() [2/3]

CharBuffer::CharBuffer | ( | int32_t | initialSize | ) |

Definition at line 30 of file CharBuffer.cpp.

: myBuffer(NULL)
{
myBuffer = (char *) malloc(initialSize);
myBufferAllocatedLen = DEFAULT_BUFFER_SIZE;
reset();
}

## ~CharBuffer()

CharBuffer::~CharBuffer | ( |  | ) |

Definition at line 40 of file CharBuffer.cpp.

{
reset();
if(myBuffer != NULL)
{
free(myBuffer);
myBuffer = NULL;
}
}

## CharBuffer() [3/3]

CharBuffer::CharBuffer | ( | const CharBuffer & | buffer | ) |

Definition at line 52 of file CharBuffer.cpp.

: myBuffer(NULL)
{
myBuffer =
(char *) malloc(DEFAULT_BUFFER_SIZE);
myBufferAllocatedLen = DEFAULT_BUFFER_SIZE;
reset();
copy(buffer);
}

## Member Function Documentation

## c_str()

const char * CharBuffer::c_str | ( |  | ) | const

inline

Definition at line 49 of file CharBuffer.h.

{
return(myBuffer);
}

## copy()

bool CharBuffer::copy | ( | const CharBuffer & | buffer | ) |

Definition at line 87 of file CharBuffer.cpp.

{
// Check to see if the passed in value is the same as this.
if(this == &buffer)
{
return(true);
}
// Copy the buffer.
// First check lengh
prepareNewLength(buffer.myBufferLen);
memcpy(myBuffer, buffer.myBuffer, buffer.myBufferLen);
myBufferLen = buffer.myBufferLen;
return(true);
}

## length()

int32_t CharBuffer::length | ( |  | ) | const

inline

Definition at line 54 of file CharBuffer.h.

{
return(myBufferLen);
}

## operator=() [1/2]

CharBuffer & CharBuffer::operator= | ( | const CharBuffer & | buffer | ) |

Definition at line 66 of file CharBuffer.cpp.

{
copy(buffer);
return(*this);
}

## operator=() [2/2]

CharBuffer & CharBuffer::operator= | ( | const std::string & | stringBuffer | ) |

Definition at line 74 of file CharBuffer.cpp.

{
// First check lengh
if(prepareNewLength(stringBuffer.length()))
{
memcpy(myBuffer, stringBuffer.c_str(), stringBuffer.length());
}
// TODO: on failure of prepareNewLength, should it throw an exception?
return(*this);
}

## readFromFile()

int CharBuffer::readFromFile | ( | IFILE | filePtr,
|  | int32_t | length
| ) |  |

Definition at line 119 of file CharBuffer.cpp.

{
if(filePtr == NULL)
{
return(0);
}
if(prepareNewLength(length))
{
return(ifread(filePtr, myBuffer, length));
}
// failed to setup the buffer, return false.
return(false);
}
ifread
unsigned int ifread(IFILE file, void *buffer, unsigned int size)
Read up to size bytes from the file into the buffer.
Definition: InputFile.h:600

## reset()

void CharBuffer::reset | ( |  | ) |

Definition at line 107 of file CharBuffer.cpp.

{
myBufferLen = 0;
if(myBuffer != NULL)
{
myBuffer[0] = 0;
}
}

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

- general/CharBuffer.h
- general/CharBuffer.cpp