TList* list_create()
{
TList* LList = (TList*)sys_malloc(sizeof(TList));
LList.count = 0;
LList.items = NULL;
return(LList);
}
void list_free(TList* AList)
{
if (AList)
{
list_clear(AList);
sys_free(AList);
}
}
void list_add(TList* AList, void* AItem)
{
AList.items = sys_realloc(AList.items, sizeof(int), AList.count, AList.count + 1);
AList.count += 1;
(AList.items)[AList.count - 1] = AItem;
}
void list_remove(TList* AList, int AIndex)
{
int i;
if(clamp(AIndex, 0, AList.count-1) == AIndex)
{
for (i = AIndex; i < AList.count-1; i++)
{
(AList.items)[i] = (AList.items)[i+1];
}
AList.items = sys_realloc(AList.items, sizeof(int), AList.count, AList.count-1);
AList.count -= 1;
}
}
int list_index_of(TList* AList, void* AItem)
{
int i;
int LResult = -1;
for(i = 0; i < AList.count; i++)
{
if (AItem == (AList.items)[i])
{
LResult = i;
break;
}
}
return(LResult);
}
void list_delete(TList* AList, void* AItem)
{
int LIndex = list_index_of(AList,AItem);
if (LIndex >= 0)
{
list_remove(AList,LIndex);
}
}
void list_clear(TList* AList)
{
if(AList.items)
{
sys_free(AList.items);
AList.items = NULL;
AList.count = 0;
}
}