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
19 // Class header file...
20 #include "OutputContextStack.hpp"
21
22
23
24 #include <xalanc/PlatformSupport/DOMStringHelper.hpp>
25
26
27 namespace XALAN_CPP_NAMESPACE {
28
29
30
OutputContextStack(MemoryManager & theManager)31 OutputContextStack::OutputContextStack(MemoryManager& theManager) :
32 m_stack(theManager, 1 ),
33 m_stackPosition(m_stack.begin()),
34 m_stackSize(0)
35 {
36 // m_stack is initialized to a size of 1, so that
37 // we always have a dummy entry at the beginning
38 // of the deque. This makes the implementation
39 // much simpler.
40 }
41
42
43
~OutputContextStack()44 OutputContextStack::~OutputContextStack()
45 {
46 }
47
48
49
50 void
pushContext(FormatterListener * theListener)51 OutputContextStack::pushContext(FormatterListener* theListener)
52 {
53 ++m_stackPosition;
54 ++m_stackSize;
55
56 if (m_stackPosition == m_stack.end())
57 {
58 m_stack.resize(m_stack.size() + 1);
59
60 m_stackPosition = m_stack.end() - 1;
61 }
62
63 if (theListener != 0)
64 {
65 (*m_stackPosition).m_flistener = theListener;
66 }
67 }
68
69
70
71 void
popContext()72 OutputContextStack::popContext()
73 {
74 assert(m_stackPosition != m_stack.begin());
75
76 OutputContext& theCurrentContext = *m_stackPosition;
77
78 theCurrentContext.reset();
79
80
81 --m_stackPosition;
82 --m_stackSize;
83 }
84
85
86
87 void
clear()88 OutputContextStack::clear()
89 {
90 // Since we always keep one dummy entry at the beginning,
91 // swap with an OutputContextStackType instance of size 1.
92 OutputContextStackType temp( XalanMemMgrs::getDummyMemMgr(), 1);
93 temp.swap(m_stack);
94
95 m_stackPosition = m_stack.begin();
96
97 m_stackSize = 0;
98 }
99
100
101
102 void
reset()103 OutputContextStack::reset()
104 {
105 while(m_stackPosition != m_stack.begin())
106 {
107 popContext();
108 }
109
110 assert(empty() == true);
111 }
112
113
114
115 }
116