Back to index

lightning-sunbird  0.9+nobinonly
txList.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is TransforMiiX XSLT processor code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * The MITRE Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Keith Visco <kvisco@ziplink.net> (Original Author)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef TRANSFRMX_LIST_H
00040 #define TRANSFRMX_LIST_H
00041 
00042 #include "txCore.h"
00043 
00044 class txListIterator;
00045 
00049 class txList : public TxObject {
00050 
00051 friend class txListIterator;
00052 
00053 public:
00054 
00058     txList();
00059 
00063     virtual ~txList();
00064 
00070     void* get(int index);
00071 
00075     PRInt32 getLength();
00076 
00080     nsresult insert(int index, void* objPtr);
00081 
00085     nsresult add(void* objPtr);
00086 
00090     void* remove(void* objPtr);
00091     
00092     /*
00093      * Removes all the objects from the list
00094      */
00095     void clear();
00096 
00097 
00098 protected:
00099 
00100     struct ListItem {
00101         ListItem* nextItem;
00102         ListItem* prevItem;
00103         void* objPtr;
00104     };
00105 
00106     ListItem* getFirstItem();
00107     ListItem* getLastItem();
00108 
00112     ListItem* remove(ListItem* sItem);
00113 
00114 private:
00115       txList(const txList& aOther); // not implemented
00116 
00117       ListItem* firstItem;
00118       ListItem* lastItem;
00119       PRInt32 itemCount;
00120 
00121       nsresult insertAfter(void* objPtr, ListItem* sItem);
00122       nsresult insertBefore(void* objPtr, ListItem* sItem);
00123 };
00124 
00125 
00126 
00130 class txListIterator {
00131 
00132 public:
00137     txListIterator(txList* list);
00138 
00142     ~txListIterator();
00143 
00150     nsresult addAfter(void* objPtr);
00151 
00158     nsresult addBefore(void* objPtr);
00159 
00165     MBool  hasNext();
00166 
00172     MBool  hasPrevious();
00173 
00177     void* next();
00178 
00182     void* previous();
00183     
00187     void* current();
00188     
00192     void* advance(int i);
00193 
00198     void* remove();
00199 
00203     void reset();
00204 
00208     void resetToEnd();
00209 
00210 private:
00211 
00212    //-- points to the current list item
00213    txList::ListItem* currentItem;
00214 
00215    //-- points to the list to iterator over
00216    txList* list;
00217 
00218    //-- we've moved off the end of the list
00219    MBool atEndOfList;
00220 };
00221 
00222 typedef txList List;
00223 
00224 #endif