michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef TRANSFRMX_LIST_H michael@0: #define TRANSFRMX_LIST_H michael@0: michael@0: #include "txCore.h" michael@0: michael@0: class txListIterator; michael@0: michael@0: /** michael@0: * Represents an ordered list of Object pointers. Modeled after a Java 2 List. michael@0: **/ michael@0: class txList : public txObject { michael@0: michael@0: friend class txListIterator; michael@0: michael@0: public: michael@0: michael@0: /** michael@0: * Creates an empty txList michael@0: **/ michael@0: txList(); michael@0: michael@0: /** michael@0: * txList destructor, object references will not be deleted. michael@0: **/ michael@0: ~txList(); michael@0: michael@0: /** michael@0: * Returns the number of items in this txList michael@0: **/ michael@0: int32_t getLength(); michael@0: michael@0: /** michael@0: * Returns true if there are no items in this txList michael@0: */ michael@0: inline bool isEmpty() michael@0: { michael@0: return itemCount == 0; michael@0: } michael@0: michael@0: /** michael@0: * Adds the given Object to the list michael@0: **/ michael@0: nsresult add(void* objPtr); michael@0: michael@0: /* michael@0: * Removes all the objects from the list michael@0: */ michael@0: void clear(); michael@0: michael@0: protected: michael@0: michael@0: struct ListItem { michael@0: ListItem* nextItem; michael@0: ListItem* prevItem; michael@0: void* objPtr; michael@0: }; michael@0: michael@0: /** michael@0: * Removes the given ListItem pointer from the list michael@0: **/ michael@0: ListItem* remove(ListItem* sItem); michael@0: michael@0: private: michael@0: txList(const txList& aOther); // not implemented michael@0: michael@0: ListItem* firstItem; michael@0: ListItem* lastItem; michael@0: int32_t itemCount; michael@0: michael@0: nsresult insertAfter(void* objPtr, ListItem* sItem); michael@0: nsresult insertBefore(void* objPtr, ListItem* sItem); michael@0: }; michael@0: michael@0: michael@0: michael@0: /** michael@0: * An Iterator for the txList Class michael@0: **/ michael@0: class txListIterator { michael@0: michael@0: public: michael@0: /** michael@0: * Creates a new txListIterator for the given txList michael@0: * @param list, the txList to create an Iterator for michael@0: **/ michael@0: txListIterator(txList* list); michael@0: michael@0: /** michael@0: * Adds the Object pointer to the txList pointed to by this txListIterator. michael@0: * The Object pointer is inserted as the next item in the txList michael@0: * based on the current position within the txList michael@0: * @param objPtr the Object pointer to add to the list michael@0: **/ michael@0: nsresult addAfter(void* objPtr); michael@0: michael@0: /** michael@0: * Adds the Object pointer to the txList pointed to by this txListIterator. michael@0: * The Object pointer is inserted as the previous item in the txList michael@0: * based on the current position within the txList michael@0: * @param objPtr the Object pointer to add to the list michael@0: **/ michael@0: nsresult addBefore(void* objPtr); michael@0: michael@0: /** michael@0: * Returns true if a successful call to the next() method can be made michael@0: * @return true if a successful call to the next() method can be made, michael@0: * otherwise false michael@0: **/ michael@0: bool hasNext(); michael@0: michael@0: /** michael@0: * Returns the next Object pointer from the list michael@0: **/ michael@0: void* next(); michael@0: michael@0: /** michael@0: * Returns the previous Object pointer from the list michael@0: **/ michael@0: void* previous(); michael@0: michael@0: /** michael@0: * Returns the current Object michael@0: **/ michael@0: void* current(); michael@0: michael@0: /** michael@0: * Removes the Object last returned by the next() or previous() methods; michael@0: * @return the removed Object pointer michael@0: **/ michael@0: void* remove(); michael@0: michael@0: /** michael@0: * Resets the current location within the txList to the beginning of the txList michael@0: **/ michael@0: void reset(); michael@0: michael@0: /** michael@0: * Resets the current location within the txList to the end of the txList michael@0: **/ michael@0: void resetToEnd(); michael@0: michael@0: private: michael@0: michael@0: //-- points to the current list item michael@0: txList::ListItem* currentItem; michael@0: michael@0: //-- points to the list to iterator over michael@0: txList* list; michael@0: michael@0: //-- we've moved off the end of the list michael@0: bool atEndOfList; michael@0: }; michael@0: michael@0: typedef txList List; michael@0: michael@0: #endif