| // *********************************************************
// 動的配列の実装
// nIndex が 負の値の場合は 0 とみなします
// *********************************************************
int& Integer::operator[]( int nIndex )
{
if ( nIndex < 0 ) {
nIndex = 0;
}
if ( this->pArray == NULL ) {
this->pArray =
GlobalAlloc(
GMEM_FIXED | GMEM_ZEROINIT,
(nIndex+1)*sizeof( int ) + 16
);
this->nSize = nIndex + 1;
}
else {
if ( nIndex > this->nSize ) {
void *pCopy;
pCopy =
GlobalAlloc(
GMEM_FIXED | GMEM_ZEROINIT,
(nIndex+1)*sizeof( int ) + 16
);
memcpy( pCopy, this->pArray, this->nSize*sizeof( int ) );
GlobalFree( (HGLOBAL)this->pArray );
this->pArray = pCopy;
this->nSize = nIndex + 1;
}
}
return *(((int *)(this->pArray))+nIndex);
}
| |