/* * Jakelib2 - General purpose C++ library * Copyright (C) 2001 Florian Wolff (florian@donuz.de) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * $Id: ZArrayList.h,v 1.2 2002/06/08 10:09:42 florian Exp $ */ /** *

This class implements a simple to use, self-growing list. * Objects to be stored in an ZArrayList must be derived from * Object.

*

ZArrayList makes use of the reference counter every ZObject * has. The reference counter of every object added to the array list is incremented. * If autoDelete is TRUE the reference counter for every object * that is removed from the array list (by clear, remove, * removeLastElement or overwritten by set) will be decremented. * Objects with a reference count auf zero are deleted automatically.

* * @package jakelib.util * @version $Id: ZArrayList.h,v 1.2 2002/06/08 10:09:42 florian Exp $ * @author Florian 'Overflo' Wolff (florian@donuz.de) */ class ZArrayList : public ZObject { public: enum SortDirection {ASCENDING, DESCENDING}; /** * Constructs an empty ZArrayList so that its internal data array * has size 10 and its standard capacity increment is * zero. */ ZArrayList(); /** * Constructs an empty ZArrayList so that its internal data array * has size 10 and its standard capacity increment is * zero. * * @param autoDelete If set to TRUE the delete operator is called for every list item beeing removed from the list. */ ZArrayList(boolean autoDelete); /** * Constructs an empty ZArrayList with the specified initial capacity and * with its capacity increment equal to zero. * * @param initialCapacity The initial capacity of the ZArrayList. * @param autoDelete If set to TRUE the delete operator is called for every list item beeing removed from the list. */ ZArrayList(int initialCapacity, boolean autoDelete); ZArrayList(int initialCapacity, int capacityIncrement, boolean autoDelete); ~ZArrayList(); int add(ZObject* object); int add(const char* str); void ensureCapacity(int minCapacity); ZObject* get(int index); /** * Returns the number of elements stored in the ZArrayList. * * @return Number of elements. */ int size(); /** * Determines whether the ZArrayList is empty. * * @return TRUE if the ZArrayList is empty, FALSE if it contains at least one item. */ boolean isEmpty(); void flush(); void set(int index, ZObject* object); void insert(int index, ZObject* object); void clear(); int indexOf(ZObject* object); boolean contains(ZObject* object); void removeLastElement(); void remove(int index); boolean remove(ZObject* object); protected: ZObject** elementData; int elementCount; int capacityIncrement; int capacity; boolean autoDelete; void init(int initialCapacity, int capacityIncrement, boolean autoDelete); };