Back to index

lightning-sunbird  0.9+nobinonly
txNodeSet.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 
00043 #ifndef txNodeSet_h__
00044 #define txNodeSet_h__
00045 
00046 #include "ExprResult.h"
00047 #include "nsVoidArray.h"
00048 #include "txError.h"
00049 #include "txXPathTreeWalker.h"
00050 
00051 class txNodeSet : public txAExprResult
00052 {
00053 public:
00057     txNodeSet(txResultRecycler* aRecycler);
00058 
00062     txNodeSet(const txXPathNode& aNode, txResultRecycler* aRecycler);
00063 
00068     txNodeSet(const txNodeSet& aSource, txResultRecycler* aRecycler);
00069 
00073     virtual ~txNodeSet();
00074 
00082     nsresult add(const txXPathNode& aNode);
00083 
00092     nsresult add(const txNodeSet& aNodes);
00093     nsresult addAndTransfer(txNodeSet* aNodes);
00094 
00110     nsresult append(const txXPathNode& aNode);
00111 
00117     nsresult append(const txNodeSet& aNodes);
00118 
00129     void setReverse()
00130     {
00131         mDirection = -1;
00132     }
00133     void unsetReverse()
00134     {
00135         mDirection = 1;
00136     }
00137 
00145     nsresult mark(PRInt32 aIndex);
00146     nsresult sweep();
00147 
00151     void clear();
00152 
00159     PRInt32 indexOf(const txXPathNode& aNode) const;
00160 
00166     PRBool contains(const txXPathNode& aNode) const
00167     {
00168         return indexOf(aNode) >= 0;
00169     }
00170 
00176     const txXPathNode& get(PRInt32 aIndex) const;
00177 
00182     PRBool isEmpty() const
00183     {
00184         return mStart ? mStart == mEnd : PR_TRUE;
00185     }
00186 
00191     PRInt32 size() const
00192     {
00193         return mStart ? mEnd - mStart : 0;
00194     }
00195 
00196     TX_DECL_EXPRRESULT
00197 
00198 private:
00199     static void toString(const txNodeSet& aNodes, nsAString& aResult);
00200 
00206     PRBool ensureGrowSize(PRInt32 aSize);
00207 
00222     txXPathNode* findPosition(const txXPathNode& aNode, 
00223                               txXPathNode* aFirst,
00224                               txXPathNode* aLast, PRBool& aDupe) const;
00225 
00226     static void copyElements(txXPathNode* aDest, const txXPathNode* aStart,
00227                              const txXPathNode* aEnd);
00228     static void transferElements(txXPathNode* aDest, const txXPathNode* aStart,
00229                                  const txXPathNode* aEnd);
00230 
00231     typedef void (*transferOp) (txXPathNode* aDest, const txXPathNode* aStart,
00232                                 const txXPathNode* aEnd);
00233     nsresult add(const txNodeSet& aNodes, transferOp aTransfer);
00234 
00235     txXPathNode *mStart, *mEnd, *mStartBuffer, *mEndBuffer;
00236     PRInt32 mDirection;
00237     // used for mark() and sweep() in predicates
00238     PRPackedBool* mMarks;
00239 };
00240 
00241 #endif