1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40//
41// W A R N I N G
42// -------------
43//
44// This file is not part of the Qt API. It exists purely as an
45// implementation detail. This header file may change from version to
46// version without notice, or even be removed.
47//
48// We mean it.
49//
50
51/**
52 * @file
53 * @short This file is included by qstackcontextbase_p.h.
54 * If you need includes in this file, put them in qstackcontextbase_p.h, outside of the namespace.
55 */
56
57template<typename TSuperClass>
58StackContextBase<TSuperClass>::StackContextBase() : m_rangeVariables(10),
59 m_expressionVariables(10),
60 m_positionIterators(5),
61 m_itemCacheCells(5),
62 m_itemSequenceCacheCells(5)
63{
64 /* The m_* containers are initialized with default sizes. Estimated guesses on usage patterns. */
65}
66
67template<typename TSuperClass>
68StackContextBase<TSuperClass>::StackContextBase(const DynamicContext::Ptr &prevContext)
69 : TSuperClass(prevContext),
70 m_rangeVariables(10),
71 m_expressionVariables(10),
72 m_positionIterators(5),
73 m_itemCacheCells(5),
74 m_itemSequenceCacheCells(5)
75{
76 Q_ASSERT(prevContext);
77}
78
79template<typename TSuperClass>
80ItemCacheCell &StackContextBase<TSuperClass>::itemCacheCell(const VariableSlotID slot)
81{
82 if(slot >= m_itemCacheCells.size())
83 m_itemCacheCells.resize(size: qMax(a: slot + 1, b: m_itemCacheCells.size()));
84
85 return m_itemCacheCells[slot];
86}
87
88template<typename TSuperClass>
89ItemSequenceCacheCell::Vector &StackContextBase<TSuperClass>::itemSequenceCacheCells(const VariableSlotID slot)
90{
91 if(slot >= m_itemSequenceCacheCells.size())
92 m_itemSequenceCacheCells.resize(size: qMax(a: slot + 1, b: m_itemSequenceCacheCells.size()));
93
94 return m_itemSequenceCacheCells;
95}
96
97template<typename TSuperClass>
98Item StackContextBase<TSuperClass>::rangeVariable(const VariableSlotID slot) const
99{
100 Q_ASSERT(slot < m_rangeVariables.size());
101 Q_ASSERT(m_rangeVariables.at(slot));
102 return m_rangeVariables.at(i: slot);
103}
104
105template<typename TSuperClass>
106Expression::Ptr StackContextBase<TSuperClass>::expressionVariable(const VariableSlotID slot) const
107{
108 Q_ASSERT(slot < m_expressionVariables.size());
109 Q_ASSERT(m_expressionVariables.at(slot));
110 return m_expressionVariables.at(i: slot);
111}
112
113template<typename TSuperClass>
114Item::Iterator::Ptr StackContextBase<TSuperClass>::positionIterator(const VariableSlotID slot) const
115{
116 Q_ASSERT(slot < m_positionIterators.size());
117 return m_positionIterators.at(i: slot);
118}
119
120template<typename TSuperClass>
121template<typename VectorType, typename UnitType>
122inline
123void StackContextBase<TSuperClass>::setSlotVariable(const VariableSlotID slot,
124 const UnitType &newValue,
125 VectorType &container) const
126{
127 if(slot < container.size())
128 container.replace(slot, newValue);
129 else
130 {
131 container.resize(slot + 1);
132 container.replace(slot, newValue);
133 }
134}
135
136template<typename TSuperClass>
137void StackContextBase<TSuperClass>::setRangeVariable(const VariableSlotID slot,
138 const Item &newValue)
139{
140 setSlotVariable(slot, newValue, m_rangeVariables);
141}
142
143template<typename TSuperClass>
144void StackContextBase<TSuperClass>::setExpressionVariable(const VariableSlotID slot,
145 const Expression::Ptr &newValue)
146{
147 setSlotVariable(slot, newValue, m_expressionVariables);
148}
149
150template<typename TSuperClass>
151void StackContextBase<TSuperClass>::setPositionIterator(const VariableSlotID slot,
152 const Item::Iterator::Ptr &newValue)
153{
154 setSlotVariable(slot, newValue, m_positionIterators);
155}
156
157template<typename TSuperClass>
158DynamicContext::TemplateParameterHash &StackContextBase<TSuperClass>::templateParameterStore()
159{
160 return m_templateParameterStore;
161}
162
163

source code of qtxmlpatterns/src/xmlpatterns/environment/qstackcontextbase_tpl_p.h