2002-08-13 00:10:24 +04:00
|
|
|
#ifndef _MEDIA_T_LIST_H
|
|
|
|
#define _MEDIA_T_LIST_H
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
template<class value> class List
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
List() : count(0) {}
|
2002-12-03 03:59:42 +03:00
|
|
|
|
|
|
|
List(const List<value> &other)
|
|
|
|
{
|
|
|
|
printf("template<class value> class List copy constructor\n");
|
|
|
|
count = other.count;
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
list[i] = other.list[i];
|
|
|
|
hmpt;
|
|
|
|
}
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
void Insert(const value &v)
|
|
|
|
{
|
|
|
|
value temp;
|
|
|
|
if (count == MAXENT) debugger("template List out of memory");
|
|
|
|
list[count] = v;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// you can't Remove() while iterating through the list using GetAt()
|
|
|
|
bool GetAt(int32 index, value *v)
|
|
|
|
{
|
|
|
|
if (index < 0 || index >= count)
|
|
|
|
return false;
|
|
|
|
*v = list[index];
|
|
|
|
return true;
|
|
|
|
}
|
2002-10-09 03:59:43 +04:00
|
|
|
|
|
|
|
bool GetPointerAt(int32 index, value **v)
|
|
|
|
{
|
|
|
|
if (index < 0 || index >= count)
|
|
|
|
return false;
|
|
|
|
*v = &list[index];
|
|
|
|
return true;
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
// you can't Remove() while iterating through the map using GetAt()
|
|
|
|
bool Remove(int32 index)
|
|
|
|
{
|
|
|
|
if (index < 0 || index >= count)
|
|
|
|
return false;
|
|
|
|
count--;
|
|
|
|
if (count > 0)
|
|
|
|
list[index] = list[count];
|
|
|
|
return true;
|
|
|
|
}
|
2002-10-09 03:59:43 +04:00
|
|
|
|
2002-12-03 03:59:42 +03:00
|
|
|
int Find(const value &v)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
if (list[i] == v)
|
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsEmpty()
|
|
|
|
{
|
|
|
|
return count == 0;
|
|
|
|
}
|
|
|
|
|
2002-10-09 03:59:43 +04:00
|
|
|
void MakeEmpty()
|
|
|
|
{
|
|
|
|
count = 0;
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
enum { MAXENT = 64 };
|
|
|
|
value list[MAXENT];
|
|
|
|
int count;
|
|
|
|
};
|
|
|
|
|
2002-08-13 00:10:24 +04:00
|
|
|
#endif // _MEDIA_T_LIST_H
|