Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

83 lines
1.9 KiB

//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright © 2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 02/08/2001
// PROJECT:
// SUBSYSTEM:
// FILE: GenericList.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of GenericList.cpp
//----------------------------------------------------------------------------
#include "stdafx.h"
#include "GenericList.h"
template<class TYPE, TYPE def>
CGenericList<TYPE,def>::CGenericList()
{
m_nData = 0;
m_pData = NULL;
}
template<class TYPE, TYPE def>
CGenericList<TYPE,def>::~CGenericList()
{
RemoveAll();
}
template<class TYPE, TYPE def>
BOOL CGenericList<TYPE,def>::Add( TYPE pData, INT nIndex )
{
// allocate space for new element
m_pData = (TYPE*) realloc( m_pData, sizeof(TYPE) * ( m_nData + 1 ) );
if( !m_pData )
{
m_nData = 0;
return FALSE;
}
// add to end
if( nIndex < 0 || nIndex >= m_nData )
nIndex = m_nData;
// shift elements
::MoveMemory( &m_pData[ nIndex + 1 ], &m_pData[ nIndex ], sizeof(TYPE) * ( m_nData - nIndex ) );
// initialize new element
m_pData[ nIndex ] = pData;
return TRUE;
}
template<class TYPE, TYPE def>
BOOL CGenericList<TYPE,def>::Remove( INT nIndex )
{
// validate position
if( nIndex < 0 || nIndex >= m_nData )
return FALSE;
// decrease number of elements
m_nData --;
// shift elements
::MoveMemory( &m_pData[ nIndex ], &m_pData[ nIndex + 1 ], sizeof(TYPE) * ( m_nData - nIndex ) );
// deallocate space
m_pData = (TYPE*) realloc( m_pData, sizeof(TYPE) * m_nData );
if( !m_pData )
{
m_nData = 0;
return FALSE;
}
return TRUE;
}
template<class TYPE, TYPE def>
void CGenericList<TYPE,def>::RemoveAll()
{
while( GetCount() )
Remove( 0 );
}