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_COUNTERSTABLE_HEADER_GUARD_1357924680) 00019 #define XALAN_COUNTERSTABLE_HEADER_GUARD_1357924680 00020 00021 00022 00023 // Base include file. Must be first. 00024 #include <xalanc/XSLT/XSLTDefinitions.hpp> 00025 00026 00027 00028 #include <xalanc/Include/XalanVector.hpp> 00029 00030 00031 00032 00033 #include "xalanc/XPath/MutableNodeRefList.hpp" 00034 00035 00036 00037 XALAN_CPP_NAMESPACE_BEGIN 00038 00039 00040 00041 class ElemNumber; 00042 class StylesheetExecutionContext; 00043 00044 00045 00046 /** 00047 * <meta name="usage" content="internal"/> 00048 * A class that does incremental counting for support of xsl:number. 00049 * This class stores a cache of counted nodes (m_countNodes). 00050 * It tries to cache the counted nodes in document order... 00051 * the node count is based on its position in the cache list 00052 */ 00053 struct Counter 00054 { 00055 typedef XalanSize_t CountType; 00056 00057 typedef XalanVector<XalanNode*> NodeVectorType; 00058 00059 /** 00060 * The start count from where m_countNodes counts 00061 * from. In other words, the count of a given node 00062 * in the m_countNodes vector is node position + 00063 * m_countNodesStartCount. 00064 */ 00065 CountType m_countNodesStartCount; 00066 00067 /** 00068 * A vector of all nodes counted so far. 00069 */ 00070 NodeVectorType m_countNodes; 00071 00072 /** 00073 * The node from where the counting starts. This is needed to 00074 * find a counter if the node being counted is not immediatly 00075 * found in the m_countNodes vector. 00076 */ 00077 const XalanNode* m_fromNode; 00078 00079 /** 00080 * The owning xsl:number element. 00081 */ 00082 const ElemNumber* m_numberElem; 00083 00084 /** 00085 * Construct a counter object. 00086 */ 00087 Counter( 00088 MemoryManager& theManager, 00089 const ElemNumber* numberElem, 00090 NodeVectorType& countNodes) : 00091 m_countNodesStartCount(0), 00092 m_countNodes(countNodes, theManager), 00093 m_fromNode(0), 00094 m_numberElem(numberElem) 00095 { 00096 } 00097 00098 /** 00099 * Construct a counter object. 00100 */ 00101 Counter(MemoryManager& theManager, const ElemNumber* numberElem = 0) : 00102 m_countNodesStartCount(0), 00103 m_countNodes(theManager), 00104 m_fromNode(0), 00105 m_numberElem(numberElem) 00106 { 00107 } 00108 00109 Counter(const Counter& other, MemoryManager& theManager) : 00110 m_countNodesStartCount(other.m_countNodesStartCount), 00111 m_countNodes(other.m_countNodes, theManager), 00112 m_fromNode(other.m_fromNode), 00113 m_numberElem(other.m_numberElem) 00114 { 00115 } 00116 00117 /** 00118 * Try to find a node that was previously counted. If found, return a 00119 * positive integer that corresponds to the count. 00120 * @param node The node to be counted. 00121 * @returns The count of the node, or 0 if not found. 00122 */ 00123 CountType 00124 getPreviouslyCounted( 00125 StylesheetExecutionContext& support, 00126 const XalanNode* node) const; 00127 00128 /** 00129 * Get the last node in the list. 00130 */ 00131 XalanNode* 00132 getLast() const 00133 { 00134 return m_countNodes.empty() == true ? 0 : m_countNodes.back(); 00135 } 00136 00137 private: 00138 // Not implemented 00139 Counter(); 00140 Counter(const Counter&); 00141 }; 00142 00143 XALAN_USES_MEMORY_MANAGER(Counter) 00144 00145 typedef XalanVector<Counter> CounterVectorTypeDecl; 00146 XALAN_USES_MEMORY_MANAGER(CounterVectorTypeDecl) 00147 00148 typedef XalanVector<CounterVectorTypeDecl> ElemCounterVectorVectorTypeDecl; 00149 XALAN_USES_MEMORY_MANAGER(ElemCounterVectorVectorTypeDecl) 00150 /** 00151 * <meta name="usage" content="internal"/> 00152 * This is a table of counters, keyed by ElemNumber objects, each 00153 * of which has a list of Counter objects. This really isn't a true 00154 * table, it is more like a list of lists (there must be a technical 00155 * term for that...). 00156 */ 00157 class CountersTable 00158 { 00159 public: 00160 00161 typedef Counter::CountType CountType; 00162 00163 typedef CounterVectorTypeDecl CounterVectorType; 00164 typedef ElemCounterVectorVectorTypeDecl ElemCounterVectorVectorType; 00165 00166 typedef Counter::NodeVectorType NodeVectorType; 00167 00168 /** 00169 * Construct a CountersTable. 00170 */ 00171 CountersTable(MemoryManager& theManager, 00172 unsigned long theSize = 0) : 00173 m_countersVector(theManager), 00174 m_newFound(theManager) 00175 { 00176 resize(theSize); 00177 }; 00178 00179 ~CountersTable() 00180 { 00181 } 00182 00183 /** 00184 * Resize the table. The must be done prior 00185 * to using the table, if the size was not past 00186 * in the constructor. 00187 * 00188 * @theSize The new size 00189 */ 00190 void 00191 resize(unsigned long theSize) 00192 { 00193 m_countersVector.resize(theSize); 00194 } 00195 00196 /** 00197 * Count forward until the given node is found, or until 00198 * we have looked to the given amount. 00199 * 00200 * @executionContext The current execution context; 00201 * @numberElem The executing ElemNumber 00202 * @node The node to count. 00203 * @return The node count, or 0 if not found. 00204 */ 00205 CountType 00206 countNode( 00207 StylesheetExecutionContext& executionContext, 00208 const ElemNumber& numberElem, 00209 XalanNode* node); 00210 00211 /** 00212 * Clear all cached data from the table. 00213 */ 00214 void 00215 reset() 00216 { 00217 m_newFound.clear(); 00218 00219 m_countersVector.clear(); 00220 } 00221 00222 private: 00223 // not implemented 00224 CountersTable(); 00225 CountersTable(const CountersTable&); 00226 00227 /** 00228 * A vector which holds counters for ElemNumber instances. 00229 */ 00230 ElemCounterVectorVectorType m_countersVector; 00231 00232 00233 /** 00234 * A vector to use as a temporary buffer. 00235 */ 00236 NodeVectorType m_newFound; 00237 }; 00238 00239 00240 00241 XALAN_CPP_NAMESPACE_END 00242 00243 00244 00245 #endif // !defined(XALAN_COUNTERSTABLE_HEADER_GUARD_1357924680)
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
Xalan-C++ XSLT Processor Version 1.11 |
|