From 0723a9ac982948e1a674ad3ee45e9392bd7d4df3 Mon Sep 17 00:00:00 2001 From: Michael Pfeiffer Date: Thu, 8 Aug 2002 16:13:29 +0000 Subject: [PATCH] Template list class. Duplicates the one in current/src/add-ons/print/drivers/pdf/source git-svn-id: file:///srv/svn/repos/haiku/trunk/current@652 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/kits/midi/synth_file_reader/TList.h | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 src/tests/kits/midi/synth_file_reader/TList.h diff --git a/src/tests/kits/midi/synth_file_reader/TList.h b/src/tests/kits/midi/synth_file_reader/TList.h new file mode 100644 index 0000000000..10350e8b9e --- /dev/null +++ b/src/tests/kits/midi/synth_file_reader/TList.h @@ -0,0 +1,110 @@ +/* + +TList.h + +Copyright (c) 2002 OpenBeOS. + +Author: + Michael Pfeiffer + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +*/ + +/* +TODO: Move this header file into a "common" directory! +This class is an minor extended version of the one found in +current/src/add-ons/print/drivers/pdf/source +*/ + +#ifndef _TLIST_H +#define _TLIST_H + +#include + +template +class TList { +private: + BList fList; + bool fOwnsItems; + + typedef int (*sort_func)(const void*, const void*); + +public: + TList(bool ownsItems = true) : fOwnsItems(ownsItems) { } + virtual ~TList(); + void MakeEmpty(); + int32 CountItems() const; + T* ItemAt(int32 index) const; + void AddItem(T* p); + T* Items(); + void SortItems(int (*comp)(const T**, const T**)); + +}; + +// TList +template +TList::~TList() { + MakeEmpty(); +} + + +template +void TList::MakeEmpty() { + const int32 n = CountItems(); + if (fOwnsItems) { + for (int i = 0; i < n; i++) { + delete ItemAt(i); + } + } + fList.MakeEmpty(); +} + + +template +int32 TList::CountItems() const { + return fList.CountItems(); +} + + +template +T* TList::ItemAt(int32 index) const { + return (T*)fList.ItemAt(index); +} + + +template +void TList::AddItem(T* p) { + fList.AddItem(p); +} + + +template +T* TList::Items() { + return (T*)fList.Items(); +} + + +template +void TList::SortItems(int (*comp)(const T**, const T**)) { + sort_func sort = (sort_func)comp; + fList.SortItems(sort); +} + +#endif