Append this chain with a sub-chain
| Return Type | Function name | Arguments |
|---|---|---|
| uint32_t | hzChain::AppendSub | (hzChain&,uint32_t,uint32_t,) |
Declared in file: hzChain.h
Defined in file : hzChain.cpp
Function Logic:
Function body:
uint32_t hzChain::AppendSub (hzChain& Z)uint32_t nStart, uint32_t nBytes,
{
// Append this chain with a sub-chain
//
// Arguments: 1) Z Sub-chain input
// 2) nStart Start position within sub-chain
// 3) nBytes No of bytes to write from sub-chain
//
// Returns: Number of bytes added
_hzfunc("hzChain::Append(hzChain,Start,noBytes)") ;
chIter zi ; // For iteration of operand chain
_zblk* curBlk ; // Working block pointer
_zblk* newBlk ; // Working block pointer
uint32_t nBytesWritten = 0; // Total bytes written
if (!Z.Size())
return 0;
// If nothing in this chain, create the first block
if (!mx)
{ mx = new _chain() ; mx->m_Test = mx ; }
if (!mx->m_Begin)
mx->m_Begin = mx->m_End = _zblk_alloc() ;
curBlk = (_zblk*) mx->m_End ;
if (!curBlk)
hzexit(E_MEMORY, "Chain %p has no end block\n", this) ;
for (zi = Z, zi += nStart ; !zi.eof() && nBytesWritten < nBytes ; zi++)
{
if (curBlk->m_nUsage == ZBLKSIZE)
{
// Out of space - make new block
newBlk = _zblk_alloc() ;
newBlk->Prev(curBlk) ;
curBlk->Next(newBlk) ;
mx->m_End = curBlk = newBlk ;
}
curBlk->m_Data[curBlk->m_nUsage] = *zi ;
curBlk->m_nUsage++ ;
mx->m_nSize++ ;
nBytesWritten++ ;
}
return nBytesWritten ;
}