Appends chain with a single byte. Takes the single arg as the char to append, returns either E_OK if successful but E_MEMORY if not. The latter is a fatal condition. Returns: E_OK
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hzXbuf::AddByte | (const char,) |
Declared in file: hzXbuf.h
Defined in file : hzXbuf.cpp
Function Logic:
Function body:
hzEcode hzXbuf::AddByte (const char C)
{
// Appends chain with a single byte. Takes the single arg as the char to append, returns either E_OK if successful but E_MEMORY
// if not. The latter is a fatal condition.
//
// Arguments: 1) C Char to add
//
// Returns: E_OK
_hzfunc("hzXbuf::AddByte") ;
// Place char C on the end of the chain. Must detect physical end of
// the current block and add new block
_xblk* curBlk ; // Working block pointer
_xblk* newBlk ; // Working block pointer
if (!mx)
mx = new _xbuf() ;
if (!mx->m_Begin)
mx->m_Begin = mx->m_End = _xblk_alloc() ;
curBlk = (_xblk*) mx->m_End ;
if (!curBlk)
Fatal("Chain %p has no end block\n", this) ;
if (curBlk->xize == XBLKSIZE)
{
// Out of space - make new block
newBlk = _xblk_alloc() ;
if (!newBlk)
Fatal("No allocation (case 2)\n") ;
// newBlk->Prev((_xblk*) mx->m_End) ;
curBlk->Next(newBlk) ;
mx->m_End = newBlk ;
curBlk = newBlk ;
}
curBlk->m_Data[curBlk->xize] = C ;
curBlk->xize++ ;
mx->m_nSize++ ;
return E_OK ;
}