Xalan-C++ API Reference 1.12.0
XalanIndentWriter.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(XALANIDENTWRITER_HEADER_GUARD_1357924680)
19#define XALANIDENTWRITER_HEADER_GUARD_1357924680
20
21
22// Base include file. Must be first.
24
26
29
30
31namespace XALAN_CPP_NAMESPACE {
32
33
34template<
35 class WhiteSpaceWriter,
36 class NewLineWriter>
38{
39public:
40
43 typedef typename WhiteSpaceWriter::writer_type writer_type;
44
48 m_whiteSpaceWriter(writer),
49 m_newLineWriter(writer),
50 m_indent(ident),
51 m_currentIndent(0),
52 m_startNewLine(false),
53 m_ispreserve(false),
54 m_isprevtext(false),
55 m_preserves(writer.getMemoryManager(), 5)
56 {
57 assert( m_indent != -1);
58 }
59
61 {
62 }
63
64
65 void
67 {
68 m_indent = value;
69 }
70
72 getIndent()const
73 {
74 return m_indent;
75 }
76
77 void
79 {
80 if( shouldIndent() )
81 {
82 if(m_startNewLine == true)
83 {
84 m_newLineWriter();
85 }
86
87 m_whiteSpaceWriter(m_currentIndent);
88
89 }
90 }
91
92 void
94 {
95 m_currentIndent += m_indent;
96 }
97
98 void
100 {
101 assert( m_currentIndent >= m_indent);
102
103 m_currentIndent -= m_indent;
104 }
105
106 void
107 setStartNewLine(bool value)
108 {
109 m_startNewLine = value;
110 }
111
112 /**
113 * Output a line break.
114 */
115 void
117 {
118 m_newLineWriter();
119 }
120
121 void
122 setPrevText(bool value)
123 {
124 m_isprevtext = value;
125 }
126
127 void
128 setPreserve(bool value)
129 {
130 m_ispreserve = value;
131 }
132
133 void
135 {
136 if ( m_preserves.empty() )
137 {
138 m_ispreserve = false;
139 }
140 else
141 {
142 m_ispreserve = m_preserves.back();
143
144 m_preserves.pop_back();
145 }
146 }
147
148 void
150 {
151 m_preserves.push_back(m_ispreserve);
152 }
153
154private:
155 bool
156 shouldIndent() const
157 {
158 return (!m_ispreserve && !m_isprevtext);
159 // return true;
160 }
161
162private:
163
164 //data members
165
166 WhiteSpaceWriter m_whiteSpaceWriter;
167
168 NewLineWriter m_newLineWriter;
169
170 /**
171 * Amount to indent.
172 */
173 size_type m_indent;
174
175 /**
176 * Flag to keep track of the indent amount.
177 */
178 size_type m_currentIndent;
179
180 /**
181 * Flag to signal that a newline should be added.
182 */
183 bool m_startNewLine;
184
185 /**
186 * State flag to tell if preservation of whitespace
187 * is important.
188 */
189 bool m_ispreserve;
190
191 /**
192 * State flag that tells if the previous node processed
193 * was text, so we can tell if we should preserve whitespace.
194 */
195 bool m_isprevtext;
196
197 /**
198 * Stack to keep track of whether or not we need to
199 * preserve whitespace.
200 */
201 BoolStackType m_preserves;
202};
203
204}
205
206
207
208#endif // XALANIDENTWRITER_HEADER_GUARD_1357924680
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
XalanIndentWriter(writer_type &writer, size_type ident)
void setIndent(size_type value)
WhiteSpaceWriter::writer_type writer_type
XalanVector< bool > BoolStackType
void outputLineSep()
Output a line break.
FormatterListener::size_type size_type
size_t size_type
Definition XalanMap.hpp:46