|
h destination in the array.
【返回值】:如果成功返回位置,否则返回-1
***************************************************************************************************/
cp_int32 DyArrayFind(DyArray* pArr, DataCmpFunc pCmp,void *pData)
{
cp_int32 i;
//if the input parameter is invalid, return.
if(!pArr)
{
return -1;
}
//visit each one to find the right one.
for(i=0; i
m_nSize;i++)
{
if(pCmp)
{
if(pCmp(pArr->m_ppData[i],pData) == CP_TRUE)
{
return i;
}
}else
{
//if NO compare funciton, just compare the address.
if(pArr->m_ppData[i] == pData)
{
return i;
}
}
}
return -1;
}
/**************************************************************************************************
【函数名】: DyArrayForEach
【描述】:遍历数组
【参数】:
pArr: the array's address.
pVisit: the callback function to visit the data.
【返回值】:如果成功返回true,否则false
***************************************************************************************************/
cp_bool DyArrayForEach(DyArray* pArr, DataVisitFunc pVisit)
{
cp_int32 i;
//if the input parameter is invalid, return.
if(!pArr || !pVisit)
{
return CP_FALSE;
}
//visit each one with the visit function.
for(i=0; i
m_nSize;i++) { pVisit(pArr->m_ppData[i]); } return CP_TRUE; } /************************************************************************************************** 【函数名】: DyArrayDestroy 【描述】:销毁整个数组 【参数】: pArr: the array's address. 【返回值】:NA ***************************************************************************************************/ void DyArrayDestroy(DyArray* pArr) { cp_int32 i; //if the input parameter is invalid, return. if(!pArr) { return; } //Using destroy function to destroy each element's memory. if(pArr->m_fDestroy) { for(i=0; i
m_nSize; i++) { pArr->m_fDestroy(pArr->m_ppData[i]); } } //free the array. FREEFUN(pArr->m_ppData); pArr->m_ppData = NULL; FREEFUN(pArr); pArr = NULL; } /************************************************************************************************** 【函数名】: DyArrayDestroyCustom 【描述】:使用用户函数,小围数组 【参数】: pArr: the array's address. pDataDestroy: user's destroy function. 【返回值】:NA ***************************************************************************************************/ void DyArrayDestroyCustom(DyArray* pArr,DataDestroyFunc pDataDestroy) { cp_int32 i; //if the input parameter is invalid, return. if(!pArr) { return; } //Using destroy function to destroy each element's memory. if(pDataDestroy) { for(i=0; i
m_nSize;i++) { pDataDestroy(pArr->m_ppData[i]); } } //free the array. FREEFUN(pArr->m_ppData); pArr->m_ppData = NULL; FREEFUN(pArr); } /************************************************************************************************** 【函数名】: DyArrayExpand 【描述】:扩展数组 【参数】: pArr: the array's address. nNeed: the needed new size. 【返回值】:如果成功返回ture否则返回false ***************************************************************************************************/ cp_bool DyArrayExpand(DyArray* pArr, cp_int32 nNeed) { cp_int32 allocSize = 0; void** data = NULL; //if the input parameter is invalid, return. if(!pArr) { return CP_FALSE; } //if need, expand to 1.5 times of the original size. if((pArr->m_nSize + nNeed) > pArr->m_nAllocSize) { allocSize = pArr->m_nAllocSize + (pArr->m_nAllocSize>>1); data = (void**)REALLOCFUN(pArr->m_ppData, sizeof(void*) * allocSi |