beveloper 353b9f6bce changed map and list templates to be more useable, however, they will
be rewritten soon. Changed debugging macros and use of them, too.
Also replaced the linked lists in the BufferManager (which were complicated,
but working ok) with template based ones.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2133 a95241bf-73f2-0310-859d-f6bbb57e9c96
2002-12-03 00:59:42 +00:00

79 lines
1.3 KiB
C++

#ifndef _MEDIA_T_LIST_H
#define _MEDIA_T_LIST_H
template<class value> class List
{
public:
List() : count(0) {}
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;
}
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;
}
bool GetPointerAt(int32 index, value **v)
{
if (index < 0 || index >= count)
return false;
*v = &list[index];
return true;
}
// 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;
}
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;
}
void MakeEmpty()
{
count = 0;
}
private:
enum { MAXENT = 64 };
value list[MAXENT];
int count;
};
#endif // _MEDIA_T_LIST_H