Xalan-C++ API Reference 1.12.0
NodeSorter.hpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18#if !defined(XALAN_NODESORTER_HEADER_GUARD)
19#define XALAN_NODESORTER_HEADER_GUARD
20
21// Base include file. Must be first.
22#include "XSLTDefinitions.hpp"
23
24
25
26#include <functional>
27
28
29
31
32
33
35
36
37
39
40
41
42namespace XALAN_CPP_NAMESPACE {
43
44
45
46class MutableNodeRefList;
47class StylesheetExecutionContext;
48class XalanNode;
49class XPath;
50
51
54
57
58
59/**
60 * This class can sort vectors of nodes according to a select pattern.
61 */
63{
64public:
65
67 {
68 public:
69
71 XalanNode* theNode = 0,
73 m_node(theNode),
74 m_position(thePosition)
75 {
76 }
77
80 };
81
84
85 explicit
86 NodeSorter(MemoryManager& theManager);
87
89
92 {
93 return m_keys;
94 }
95
96 /**
97 * Given a list of nodes, sort each node according to the criteria in the
98 * keys. The list is assumed to be in document order.
99 *
100 * @param executionContext current execution context
101 * @param v list of Nodes
102 */
103 void
107
108 /**
109 * Return the results of a compare of two nodes.
110 */
112 {
113 public:
114
115 /**
116 * Construct a NodeSortKeyCompare object, to perform the sort
117 *
118 * @param executionContext current execution context
119 * @param theNodes vector or nodes to be sorted
120 * @param theNodeSortKeys vector of keys upon which to sort
121 */
127 m_executionContext(executionContext),
128 m_sorter(theSorter),
129 m_nodes(theNodes),
130 m_nodeSortKeys(theNodeSortKeys)
131 {
132 }
133
134 /**
135 * Compare two nodes, returning a value to indicate the
136 * result
137 *
138 * @param theLHS the first node to compare
139 * @param theRHS the second node to compare
140 * @param theKeyIndex the index of the key to use
141 * @result < 0 if theLHS is less than theRHS, 0 if they are equal, and > 0 if theLHS is greater than theRHS
142 */
143 int
147 XalanSize_t theKeyIndex = 0) const;
148
149 /**
150 * Compare two nodes as a less predicate.
151 *
152 * @param theLHS the first node to compare
153 * @param theRHS the second node to compare
154 * @param theKeyIndex the index of the key to use
155 * @return true if theLHS is less than theRHS
156 */
157 bool
161 XalanSize_t theKeyIndex = 0) const
162 {
163 return compare(theLHS, theRHS, theKeyIndex) < 0 ? true : false;
164 }
165
166 protected:
167
168 double
170 const NodeSortKey& theKey,
173
174 const XalanDOMString&
176 const NodeSortKey& theKey,
179
180 private:
181
182 StylesheetExecutionContext& m_executionContext;
183 NodeSorter& m_sorter;
184 const NodeVectorType& m_nodes;
185 const NodeSortKeyVectorType& m_nodeSortKeys;
186 };
187
188 friend struct NodeSortKeyCompare;
189
193
197
199
200#if defined(XALAN_NODESORTER_CACHE_XOBJECTS)
202#else
204#endif
205
206private:
207
208 /**
209 * Given a vector of nodes, sort each node according to the criteria in the
210 * keys.
211 *
212 * @param executionContext current execution context
213 */
214 void
216
217 // Data members...
218 NumberResultsCacheType m_numberResultsCache;
219
220 StringResultsCacheType m_stringResultsCache;
221
223
224 NodeVectorType m_scratchVector;
225};
226
227
228
229}
230
231
232
233#endif // XALAN_NODESORTER_HEADER_GUARD
#define XALAN_XSLT_EXPORT
#define XALAN_USES_MEMORY_MANAGER(Type)
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Local implementation of MutableNodeRefList.
Simple data structure class for use by the NodeSorter class.
This class can sort vectors of nodes according to a select pattern.
XalanVector< VectorEntry > NodeVectorType
NumberVectorTypeDecl NumberVectorType
NodeSorter(MemoryManager &theManager)
XalanVector< NodeSortKey > NodeSortKeyVectorType
void sort(StylesheetExecutionContext &executionContext, MutableNodeRefList &theList)
Given a list of nodes, sort each node according to the criteria in the keys.
XalanVector< StringVectorType > StringCacheType
NodeSortKeyVectorType & getSortKeys()
XalanVector< XObjectVectorType > XObjectCacheType
NumberCacheType NumberResultsCacheType
StringVectorTypeDecl StringVectorType
StringCacheType StringResultsCacheType
XalanVector< NumberVectorType > NumberCacheType
XalanVector< XObjectPtr > XObjectVectorType
compare(const CharVectorType &theLHS, const CharVectorType &theRHS)
Compare the contents of two strings.
Return the results of a compare of two nodes.
int compare(const NodeVectorType::value_type &theLHS, const NodeVectorType::value_type &theRHS, XalanSize_t theKeyIndex=0) const
Compare two nodes, returning a value to indicate the result.
NodeSortKeyCompare(StylesheetExecutionContext &executionContext, NodeSorter &theSorter, const NodeVectorType &theNodes, const NodeSortKeyVectorType &theNodeSortKeys)
Construct a NodeSortKeyCompare object, to perform the sort.
double getNumberResult(const NodeSortKey &theKey, XalanSize_t theKeyIndex, const NodeVectorType::value_type &theEntry) const
bool operator()(const NodeVectorType::value_type &theLHS, const NodeVectorType::value_type &theRHS, XalanSize_t theKeyIndex=0) const
Compare two nodes as a less predicate.
const XalanDOMString & getStringResult(const NodeSortKey &theKey, XalanSize_t theKeyIndex, const NodeVectorType::value_type &theEntry) const
VectorEntry(XalanNode *theNode=0, XalanSize_t thePosition=0)