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