1/*
2 * Copyright 2006, Haiku.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		IngoWeinhold <bonefish@cs.tu-berlin.de>
7 *		Stephan A��mus <superstippi@gmx.de>
8 */
9
10#ifndef LIST_H
11#define LIST_H
12
13#include <List.h>
14
15template<class T, bool delete_on_destruction = true>
16class List : protected BList {
17 public:
18	List(int32 count = 10)
19		: BList(count) {}
20
21	~List()
22		{ MakeEmpty(); }
23
24	// adding items
25	inline void AddItem(T value)
26		{ BList::AddItem((void*)value); }
27
28	inline void AddItem(T value, int32 index)
29		{ BList::AddItem((void*)value, index); }
30
31	// information
32	inline bool HasItem(T value) const
33		{ return BList::HasItem((void*)value); }
34
35	inline int32 IndexOf(T value) const
36		{ return BList::IndexOf((void*)value); }
37
38	inline bool IsEmpty() const
39		{ return BList::IsEmpty(); }
40
41	inline int32 CountItems() const
42		{ return BList::CountItems(); }
43
44	// retrieving items
45	inline T ItemAt(int32 index) const
46		{ return (T)BList::ItemAt(index); }
47
48	inline T ItemAtFast(int32 index) const
49		{ return (T)BList::ItemAtFast(index); }
50
51	inline T FirstItem() const
52		{ return (T)BList::FirstItem(); }
53
54	inline T LastItem() const
55		{ return (T)BList::LastItem(); }
56
57	// removing items
58	inline bool RemoveItem(T value)
59		{ return BList::RemoveItem((void*)value); }
60
61	inline T RemoveItem(int32 index)
62		{ return (T)BList::RemoveItem(index); }
63
64	inline bool RemoveItems(int32 index, int32 count)
65		{ return BList::RemoveItems(index, count); }
66
67	inline void MakeEmpty() {
68		if (delete_on_destruction) {
69			// delete all values
70			int32 count = CountItems();
71			for (int32 i = 0; i < count; i++)
72				delete (T)BList::ItemAtFast(i);
73		}
74		BList::MakeEmpty();
75	}
76};
77
78#endif	// LIST_H
79