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 
37 namespace XALAN_CPP_NAMESPACE {
38 
39 
40 
41 class ElemNumber;
42 class 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  */
53 struct Counter
54 {
55  typedef XalanSize_t CountType;
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,
89  const ElemNumber* numberElem,
90  NodeVectorType& countNodes) :
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
124  getPreviouslyCounted(
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 
137 private:
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 {
159 public:
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
206  countNode(
207  StylesheetExecutionContext& executionContext,
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 
222 private:
223  // not implemented
224  CountersTable();
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)
MutableNodeRefList.hpp
xalanc::Counter::m_fromNode
const XalanNode * m_fromNode
The node from where the counting starts.
Definition: CountersTable.hpp:77
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::XalanVector::empty
bool empty() const
Definition: XalanVector.hpp:600
xalanc::XalanVector::back
reference back()
Definition: XalanVector.hpp:637
xalanc::StylesheetExecutionContext
Definition: StylesheetExecutionContext.hpp:106
xalanc::CountersTable::CountType
Counter::CountType CountType
Definition: CountersTable.hpp:161
xalanc::XalanNode
Definition: XalanNode.hpp:38
xalanc::CountersTable::reset
void reset()
Clear all cached data from the table.
Definition: CountersTable.hpp:215
xalanc::XalanVector< XalanNode * >
XALAN_USES_MEMORY_MANAGER
#define XALAN_USES_MEMORY_MANAGER(Type)
Definition: XalanMemoryManagement.hpp:589
xalanc::Counter::m_countNodesStartCount
CountType m_countNodesStartCount
The start count from where m_countNodes counts from.
Definition: CountersTable.hpp:65
xalanc::CountersTable::resize
void resize(unsigned long theSize)
Resize the table.
Definition: CountersTable.hpp:191
xalanc::Counter::Counter
Counter(MemoryManager &theManager, const ElemNumber *numberElem, NodeVectorType &countNodes)
Construct a counter object.
Definition: CountersTable.hpp:87
xalanc::CountersTable::ElemCounterVectorVectorType
ElemCounterVectorVectorTypeDecl ElemCounterVectorVectorType
Definition: CountersTable.hpp:164
XalanVector.hpp
xalanc::Counter::m_numberElem
const ElemNumber * m_numberElem
The owning xsl:number element.
Definition: CountersTable.hpp:82
xalanc::Counter::Counter
Counter(const Counter &other, MemoryManager &theManager)
Definition: CountersTable.hpp:109
xalanc::Counter::CountType
XalanSize_t CountType
Definition: CountersTable.hpp:55
xalanc::CountersTable::CountersTable
CountersTable(MemoryManager &theManager, unsigned long theSize=0)
Construct a CountersTable.
Definition: CountersTable.hpp:171
xalanc::Counter
<meta name="usage" content="internal"> A class that does incremental counting for support of xsl:numb...
Definition: CountersTable.hpp:53
xalanc::CountersTable::~CountersTable
~CountersTable()
Definition: CountersTable.hpp:179
xalanc::Counter::Counter
Counter(MemoryManager &theManager, const ElemNumber *numberElem=0)
Construct a counter object.
Definition: CountersTable.hpp:101
xalanc::CountersTable::CounterVectorType
CounterVectorTypeDecl CounterVectorType
Definition: CountersTable.hpp:163
XSLTDefinitions.hpp
xalanc::Counter::NodeVectorType
XalanVector< XalanNode * > NodeVectorType
Definition: CountersTable.hpp:57
xalanc::CountersTable
<meta name="usage" content="internal"> This is a table of counters, keyed by ElemNumber objects,...
Definition: CountersTable.hpp:157
xalanc::Counter::getLast
XalanNode * getLast() const
Get the last node in the list.
Definition: CountersTable.hpp:132
xalanc::CountersTable::NodeVectorType
Counter::NodeVectorType NodeVectorType
Definition: CountersTable.hpp:166
xalanc::ElemNumber
Definition: ElemNumber.hpp:59
xalanc::Counter::m_countNodes
NodeVectorType m_countNodes
A vector of all nodes counted so far.
Definition: CountersTable.hpp:70