Bumping manifests a=b2g-bump
[gecko.git] / dom / xslt / base / txList.h
blob180bab1afe8ebc2103e8598e500a5c9df231a313
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef TRANSFRMX_LIST_H
7 #define TRANSFRMX_LIST_H
9 #include "txCore.h"
11 class txListIterator;
13 /**
14 * Represents an ordered list of Object pointers. Modeled after a Java 2 List.
15 **/
16 class txList : public txObject {
18 friend class txListIterator;
20 public:
22 /**
23 * Creates an empty txList
24 **/
25 txList();
27 /**
28 * txList destructor, object references will not be deleted.
29 **/
30 ~txList();
32 /**
33 * Returns the number of items in this txList
34 **/
35 int32_t getLength();
37 /**
38 * Returns true if there are no items in this txList
40 inline bool isEmpty()
42 return itemCount == 0;
45 /**
46 * Adds the given Object to the list
47 **/
48 nsresult add(void* objPtr);
51 * Removes all the objects from the list
53 void clear();
55 protected:
57 struct ListItem {
58 ListItem* nextItem;
59 ListItem* prevItem;
60 void* objPtr;
63 /**
64 * Removes the given ListItem pointer from the list
65 **/
66 ListItem* remove(ListItem* sItem);
68 private:
69 txList(const txList& aOther); // not implemented
71 ListItem* firstItem;
72 ListItem* lastItem;
73 int32_t itemCount;
75 nsresult insertAfter(void* objPtr, ListItem* sItem);
76 nsresult insertBefore(void* objPtr, ListItem* sItem);
81 /**
82 * An Iterator for the txList Class
83 **/
84 class txListIterator {
86 public:
87 /**
88 * Creates a new txListIterator for the given txList
89 * @param list, the txList to create an Iterator for
90 **/
91 explicit txListIterator(txList* list);
93 /**
94 * Adds the Object pointer to the txList pointed to by this txListIterator.
95 * The Object pointer is inserted as the next item in the txList
96 * based on the current position within the txList
97 * @param objPtr the Object pointer to add to the list
98 **/
99 nsresult addAfter(void* objPtr);
102 * Adds the Object pointer to the txList pointed to by this txListIterator.
103 * The Object pointer is inserted as the previous item in the txList
104 * based on the current position within the txList
105 * @param objPtr the Object pointer to add to the list
107 nsresult addBefore(void* objPtr);
110 * Returns true if a successful call to the next() method can be made
111 * @return true if a successful call to the next() method can be made,
112 * otherwise false
114 bool hasNext();
117 * Returns the next Object pointer from the list
119 void* next();
122 * Returns the previous Object pointer from the list
124 void* previous();
127 * Returns the current Object
129 void* current();
132 * Removes the Object last returned by the next() or previous() methods;
133 * @return the removed Object pointer
135 void* remove();
138 * Resets the current location within the txList to the beginning of the txList
140 void reset();
143 * Resets the current location within the txList to the end of the txList
145 void resetToEnd();
147 private:
149 //-- points to the current list item
150 txList::ListItem* currentItem;
152 //-- points to the list to iterator over
153 txList* list;
155 //-- we've moved off the end of the list
156 bool atEndOfList;
159 typedef txList List;
161 #endif