Xalan-C++ API Reference 1.12.0
CountersTable.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_COUNTERSTABLE_HEADER_GUARD_1357924680)
19#define XALAN_COUNTERSTABLE_HEADER_GUARD_1357924680
20
21
22
23// Base include file. Must be first.
25
26
27
29
30
31
32
34
35
36
37namespace XALAN_CPP_NAMESPACE {
38
39
40
41class ElemNumber;
42class StylesheetExecutionContext;
43
44
45
46/**
47 * <meta name="usage" content="internal"/>
48 * A class that does incremental counting for support of xsl:number.
49 * This class stores a cache of counted nodes (m_countNodes).
50 * It tries to cache the counted nodes in document order...
51 * the node count is based on its position in the cache list
52 */
53struct Counter
54{
56
58
59 /**
60 * The start count from where m_countNodes counts
61 * from. In other words, the count of a given node
62 * in the m_countNodes vector is node position +
63 * m_countNodesStartCount.
64 */
66
67 /**
68 * A vector of all nodes counted so far.
69 */
71
72 /**
73 * The node from where the counting starts. This is needed to
74 * find a counter if the node being counted is not immediatly
75 * found in the m_countNodes vector.
76 */
78
79 /**
80 * The owning xsl:number element.
81 */
83
84 /**
85 * Construct a counter object.
86 */
88 MemoryManager& theManager,
91 m_countNodesStartCount(0),
92 m_countNodes(countNodes, theManager),
93 m_fromNode(0),
94 m_numberElem(numberElem)
95 {
96 }
97
98 /**
99 * Construct a counter object.
100 */
101 Counter(MemoryManager& theManager, const ElemNumber* numberElem = 0) :
102 m_countNodesStartCount(0),
103 m_countNodes(theManager),
104 m_fromNode(0),
105 m_numberElem(numberElem)
106 {
107 }
108
109 Counter(const Counter& other, MemoryManager& theManager) :
110 m_countNodesStartCount(other.m_countNodesStartCount),
111 m_countNodes(other.m_countNodes, theManager),
112 m_fromNode(other.m_fromNode),
113 m_numberElem(other.m_numberElem)
114 {
115 }
116
117 /**
118 * Try to find a node that was previously counted. If found, return a
119 * positive integer that corresponds to the count.
120 * @param node The node to be counted.
121 * @returns The count of the node, or 0 if not found.
122 */
123 CountType
126 const XalanNode* node) const;
127
128 /**
129 * Get the last node in the list.
130 */
131 XalanNode*
132 getLast() const
133 {
134 return m_countNodes.empty() == true ? 0 : m_countNodes.back();
135 }
136
137private:
138 // Not implemented
139 Counter();
140 Counter(const Counter&);
141};
142
144
147
150/**
151 * <meta name="usage" content="internal"/>
152 * This is a table of counters, keyed by ElemNumber objects, each
153 * of which has a list of Counter objects. This really isn't a true
154 * table, it is more like a list of lists (there must be a technical
155 * term for that...).
156 */
158{
159public:
160
162
165
167
168 /**
169 * Construct a CountersTable.
170 */
171 CountersTable(MemoryManager& theManager,
172 unsigned long theSize = 0) :
173 m_countersVector(theManager),
174 m_newFound(theManager)
175 {
176 resize(theSize);
177 };
178
180 {
181 }
182
183 /**
184 * Resize the table. The must be done prior
185 * to using the table, if the size was not past
186 * in the constructor.
187 *
188 * @theSize The new size
189 */
190 void
191 resize(unsigned long theSize)
192 {
193 m_countersVector.resize(theSize);
194 }
195
196 /**
197 * Count forward until the given node is found, or until
198 * we have looked to the given amount.
199 *
200 * @executionContext The current execution context;
201 * @numberElem The executing ElemNumber
202 * @node The node to count.
203 * @return The node count, or 0 if not found.
204 */
205 CountType
208 const ElemNumber& numberElem,
209 XalanNode* node);
210
211 /**
212 * Clear all cached data from the table.
213 */
214 void
216 {
217 m_newFound.clear();
218
219 m_countersVector.clear();
220 }
221
222private:
223 // not implemented
226
227 /**
228 * A vector which holds counters for ElemNumber instances.
229 */
230 ElemCounterVectorVectorType m_countersVector;
231
232
233 /**
234 * A vector to use as a temporary buffer.
235 */
236 NodeVectorType m_newFound;
237};
238
239
240
241}
242
243
244
245#endif // !defined(XALAN_COUNTERSTABLE_HEADER_GUARD_1357924680)
#define XALAN_USES_MEMORY_MANAGER(Type)
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
<meta name="usage" content="internal"> This is a table of counters, keyed by ElemNumber objects,...
CounterVectorTypeDecl CounterVectorType
void resize(unsigned long theSize)
Resize the table.
void reset()
Clear all cached data from the table.
CountType countNode(StylesheetExecutionContext &executionContext, const ElemNumber &numberElem, XalanNode *node)
Count forward until the given node is found, or until we have looked to the given amount.
ElemCounterVectorVectorTypeDecl ElemCounterVectorVectorType
Counter::NodeVectorType NodeVectorType
CountersTable(MemoryManager &theManager, unsigned long theSize=0)
Construct a CountersTable.
Counter::CountType CountType
<meta name="usage" content="internal"> A class that does incremental counting for support of xsl:numb...
const XalanNode * m_fromNode
The node from where the counting starts.
XalanNode * getLast() const
Get the last node in the list.
Counter(MemoryManager &theManager, const ElemNumber *numberElem=0)
Construct a counter object.
CountType m_countNodesStartCount
The start count from where m_countNodes counts from.
NodeVectorType m_countNodes
A vector of all nodes counted so far.
Counter(MemoryManager &theManager, const ElemNumber *numberElem, NodeVectorType &countNodes)
Construct a counter object.
XalanVector< XalanNode * > NodeVectorType
const ElemNumber * m_numberElem
The owning xsl:number element.
CountType getPreviouslyCounted(StylesheetExecutionContext &support, const XalanNode *node) const
Try to find a node that was previously counted.
Counter(const Counter &other, MemoryManager &theManager)
XalanSize_t CountType