Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.11


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 
34 #include <xalanc/XPath/XObject.hpp>
35 
36 
37 
39 
40 
41 
42 XALAN_CPP_NAMESPACE_BEGIN
43 
44 
45 
46 class MutableNodeRefList;
48 class XalanNode;
49 class XPath;
50 
51 
54 
56 XALAN_USES_MEMORY_MANAGER(StringVectorTypeDecl)
57 
58 
59 /**
60  * This class can sort vectors of nodes according to a select pattern.
61  */
63 {
64 public:
65 
67  {
68  public:
69 
71  XalanNode* theNode = 0,
72  XalanSize_t thePosition = 0) :
73  m_node(theNode),
74  m_position(thePosition)
75  {
76  }
77 
79  XalanSize_t m_position;
80  };
81 
84 
85  explicit
86  NodeSorter(MemoryManager& theManager);
87 
88  ~NodeSorter();
89 
90  NodeSortKeyVectorType&
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
104  sort(
105  StylesheetExecutionContext& executionContext,
106  MutableNodeRefList& theList);
107 
108  /**
109  * Return the results of a compare of two nodes.
110  */
111 #if defined(XALAN_NO_STD_NAMESPACE)
112  struct XALAN_XSLT_EXPORT NodeSortKeyCompare : public binary_function<const NodeVectorType::value_type&, const NodeVectorType::value_type&, bool>
113 #else
114  struct XALAN_XSLT_EXPORT NodeSortKeyCompare : public std::binary_function<const NodeVectorType::value_type&, const NodeVectorType::value_type&, bool>
115 #endif
116  {
117  public:
118 
119  /**
120  * Construct a NodeSortKeyCompare object, to perform the sort
121  *
122  * @param executionContext current execution context
123  * @param theNodes vector or nodes to be sorted
124  * @param theNodeSortKeys vector of keys upon which to sort
125  */
127  StylesheetExecutionContext& executionContext,
128  NodeSorter& theSorter,
129  const NodeVectorType& theNodes,
130  const NodeSortKeyVectorType& theNodeSortKeys) :
131  m_executionContext(executionContext),
132  m_sorter(theSorter),
133  m_nodes(theNodes),
134  m_nodeSortKeys(theNodeSortKeys)
135  {
136  }
137 
138  /**
139  * Compare two nodes, returning a value to indicate the
140  * result
141  *
142  * @param theLHS the first node to compare
143  * @param theRHS the second node to compare
144  * @param theKeyIndex the index of the key to use
145  * @result < 0 if theLHS is less than theRHS, 0 if they are equal, and > 0 if theLHS is greater than theRHS
146  */
147  int
148  compare(
149  first_argument_type theLHS,
150  second_argument_type theRHS,
151  XalanSize_t theKeyIndex = 0) const;
152 
153  /**
154  * Compare two nodes as a less predicate.
155  *
156  * @param theLHS the first node to compare
157  * @param theRHS the second node to compare
158  * @param theKeyIndex the index of the key to use
159  * @return true if theLHS is less than theRHS
160  */
161  result_type
163  first_argument_type theLHS,
164  second_argument_type theRHS,
165  XalanSize_t theKeyIndex = 0) const
166  {
167  return compare(theLHS, theRHS, theKeyIndex) < 0 ? true : false;
168  }
169 
170  protected:
171 
172  double
174  const NodeSortKey& theKey,
175  XalanSize_t theKeyIndex,
176  first_argument_type theEntry) const;
177 
178  const XalanDOMString&
180  const NodeSortKey& theKey,
181  XalanSize_t theKeyIndex,
182  first_argument_type theEntry) const;
183 
184  private:
185 
186  StylesheetExecutionContext& m_executionContext;
187  NodeSorter& m_sorter;
188  const NodeVectorType& m_nodes;
189  const NodeSortKeyVectorType& m_nodeSortKeys;
190  };
191 
192  friend struct NodeSortKeyCompare;
193 
196  typedef StringVectorTypeDecl StringVectorType;
197 
201 
202  typedef NumberCacheType NumberResultsCacheType;
203 
204 #if defined(XALAN_NODESORTER_CACHE_XOBJECTS)
205  typedef XObjectCacheType StringResultsCacheType;
206 #else
207  typedef StringCacheType StringResultsCacheType;
208 #endif
209 
210 private:
211 
212  /**
213  * Given a vector of nodes, sort each node according to the criteria in the
214  * keys.
215  *
216  * @param executionContext current execution context
217  */
218  void
219  sort(StylesheetExecutionContext& executionContext);
220 
221  // Data members...
222  NumberResultsCacheType m_numberResultsCache;
223 
224  StringResultsCacheType m_stringResultsCache;
225 
226  NodeSortKeyVectorType m_keys;
227 
228  NodeVectorType m_scratchVector;
229 };
230 
231 
232 
233 XALAN_CPP_NAMESPACE_END
234 
235 
236 
237 #endif // XALAN_NODESORTER_HEADER_GUARD
int compare(first_argument_type theLHS, second_argument_type theRHS, XalanSize_t theKeyIndex=0) const
Compare two nodes, returning a value to indicate the result.
XalanVector< XObjectPtr > XObjectVectorType
Definition: NodeSorter.hpp:195
Local implementation of MutableNodeRefList.
NumberCacheType NumberResultsCacheType
Definition: NodeSorter.hpp:202
const XalanDOMString & getStringResult(const NodeSortKey &theKey, XalanSize_t theKeyIndex, first_argument_type theEntry) const
XalanVector< NodeSortKey > NodeSortKeyVectorType
Definition: NodeSorter.hpp:83
double getNumberResult(const NodeSortKey &theKey, XalanSize_t theKeyIndex, first_argument_type theEntry) const
StringVectorTypeDecl StringVectorType
Definition: NodeSorter.hpp:196
Definition: XPath.hpp:64
StringCacheType StringResultsCacheType
Definition: NodeSorter.hpp:207
XalanVector< StringVectorType > StringCacheType
Definition: NodeSorter.hpp:200
void sort(StylesheetExecutionContext &executionContext, MutableNodeRefList &theList)
Given a list of nodes, sort each node according to the criteria in the keys.
Simple data structure class for use by the NodeSorter class.
Definition: NodeSortKey.hpp:49
XalanVector< XObjectVectorType > XObjectCacheType
Definition: NodeSorter.hpp:199
result_type operator()(first_argument_type theLHS, second_argument_type theRHS, XalanSize_t theKeyIndex=0) const
Compare two nodes as a less predicate.
Definition: NodeSorter.hpp:162
#define XALAN_USES_MEMORY_MANAGER(Type)
#define XALAN_XSLT_EXPORT
VectorEntry(XalanNode *theNode=0, XalanSize_t thePosition=0)
Definition: NodeSorter.hpp:70
XalanVector< NumberVectorType > NumberCacheType
Definition: NodeSorter.hpp:198
NumberVectorTypeDecl NumberVectorType
Definition: NodeSorter.hpp:194
NodeSortKeyCompare(StylesheetExecutionContext &executionContext, NodeSorter &theSorter, const NodeVectorType &theNodes, const NodeSortKeyVectorType &theNodeSortKeys)
Construct a NodeSortKeyCompare object, to perform the sort.
Definition: NodeSorter.hpp:126
NodeSortKeyVectorType & getSortKeys()
Definition: NodeSorter.hpp:91
This class can sort vectors of nodes according to a select pattern.
Definition: NodeSorter.hpp:62
XalanVector< double > NumberVectorTypeDecl
Definition: NodeSorter.hpp:49
XalanVector< VectorEntry > NodeVectorType
Definition: NodeSorter.hpp:82

Interpreting class diagrams

Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.

Xalan-C++ XSLT Processor Version 1.11
Copyright © 1999-2012 The Apache Software Foundation.
All Rights Reserved.

Apache Logo