File: txNodeSet.h

package info (click to toggle)
kompozer 1%3A0.8~b3.dfsg.1-0.1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 283,956 kB
  • ctags: 314,166
  • sloc: cpp: 1,763,181; ansic: 990,028; xml: 97,969; makefile: 46,334; asm: 34,989; perl: 26,943; sh: 20,165; cs: 6,232; java: 5,513; python: 3,221; pascal: 340; lex: 306; php: 244; csh: 132; objc: 97; yacc: 79; ada: 49; awk: 14; sql: 4; sed: 4
file content (241 lines) | stat: -rw-r--r-- 8,178 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is TransforMiiX XSLT processor code.
 *
 * The Initial Developer of the Original Code is
 * The MITRE Corporation.
 * Portions created by the Initial Developer are Copyright (C) 1999
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   Keith Visco <kvisco@ziplink.net> (Original Author)
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

/**
 * Implementation of an XPath NodeSet
 */

#ifndef txNodeSet_h__
#define txNodeSet_h__

#include "ExprResult.h"
#include "nsVoidArray.h"
#include "txError.h"
#include "txXPathTreeWalker.h"

class txNodeSet : public txAExprResult
{
public:
    /**
     * Creates a new empty NodeSet
     */
    txNodeSet(txResultRecycler* aRecycler);

    /**
     * Creates a new NodeSet with one node.
     */
    txNodeSet(const txXPathNode& aNode, txResultRecycler* aRecycler);

    /**
     * Creates a new txNodeSet, copying the node references from the source
     * NodeSet.
     */
    txNodeSet(const txNodeSet& aSource, txResultRecycler* aRecycler);

    /**
     * Destructor for txNodeSet, deletes the nodes.
     */
    virtual ~txNodeSet();

    /**
     * Adds the specified txXPathNode to this NodeSet if it is not already
     * in this NodeSet. The node is inserted according to document order.
     *
     * @param  aNode the txXPathNode to add to the NodeSet
     * @return errorcode.
     */
    nsresult add(const txXPathNode& aNode);

    /**
     * Adds the nodes in specified NodeSet to this NodeSet. The resulting
     * NodeSet is sorted in document order and does not contain any duplicate
     * nodes.
     *
     * @param  aNodes the NodeSet to add, must be in document order.
     * @return errorcode.
     */
    nsresult add(const txNodeSet& aNodes);
    nsresult addAndTransfer(txNodeSet* aNodes);

    /**
     * Append API
     * These functions should be used with care.
     * They are intended to be used when the caller assures that the resulting
     * NodeSet remains in document order.
     * Abuse will break document order, and cause errors in the result.
     * These functions are significantly faster than the add API, as no
     * order info operations will be performed.
     */

    /**
     * Appends the specified Node to the end of this NodeSet
     * @param  aNode the Node to append to the NodeSet
     * @return errorcode.
     */
    nsresult append(const txXPathNode& aNode);

    /**
     * Appends the nodes in the specified NodeSet to the end of this NodeSet
     * @param  aNodes the NodeSet to append to the NodeSet
     * @return errorcode.
     */
    nsresult append(const txNodeSet& aNodes);

    /**
     * API to implement reverse axes in LocationStep.
     *
     * Before adding nodes to the nodeset for a reversed axis, call
     * setReverse(). This will make the append(aNode) and get() methods treat
     * the nodeset as required. Do only call append(aNode), get(), mark()
     * and sweep() while the nodeset is reversed.
     * Afterwards, call unsetReverse(). The nodes are stored in document
     * order internally.
     */
    void setReverse()
    {
        mDirection = -1;
    }
    void unsetReverse()
    {
        mDirection = 1;
    }

    /**
     * API to implement predicates in PredicateExpr
     *
     * mark(aIndex) marks the specified member of the nodeset.
     * sweep() clears all members of the nodeset that haven't been
     * marked before and clear the mMarks array.
     */
    nsresult mark(PRInt32 aIndex);
    nsresult sweep();

    /**
     * Removes all nodes from this nodeset
     */
    void clear();

    /**
     * Returns the index of the specified Node,
     * or -1 if the Node is not contained in the NodeSet
     * @param  aNode the Node to get the index for
     * @return index of specified node or -1 if the node does not exist
     */
    PRInt32 indexOf(const txXPathNode& aNode) const;

    /**
     * Returns true if the specified Node is contained in the set.
     * @param  aNode the Node to search for
     * @return true if specified Node is contained in the NodeSet
     */
    PRBool contains(const txXPathNode& aNode) const
    {
        return indexOf(aNode) >= 0;
    }

    /**
     * Returns the Node at the specified node in this NodeSet.
     * @param  aIndex the node of the Node to return
     * @return Node at specified node
     */
    const txXPathNode& get(PRInt32 aIndex) const;

    /**
     * Returns true if there are no Nodes in the NodeSet.
     * @return true if there are no Nodes in the NodeSet.
     */
    PRBool isEmpty() const
    {
        return mStart ? mStart == mEnd : PR_TRUE;
    }

    /**
     * Returns the number of elements in the NodeSet
     * @return the number of elements in the NodeSet
     */
    PRInt32 size() const
    {
        return mStart ? mEnd - mStart : 0;
    }

    TX_DECL_EXPRRESULT

private:
    static void toString(const txNodeSet& aNodes, nsAString& aResult);

    /**
     * Ensure that this nodeset can take another aSize nodes.
     *
     * Changes mStart and mEnd as well as mBufferStart and mBufferEnd.
     */
    PRBool ensureGrowSize(PRInt32 aSize);

    /**
     * Finds position in the buffer where a node should be inserted
     * to keep the nodeset in document order. Searches the positions
     * aFirst-aLast, including aFirst, but not aLast.
     * @param  aNode   Node to find insert position for.
     * @param  aFirst  First item of the search range, included.
     * @param  aLast   Last item of the search range, excluded.
     * @param  aDupe   out-param. Will be set to true if the node already
     *                 exists in the NodeSet, false if it should be
     *                 inserted.
     * @return pointer where to insert the node. The node should be inserted
     *         before the given node. This value is always set, even if aNode
     *         already exists in the NodeSet
     */
    txXPathNode* findPosition(const txXPathNode& aNode, 
                              txXPathNode* aFirst,
                              txXPathNode* aLast, PRBool& aDupe) const;

    static void copyElements(txXPathNode* aDest, const txXPathNode* aStart,
                             const txXPathNode* aEnd);
    static void transferElements(txXPathNode* aDest, const txXPathNode* aStart,
                                 const txXPathNode* aEnd);

    typedef void (*transferOp) (txXPathNode* aDest, const txXPathNode* aStart,
                                const txXPathNode* aEnd);
    nsresult add(const txNodeSet& aNodes, transferOp aTransfer);

    txXPathNode *mStart, *mEnd, *mStartBuffer, *mEndBuffer;
    PRInt32 mDirection;
    // used for mark() and sweep() in predicates
    PRPackedBool* mMarks;
};

#endif