1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/xslt/base/txList.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,161 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef TRANSFRMX_LIST_H 1.10 +#define TRANSFRMX_LIST_H 1.11 + 1.12 +#include "txCore.h" 1.13 + 1.14 +class txListIterator; 1.15 + 1.16 +/** 1.17 + * Represents an ordered list of Object pointers. Modeled after a Java 2 List. 1.18 +**/ 1.19 +class txList : public txObject { 1.20 + 1.21 +friend class txListIterator; 1.22 + 1.23 +public: 1.24 + 1.25 + /** 1.26 + * Creates an empty txList 1.27 + **/ 1.28 + txList(); 1.29 + 1.30 + /** 1.31 + * txList destructor, object references will not be deleted. 1.32 + **/ 1.33 + ~txList(); 1.34 + 1.35 + /** 1.36 + * Returns the number of items in this txList 1.37 + **/ 1.38 + int32_t getLength(); 1.39 + 1.40 + /** 1.41 + * Returns true if there are no items in this txList 1.42 + */ 1.43 + inline bool isEmpty() 1.44 + { 1.45 + return itemCount == 0; 1.46 + } 1.47 + 1.48 + /** 1.49 + * Adds the given Object to the list 1.50 + **/ 1.51 + nsresult add(void* objPtr); 1.52 + 1.53 + /* 1.54 + * Removes all the objects from the list 1.55 + */ 1.56 + void clear(); 1.57 + 1.58 +protected: 1.59 + 1.60 + struct ListItem { 1.61 + ListItem* nextItem; 1.62 + ListItem* prevItem; 1.63 + void* objPtr; 1.64 + }; 1.65 + 1.66 + /** 1.67 + * Removes the given ListItem pointer from the list 1.68 + **/ 1.69 + ListItem* remove(ListItem* sItem); 1.70 + 1.71 +private: 1.72 + txList(const txList& aOther); // not implemented 1.73 + 1.74 + ListItem* firstItem; 1.75 + ListItem* lastItem; 1.76 + int32_t itemCount; 1.77 + 1.78 + nsresult insertAfter(void* objPtr, ListItem* sItem); 1.79 + nsresult insertBefore(void* objPtr, ListItem* sItem); 1.80 +}; 1.81 + 1.82 + 1.83 + 1.84 +/** 1.85 + * An Iterator for the txList Class 1.86 +**/ 1.87 +class txListIterator { 1.88 + 1.89 +public: 1.90 + /** 1.91 + * Creates a new txListIterator for the given txList 1.92 + * @param list, the txList to create an Iterator for 1.93 + **/ 1.94 + txListIterator(txList* list); 1.95 + 1.96 + /** 1.97 + * Adds the Object pointer to the txList pointed to by this txListIterator. 1.98 + * The Object pointer is inserted as the next item in the txList 1.99 + * based on the current position within the txList 1.100 + * @param objPtr the Object pointer to add to the list 1.101 + **/ 1.102 + nsresult addAfter(void* objPtr); 1.103 + 1.104 + /** 1.105 + * Adds the Object pointer to the txList pointed to by this txListIterator. 1.106 + * The Object pointer is inserted as the previous item in the txList 1.107 + * based on the current position within the txList 1.108 + * @param objPtr the Object pointer to add to the list 1.109 + **/ 1.110 + nsresult addBefore(void* objPtr); 1.111 + 1.112 + /** 1.113 + * Returns true if a successful call to the next() method can be made 1.114 + * @return true if a successful call to the next() method can be made, 1.115 + * otherwise false 1.116 + **/ 1.117 + bool hasNext(); 1.118 + 1.119 + /** 1.120 + * Returns the next Object pointer from the list 1.121 + **/ 1.122 + void* next(); 1.123 + 1.124 + /** 1.125 + * Returns the previous Object pointer from the list 1.126 + **/ 1.127 + void* previous(); 1.128 + 1.129 + /** 1.130 + * Returns the current Object 1.131 + **/ 1.132 + void* current(); 1.133 + 1.134 + /** 1.135 + * Removes the Object last returned by the next() or previous() methods; 1.136 + * @return the removed Object pointer 1.137 + **/ 1.138 + void* remove(); 1.139 + 1.140 + /** 1.141 + * Resets the current location within the txList to the beginning of the txList 1.142 + **/ 1.143 + void reset(); 1.144 + 1.145 + /** 1.146 + * Resets the current location within the txList to the end of the txList 1.147 + **/ 1.148 + void resetToEnd(); 1.149 + 1.150 +private: 1.151 + 1.152 + //-- points to the current list item 1.153 + txList::ListItem* currentItem; 1.154 + 1.155 + //-- points to the list to iterator over 1.156 + txList* list; 1.157 + 1.158 + //-- we've moved off the end of the list 1.159 + bool atEndOfList; 1.160 +}; 1.161 + 1.162 +typedef txList List; 1.163 + 1.164 +#endif