00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one 00003 * or more contributor license agreements. See the NOTICE file 00004 * distributed with this work for additional information 00005 * regarding copyright ownership. The ASF licenses this file 00006 * to you under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 #if !defined(XALAN_NODESORTER_HEADER_GUARD) 00019 #define XALAN_NODESORTER_HEADER_GUARD 00020 00021 // Base include file. Must be first. 00022 #include "XSLTDefinitions.hpp" 00023 00024 00025 00026 #include <functional> 00027 00028 00029 00030 #include <xalanc/Include/XalanVector.hpp> 00031 00032 00033 00034 #include <xalanc/XPath/XObject.hpp> 00035 00036 00037 00038 #include <xalanc/XSLT/NodeSortKey.hpp> 00039 00040 00041 00042 XALAN_CPP_NAMESPACE_BEGIN 00043 00044 00045 00046 class MutableNodeRefList; 00047 class StylesheetExecutionContext; 00048 class XalanNode; 00049 class XPath; 00050 00051 00052 typedef XalanVector<double> NumberVectorTypeDecl; 00053 XALAN_USES_MEMORY_MANAGER(NumberVectorTypeDecl) 00054 00055 typedef XalanVector<XalanDOMString> StringVectorTypeDecl; 00056 XALAN_USES_MEMORY_MANAGER(StringVectorTypeDecl) 00057 00058 00059 /** 00060 * This class can sort vectors of nodes according to a select pattern. 00061 */ 00062 class XALAN_XSLT_EXPORT NodeSorter 00063 { 00064 public: 00065 00066 struct XALAN_XSLT_EXPORT VectorEntry 00067 { 00068 public: 00069 00070 VectorEntry( 00071 XalanNode* theNode = 0, 00072 XalanSize_t thePosition = 0) : 00073 m_node(theNode), 00074 m_position(thePosition) 00075 { 00076 } 00077 00078 XalanNode* m_node; 00079 XalanSize_t m_position; 00080 }; 00081 00082 typedef XalanVector<VectorEntry> NodeVectorType; 00083 typedef XalanVector<NodeSortKey> NodeSortKeyVectorType; 00084 00085 explicit 00086 NodeSorter(MemoryManager& theManager); 00087 00088 ~NodeSorter(); 00089 00090 NodeSortKeyVectorType& 00091 getSortKeys() 00092 { 00093 return m_keys; 00094 } 00095 00096 /** 00097 * Given a list of nodes, sort each node according to the criteria in the 00098 * keys. The list is assumed to be in document order. 00099 * 00100 * @param executionContext current execution context 00101 * @param v list of Nodes 00102 */ 00103 void 00104 sort( 00105 StylesheetExecutionContext& executionContext, 00106 MutableNodeRefList& theList); 00107 00108 /** 00109 * Return the results of a compare of two nodes. 00110 */ 00111 #if defined(XALAN_NO_STD_NAMESPACE) 00112 struct XALAN_XSLT_EXPORT NodeSortKeyCompare : public binary_function<const NodeVectorType::value_type&, const NodeVectorType::value_type&, bool> 00113 #else 00114 struct XALAN_XSLT_EXPORT NodeSortKeyCompare : public std::binary_function<const NodeVectorType::value_type&, const NodeVectorType::value_type&, bool> 00115 #endif 00116 { 00117 public: 00118 00119 /** 00120 * Construct a NodeSortKeyCompare object, to perform the sort 00121 * 00122 * @param executionContext current execution context 00123 * @param theNodes vector or nodes to be sorted 00124 * @param theNodeSortKeys vector of keys upon which to sort 00125 */ 00126 NodeSortKeyCompare( 00127 StylesheetExecutionContext& executionContext, 00128 NodeSorter& theSorter, 00129 const NodeVectorType& theNodes, 00130 const NodeSortKeyVectorType& theNodeSortKeys) : 00131 m_executionContext(executionContext), 00132 m_sorter(theSorter), 00133 m_nodes(theNodes), 00134 m_nodeSortKeys(theNodeSortKeys) 00135 { 00136 } 00137 00138 /** 00139 * Compare two nodes, returning a value to indicate the 00140 * result 00141 * 00142 * @param theLHS the first node to compare 00143 * @param theRHS the second node to compare 00144 * @param theKeyIndex the index of the key to use 00145 * @result < 0 if theLHS is less than theRHS, 0 if they are equal, and > 0 if theLHS is greater than theRHS 00146 */ 00147 int 00148 compare( 00149 first_argument_type theLHS, 00150 second_argument_type theRHS, 00151 XalanSize_t theKeyIndex = 0) const; 00152 00153 /** 00154 * Compare two nodes as a less predicate. 00155 * 00156 * @param theLHS the first node to compare 00157 * @param theRHS the second node to compare 00158 * @param theKeyIndex the index of the key to use 00159 * @return true if theLHS is less than theRHS 00160 */ 00161 result_type 00162 operator()( 00163 first_argument_type theLHS, 00164 second_argument_type theRHS, 00165 XalanSize_t theKeyIndex = 0) const 00166 { 00167 return compare(theLHS, theRHS, theKeyIndex) < 0 ? true : false; 00168 } 00169 00170 protected: 00171 00172 double 00173 getNumberResult( 00174 const NodeSortKey& theKey, 00175 XalanSize_t theKeyIndex, 00176 first_argument_type theEntry) const; 00177 00178 const XalanDOMString& 00179 getStringResult( 00180 const NodeSortKey& theKey, 00181 XalanSize_t theKeyIndex, 00182 first_argument_type theEntry) const; 00183 00184 private: 00185 00186 StylesheetExecutionContext& m_executionContext; 00187 NodeSorter& m_sorter; 00188 const NodeVectorType& m_nodes; 00189 const NodeSortKeyVectorType& m_nodeSortKeys; 00190 }; 00191 00192 friend struct NodeSortKeyCompare; 00193 00194 typedef NumberVectorTypeDecl NumberVectorType; 00195 typedef XalanVector<XObjectPtr> XObjectVectorType; 00196 typedef StringVectorTypeDecl StringVectorType; 00197 00198 typedef XalanVector<NumberVectorType> NumberCacheType; 00199 typedef XalanVector<XObjectVectorType> XObjectCacheType; 00200 typedef XalanVector<StringVectorType> StringCacheType; 00201 00202 typedef NumberCacheType NumberResultsCacheType; 00203 00204 #if defined(XALAN_NODESORTER_CACHE_XOBJECTS) 00205 typedef XObjectCacheType StringResultsCacheType; 00206 #else 00207 typedef StringCacheType StringResultsCacheType; 00208 #endif 00209 00210 private: 00211 00212 /** 00213 * Given a vector of nodes, sort each node according to the criteria in the 00214 * keys. 00215 * 00216 * @param executionContext current execution context 00217 */ 00218 void 00219 sort(StylesheetExecutionContext& executionContext); 00220 00221 // Data members... 00222 NumberResultsCacheType m_numberResultsCache; 00223 00224 StringResultsCacheType m_stringResultsCache; 00225 00226 NodeSortKeyVectorType m_keys; 00227 00228 NodeVectorType m_scratchVector; 00229 }; 00230 00231 00232 00233 XALAN_CPP_NAMESPACE_END 00234 00235 00236 00237 #endif // XALAN_NODESORTER_HEADER_GUARD
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
Xalan-C++ XSLT Processor Version 1.11 |
|