From 502b279d243d79f46bb8a151ae610949d30bf757 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 15 Dec 2004 00:24:12 +0000 Subject: Patch #1081904 ITE: MAC demo support o Endianness-aware resource loading o Removed ys_dl_list in favor of our object implementation o Cleanup in actor code o Partial support for ITE Mac rereleased demo svn-id: r16051 --- saga/list.h | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 saga/list.h (limited to 'saga/list.h') diff --git a/saga/list.h b/saga/list.h new file mode 100644 index 0000000000..dbffc4176c --- /dev/null +++ b/saga/list.h @@ -0,0 +1,154 @@ +/* ScummVM - Scumm Interpreter + * Copyright (C) 2004 The ScummVM project + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Header$ + * + */ + +#ifndef SAGA_LIST_H__ +#define SAGA_LIST_H__ + +#include "common/list.h" + +namespace Saga { + + +template +class SortedList : public Common::List { +public: + typedef int ( CompareFunction ) (const T& , const T&); + + typedef typename Common::List::iterator iterator; + typedef typename Common::List::const_iterator const_iterator; + +public: + + iterator pushFront(const T& element) { + return insert(begin(), element); + } + + iterator pushBack(const T& element) { + return insert(end(), element); + } + + iterator insert(iterator pos, const T& element) { + Common::List::insert(pos, element); + return --pos; + } + + iterator pushFront() { + return insert(begin()); + } + + iterator pushBack() { + return insert(end()); + } + + iterator insert(iterator pos) { + T init; + return insert(pos, init); + } + + iterator pushFront(const T& element, CompareFunction* compareFunction) { + return insert(begin(), element, compareFunction); + } + + iterator pushBack(const T& element, CompareFunction* compareFunction) { + return insert(end(), element, compareFunction); + } + + iterator insert(iterator pos, const T& element, CompareFunction* compareFunction) { + int res; + + for (iterator i = begin(); i != end(); ++i) { + res = compareFunction(element, i.operator*()); + if (res < 0) { + return insert(i, element); + } + } + return pushBack(element); + } + + void reorderUp(iterator pos, CompareFunction* compareFunction) { + iterator i(pos); + int res; + + --i; + while (i != end()) { + res = compareFunction(i.operator*(), pos.operator*()); + if (res <= 0) { + + T temp(*pos); + erase(pos); + ++i; + Common::List::insert(i, temp); + return; + } + --i; + } + } + + void reorderDown(iterator pos, CompareFunction* compareFunction) { + iterator i(pos); + int res; + + ++i; + while (i != end()) { + res = compareFunction(i.operator*(), pos.operator*()); + if (res >= 0) { + + T temp(*pos); + erase(pos); + Common::List::insert(i, temp); + return; + } + ++i; + } + } + + iterator eraseAndPrev(iterator pos) { + assert(pos != end()); + iterator res(pos); + + --res; + erase(pos); + return res; + } + + void remove(const T* val) { + for (iterator i = begin(); i != end(); ++i) + if(val == i.operator->()) { + erase(i); + return; + } + } + + bool locate(const T* val, iterator& foundedIterator) { + + for (iterator i = begin(); i != end(); ++i) + if (val == i.operator->()) + { + foundedIterator = i; + return true; + } + + return false; + } +}; + +} // End of namespace Saga +#endif -- cgit v1.2.3