From 20789329c37b67836fbb286e484fcabb92e529c1 Mon Sep 17 00:00:00 2001 From: beveloper Date: Mon, 30 Jun 2003 10:41:09 +0000 Subject: [PATCH] a simple list template that uses realtime memory git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3756 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../media/media-add-ons/mixer/RtList.h | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/add-ons/media/media-add-ons/mixer/RtList.h diff --git a/src/add-ons/media/media-add-ons/mixer/RtList.h b/src/add-ons/media/media-add-ons/mixer/RtList.h new file mode 100644 index 0000000000..fabef04461 --- /dev/null +++ b/src/add-ons/media/media-add-ons/mixer/RtList.h @@ -0,0 +1,64 @@ +#ifndef _MEDIA_RT_LIST_H +#define _MEDIA_RT_LIST_H +/* Copyright (C) 2003 Marcus Overhagen + * Released under terms of the MIT license. + * + * A simple list template that uses realtime + * memory and does no error checking. Since + * it doesn't call constructors ot destructors, + * don't use it to store objects. + */ + +#include + +template class RtList +{ +public: + RtList() + : item_max(INIT_COUNT), + item_count(0), + items((value *)rtm_alloc(NULL, sizeof(value) * INIT_COUNT)) + { + } + + ~RtList() + { + rtm_free(items); + } + + value *Create() + { + if (item_count == item_max) { + item_max += INC_COUNT; + rtm_realloc((void **)&items, sizeof(value) * item_max); + } + return &items[item_count++]; + } + + value *ItemAt(int index) + { + return &items[index]; + } + + int CountItems() + { + return item_count; + } + + void MakeEmpty() + { + item_count = 0; + } + +private: + RtList(const RtList &other); + RtList &operator=(const RtList &other); + +private: + enum { INIT_COUNT = 8, INC_COUNT = 16 }; + int item_max; + int item_count; + value *items; +}; + +#endif // _MEDIA_RT_LIST_H