1*a9cf57cfSAxel Dörfler /* 2*a9cf57cfSAxel Dörfler * Copyright 2003 Marcus Overhagen 3*a9cf57cfSAxel Dörfler * Distributed under the terms of the MIT License. 4*a9cf57cfSAxel Dörfler */ 520789329Sbeveloper #ifndef _MEDIA_RT_LIST_H 620789329Sbeveloper #define _MEDIA_RT_LIST_H 7*a9cf57cfSAxel Dörfler 8*a9cf57cfSAxel Dörfler 9*a9cf57cfSAxel Dörfler /*! A simple list template that uses realtime 10*a9cf57cfSAxel Dörfler memory and does no error checking. Since 11*a9cf57cfSAxel Dörfler it doesn't call constructors or destructors, 12*a9cf57cfSAxel Dörfler don't use it to store objects. 13*a9cf57cfSAxel Dörfler 14*a9cf57cfSAxel Dörfler // TODO: no error checking? Great. 1520789329Sbeveloper */ 1620789329Sbeveloper 17*a9cf57cfSAxel Dörfler 1820789329Sbeveloper #include <RealtimeAlloc.h> 1920789329Sbeveloper 20*a9cf57cfSAxel Dörfler 21*a9cf57cfSAxel Dörfler template<class value> class RtList { 2220789329Sbeveloper public: RtList()2320789329Sbeveloper RtList() 24*a9cf57cfSAxel Dörfler : 25*a9cf57cfSAxel Dörfler item_max(INIT_COUNT), 2620789329Sbeveloper item_count(0), 2720789329Sbeveloper items((value*)rtm_alloc(NULL, sizeof(value) * INIT_COUNT)) 2820789329Sbeveloper { 2920789329Sbeveloper } 3020789329Sbeveloper ~RtList()3120789329Sbeveloper ~RtList() 3220789329Sbeveloper { 3320789329Sbeveloper rtm_free(items); 3420789329Sbeveloper } 3520789329Sbeveloper Create()3620789329Sbeveloper value* Create() 3720789329Sbeveloper { 3820789329Sbeveloper if (item_count == item_max) { 3920789329Sbeveloper item_max += INC_COUNT; 4020789329Sbeveloper rtm_realloc((void**)&items, sizeof(value) * item_max); 4120789329Sbeveloper } 4220789329Sbeveloper return &items[item_count++]; 4320789329Sbeveloper } 4420789329Sbeveloper ItemAt(int index)4520789329Sbeveloper value* ItemAt(int index) 4620789329Sbeveloper { 4720789329Sbeveloper return &items[index]; 4820789329Sbeveloper } 4920789329Sbeveloper CountItems()5020789329Sbeveloper int CountItems() 5120789329Sbeveloper { 5220789329Sbeveloper return item_count; 5320789329Sbeveloper } 5420789329Sbeveloper MakeEmpty()5520789329Sbeveloper void MakeEmpty() 5620789329Sbeveloper { 5720789329Sbeveloper item_count = 0; 5820789329Sbeveloper } 5920789329Sbeveloper 6020789329Sbeveloper private: 6120789329Sbeveloper RtList(const RtList<value>& other); 6220789329Sbeveloper RtList<value> &operator=(const RtList<value>& other); 6320789329Sbeveloper 6420789329Sbeveloper private: 6520789329Sbeveloper enum { INIT_COUNT = 8, INC_COUNT = 16 }; 66*a9cf57cfSAxel Dörfler 6720789329Sbeveloper int item_max; 6820789329Sbeveloper int item_count; 6920789329Sbeveloper value* items; 7020789329Sbeveloper }; 7120789329Sbeveloper 7220789329Sbeveloper #endif // _MEDIA_RT_LIST_H 73