1/*
2 * Copyright 2003 Marcus Overhagen
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _MEDIA_RT_LIST_H
6#define _MEDIA_RT_LIST_H
7
8
9/*!	A simple list template that uses realtime
10	memory and does no error checking. Since
11	it doesn't call constructors or destructors,
12	don't use it to store objects.
13
14	// TODO: no error checking? Great.
15*/
16
17
18#include <RealtimeAlloc.h>
19
20
21template<class value> class RtList {
22public:
23	RtList()
24		:
25		item_max(INIT_COUNT),
26	 	item_count(0),
27	 	items((value*)rtm_alloc(NULL, sizeof(value) * INIT_COUNT))
28	{
29	}
30
31	~RtList()
32	{
33		rtm_free(items);
34	}
35
36	value* Create()
37	{
38		if (item_count == item_max) {
39			item_max += INC_COUNT;
40			rtm_realloc((void**)&items, sizeof(value) * item_max);
41		}
42		return &items[item_count++];
43	}
44
45	value* ItemAt(int index)
46	{
47		return &items[index];
48	}
49
50	int CountItems()
51	{
52		return item_count;
53	}
54
55	void MakeEmpty()
56	{
57		item_count = 0;
58	}
59
60private:
61	RtList(const RtList<value>& other);
62	RtList<value> &operator=(const RtList<value>& other);
63
64private:
65	enum { INIT_COUNT = 8, INC_COUNT = 16 };
66
67	int		item_max;
68	int		item_count;
69	value*	items;
70};
71
72#endif // _MEDIA_RT_LIST_H
73