1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
44 * @short This file is included by qstackcontextbase_p.h.
45 * If you need includes in this file, put them in qstackcontextbase_p.h, outside of the namespace.
48 template<typename TSuperClass>
49 StackContextBase<TSuperClass>::StackContextBase() : m_rangeVariables(10),
50 m_expressionVariables(10),
51 m_positionIterators(5),
53 m_itemSequenceCacheCells(5)
55 /* The m_* containers are initialized with default sizes. Estimated guesses on usage patterns. */
58 template<typename TSuperClass>
59 StackContextBase<TSuperClass>::StackContextBase(const DynamicContext::Ptr &prevContext)
60 : TSuperClass(prevContext),
62 m_expressionVariables(10),
63 m_positionIterators(5),
65 m_itemSequenceCacheCells(5)
67 Q_ASSERT(prevContext);
70 template<typename TSuperClass>
71 ItemCacheCell &StackContextBase<TSuperClass>::itemCacheCell(const VariableSlotID slot)
73 if(slot >= m_itemCacheCells.size())
74 m_itemCacheCells.resize(qMax(slot + 1, m_itemCacheCells.size()));
76 return m_itemCacheCells[slot];
79 template<typename TSuperClass>
80 ItemSequenceCacheCell::Vector &StackContextBase<TSuperClass>::itemSequenceCacheCells(const VariableSlotID slot)
82 if(slot >= m_itemSequenceCacheCells.size())
83 m_itemSequenceCacheCells.resize(qMax(slot + 1, m_itemSequenceCacheCells.size()));
85 return m_itemSequenceCacheCells;
88 template<typename TSuperClass>
89 Item StackContextBase<TSuperClass>::rangeVariable(const VariableSlotID slot) const
91 Q_ASSERT(slot < m_rangeVariables.size());
92 Q_ASSERT(m_rangeVariables.at(slot));
93 return m_rangeVariables.at(slot);
96 template<typename TSuperClass>
97 Expression::Ptr StackContextBase<TSuperClass>::expressionVariable(const VariableSlotID slot) const
99 Q_ASSERT(slot < m_expressionVariables.size());
100 Q_ASSERT(m_expressionVariables.at(slot));
101 return m_expressionVariables.at(slot);
104 template<typename TSuperClass>
105 Item::Iterator::Ptr StackContextBase<TSuperClass>::positionIterator(const VariableSlotID slot) const
107 Q_ASSERT(slot < m_positionIterators.size());
108 return m_positionIterators.at(slot);
111 template<typename TSuperClass>
112 template<typename VectorType, typename UnitType>
114 void StackContextBase<TSuperClass>::setSlotVariable(const VariableSlotID slot,
115 const UnitType &newValue,
116 VectorType &container) const
118 if(slot < container.size())
119 container.replace(slot, newValue);
122 container.resize(slot + 1);
123 container.replace(slot, newValue);
127 template<typename TSuperClass>
128 void StackContextBase<TSuperClass>::setRangeVariable(const VariableSlotID slot,
129 const Item &newValue)
131 setSlotVariable(slot, newValue, m_rangeVariables);
134 template<typename TSuperClass>
135 void StackContextBase<TSuperClass>::setExpressionVariable(const VariableSlotID slot,
136 const Expression::Ptr &newValue)
138 setSlotVariable(slot, newValue, m_expressionVariables);
141 template<typename TSuperClass>
142 void StackContextBase<TSuperClass>::setPositionIterator(const VariableSlotID slot,
143 const Item::Iterator::Ptr &newValue)
145 setSlotVariable(slot, newValue, m_positionIterators);
148 template<typename TSuperClass>
149 DynamicContext::TemplateParameterHash &StackContextBase<TSuperClass>::templateParameterStore()
151 return m_templateParameterStore;