/*========================================================================== * * Copyright (C) 1995 - 2000 Microsoft Corporation. All Rights Reserved. * * File: AutoArray.inl * Content: CAutoArray methods * * History: * Date By Reason * ====== == ====== * 12-12-2001 simonpow Created ***************************************************************************/ template void CAutoArray::SetExistingElements(DWORD dwIndex, const T * pElemData, DWORD dwNumElem) { DNASSERT(dwIndex+dwNumElem<=m_dwSize); //have to handle the case where pElemData is actually a pointer //into this arrays data (don't want to overwrite original data //with copied data prematurely). //copy from top down if destination is in front of source T * pDest=m_pData+dwIndex; if (pDest>pElemData) { T * pDestScan=pDest+dwNumElem-1; pElemData+=(dwNumElem-1); while (pDestScan>=pDest) *pDestScan--=*pElemData--; } //otherwise it must be bottom up else { T * pDestScan=pDest; pDest+=dwNumElem; while (pDestScan=m_dwSize already! template BOOL CAutoArray::GrowToAtLeast(DWORD dwIndex) { //allocate new memory block DWORD dwNewSize=GetArraySize(dwIndex); T * pNewData=new T[dwNewSize]; if (!pNewData) return FALSE; //if we've got existing data copy it to new block if (m_pData) { for (DWORD dwLoop=0; dwLoop BOOL CAutoArray::SetElements(DWORD dwIndex, const T * pElemData, DWORD dwNumElem) { //calculate the top dwIndex+1 we need to touch DWORD dwCeilingIndex=dwIndex+dwNumElem; DWORD dwLoop; //Are we going to exceed current array size if (dwCeilingIndex<=m_dwSize) { //No=easy case, just set new elements for (dwLoop=dwIndex; dwLoop BOOL CAutoArray::MoveElements(DWORD dwIndex, DWORD dwNumElements, DWORD dwNewIndex, BOOL bCopySemantics) { DNASSERT(dwIndex+dwNumElements<=m_dwSize); DWORD dw; //Are we shifting element block down? if (dwNewIndex<=dwIndex) { //Yes=easy case. Just copy elements from bottom up for (dw=0; dw0; dw--) m_pData[dwNewIndex+dw]=m_pData[dwIndex+dw]; return TRUE; } //array does need to grow, so create larger array DWORD dwNewSize=GetArraySize(dw); T * pNewData=new T[dwNewSize]; if (!pNewData) return FALSE; if (m_pData) { //copy across block of elements below the //block we've got to move for (dw=0; dw