source: trunk/src/xmlpatterns/environment/qstackcontextbase.cpp@ 497

Last change on this file since 497 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 5.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42/**
43 * @file
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.
46 */
47
48template<typename TSuperClass>
49StackContextBase<TSuperClass>::StackContextBase() : m_rangeVariables(10),
50 m_expressionVariables(10),
51 m_positionIterators(5),
52 m_itemCacheCells(5),
53 m_itemSequenceCacheCells(5)
54{
55 /* The m_* containers are initialized with default sizes. Estimated guesses on usage patterns. */
56}
57
58template<typename TSuperClass>
59StackContextBase<TSuperClass>::StackContextBase(const DynamicContext::Ptr &prevContext)
60 : TSuperClass(prevContext),
61 m_rangeVariables(10),
62 m_expressionVariables(10),
63 m_positionIterators(5),
64 m_itemCacheCells(5),
65 m_itemSequenceCacheCells(5)
66{
67 Q_ASSERT(prevContext);
68}
69
70template<typename TSuperClass>
71ItemCacheCell &StackContextBase<TSuperClass>::itemCacheCell(const VariableSlotID slot)
72{
73 if(slot >= m_itemCacheCells.size())
74 m_itemCacheCells.resize(qMax(slot + 1, m_itemCacheCells.size()));
75
76 return m_itemCacheCells[slot];
77}
78
79template<typename TSuperClass>
80ItemSequenceCacheCell::Vector &StackContextBase<TSuperClass>::itemSequenceCacheCells(const VariableSlotID slot)
81{
82 if(slot >= m_itemSequenceCacheCells.size())
83 m_itemSequenceCacheCells.resize(qMax(slot + 1, m_itemSequenceCacheCells.size()));
84
85 return m_itemSequenceCacheCells;
86}
87
88template<typename TSuperClass>
89Item StackContextBase<TSuperClass>::rangeVariable(const VariableSlotID slot) const
90{
91 Q_ASSERT(slot < m_rangeVariables.size());
92 Q_ASSERT(m_rangeVariables.at(slot));
93 return m_rangeVariables.at(slot);
94}
95
96template<typename TSuperClass>
97Expression::Ptr StackContextBase<TSuperClass>::expressionVariable(const VariableSlotID slot) const
98{
99 Q_ASSERT(slot < m_expressionVariables.size());
100 Q_ASSERT(m_expressionVariables.at(slot));
101 return m_expressionVariables.at(slot);
102}
103
104template<typename TSuperClass>
105Item::Iterator::Ptr StackContextBase<TSuperClass>::positionIterator(const VariableSlotID slot) const
106{
107 Q_ASSERT(slot < m_positionIterators.size());
108 return m_positionIterators.at(slot);
109}
110
111template<typename TSuperClass>
112template<typename VectorType, typename UnitType>
113inline
114void StackContextBase<TSuperClass>::setSlotVariable(const VariableSlotID slot,
115 const UnitType &newValue,
116 VectorType &container) const
117{
118 if(slot < container.size())
119 container.replace(slot, newValue);
120 else
121 {
122 container.resize(slot + 1);
123 container.replace(slot, newValue);
124 }
125}
126
127template<typename TSuperClass>
128void StackContextBase<TSuperClass>::setRangeVariable(const VariableSlotID slot,
129 const Item &newValue)
130{
131 setSlotVariable(slot, newValue, m_rangeVariables);
132}
133
134template<typename TSuperClass>
135void StackContextBase<TSuperClass>::setExpressionVariable(const VariableSlotID slot,
136 const Expression::Ptr &newValue)
137{
138 setSlotVariable(slot, newValue, m_expressionVariables);
139}
140
141template<typename TSuperClass>
142void StackContextBase<TSuperClass>::setPositionIterator(const VariableSlotID slot,
143 const Item::Iterator::Ptr &newValue)
144{
145 setSlotVariable(slot, newValue, m_positionIterators);
146}
147
148template<typename TSuperClass>
149DynamicContext::TemplateParameterHash &StackContextBase<TSuperClass>::templateParameterStore()
150{
151 return m_templateParameterStore;
152}
153
Note: See TracBrowser for help on using the repository browser.