Doxygen
qhpxmlwriter.cpp
浏览该文件的文档.
1 /*
2  * Copyright (C) 2008 by Sebastian Pipping.
3  * Copyright (C) 2008 Dimitri van Heesch.
4  *
5  * Permission to use, copy, modify, and distribute this software and its
6  * documentation under the terms of the GNU General Public License is hereby
7  * granted. No representations are made about the suitability of this software
8  * for any purpose. It is provided "as is" without express or implied warranty.
9  * See the GNU General Public License for more details.
10  *
11  * Documents produced by Doxygen are derivative works derived from the
12  * input used in their production; they are not affected by this license.
13  *
14  * Sebastian Pipping <sebastian@pipping.org>
15  */
16 
17 #include "qhpxmlwriter.h"
18 #include "util.h"
19 #include "qcstring.h"
20 
22  : m_indentLevel(0), m_curLineIndented(false), m_compress(false)
23 {
24 }
25 
27 {
28 }
29 
31 {
32  m_indentLevel = level;
33 }
34 
36 {
37  m_compress = enabled;
38 }
39 
40 void QhpXmlWriter::insert(QhpXmlWriter const & source)
41 {
42  m_backend << source.m_backend.str();
43 }
44 
46 {
47  file << m_backend.str();
48 }
49 
50 void QhpXmlWriter::open(const QCString &elementName,
51  const char * const attributes[])
52 {
53  indent();
54  openPure(elementName, attributes);
55  newLine();
56  m_indentLevel++;
57 }
58 
59 void QhpXmlWriter::openClose(const QCString &elementName,
60  const char * const attributes[])
61 {
62  indent();
63  openClosePure(elementName, attributes);
64  newLine();
65 }
66 
67 void QhpXmlWriter::openCloseContent(const QCString &elementName,
68  const QCString &content)
69 {
70  indent();
71  openPure(elementName);
72  m_backend << convertToXML(content);
73  closePure(elementName);
74  newLine();
75 }
76 
77 void QhpXmlWriter::close(const QCString &elementName)
78 {
79  m_indentLevel--;
80  indent();
81  closePure(elementName);
82  newLine();
83 }
84 
85 void QhpXmlWriter::declaration(const QCString &version, const QCString &encoding)
86 {
87  m_backend << "<?xml version=\"" << version << "\" encoding=\"" << encoding << "\"?>";
88  newLine();
89 }
90 
92 {
94  {
95  return;
96  }
97  for (int i = 0; i < m_indentLevel; i++)
98  {
99  m_backend << " ";
100  }
101  m_curLineIndented = true;
102 }
103 
105 {
106  if (!m_compress)
107  {
108  m_backend << "\n";
109  m_curLineIndented = false;
110  }
111 }
112 
113 void QhpXmlWriter::openPureHelper(const QCString &elementName,
114  const char * const attributes[], bool close)
115 {
116  m_backend << "<" << elementName;
117  if (attributes)
118  {
119  for (const char * const * walker = attributes;
120  walker[0]; walker += 2)
121  {
122  const char *const key = walker[0];
123  const char *const value = walker[1];
124  if (!value)
125  {
126  continue;
127  }
128  m_backend << " " << key << "=\"" << convertToXML(value) << "\"";
129  }
130  }
131 
132  if (close)
133  {
134  m_backend << " /";
135  }
136  m_backend << ">";
137 }
138 
139 void QhpXmlWriter::openPure(const QCString &elementName,
140  const char * const attributes[])
141 {
142  openPureHelper(elementName, attributes, false);
143 }
144 
145 void QhpXmlWriter::openClosePure(const QCString &elementName,
146  const char * const attributes[])
147 {
148  openPureHelper(elementName, attributes, true);
149 }
150 
151 void QhpXmlWriter::closePure(const QCString &elementName)
152 {
153  m_backend << "</" << elementName << ">";
154 }
155 
qhpxmlwriter.h
QhpXmlWriter::declaration
void declaration(const QCString &version, const QCString &encoding)
Definition: qhpxmlwriter.cpp:85
QhpXmlWriter::openPure
void openPure(const QCString &elementName, const char *const attributes[]=0)
Definition: qhpxmlwriter.cpp:139
QhpXmlWriter::setIndentLevel
void setIndentLevel(int level)
Definition: qhpxmlwriter.cpp:30
QhpXmlWriter::dumpTo
void dumpTo(TextStream &file)
Definition: qhpxmlwriter.cpp:45
TextStream
Text streaming class that buffers data.
Definition: textstream.h:33
qcstring.h
QhpXmlWriter::openClosePure
void openClosePure(const QCString &elementName, const char *const attributes[]=0)
Definition: qhpxmlwriter.cpp:145
QhpXmlWriter::QhpXmlWriter
QhpXmlWriter()
Definition: qhpxmlwriter.cpp:21
version
static void version(const bool extended)
Definition: doxygen.cpp:10515
QhpXmlWriter::m_compress
bool m_compress
Definition: qhpxmlwriter.h:55
QhpXmlWriter::close
void close(const QCString &elementName)
Definition: qhpxmlwriter.cpp:77
QhpXmlWriter::open
void open(const QCString &elementName, const char *const attributes[]=0)
Definition: qhpxmlwriter.cpp:50
QhpXmlWriter::openPureHelper
void openPureHelper(const QCString &elementName, const char *const attributes[], bool close)
Definition: qhpxmlwriter.cpp:113
QhpXmlWriter::closePure
void closePure(const QCString &elementName)
Definition: qhpxmlwriter.cpp:151
QhpXmlWriter::indent
void indent()
Definition: qhpxmlwriter.cpp:91
QhpXmlWriter::insert
void insert(QhpXmlWriter const &source)
Definition: qhpxmlwriter.cpp:40
QhpXmlWriter::m_curLineIndented
bool m_curLineIndented
Definition: qhpxmlwriter.h:54
TextStream::str
std::string str() const
Return the contents of the buffer as a std::string object
Definition: textstream.h:208
QhpXmlWriter::m_indentLevel
int m_indentLevel
Definition: qhpxmlwriter.h:53
QhpXmlWriter::setCompressionEnabled
void setCompressionEnabled(bool enabled)
Definition: qhpxmlwriter.cpp:35
QhpXmlWriter::newLine
void newLine()
Definition: qhpxmlwriter.cpp:104
QhpXmlWriter::openClose
void openClose(const QCString &elementName, const char *const attributes[]=0)
Definition: qhpxmlwriter.cpp:59
QhpXmlWriter::m_backend
TextStream m_backend
Definition: qhpxmlwriter.h:52
QhpXmlWriter::openCloseContent
void openCloseContent(const QCString &elementName, const QCString &content)
Definition: qhpxmlwriter.cpp:67
QhpXmlWriter::~QhpXmlWriter
~QhpXmlWriter()
Definition: qhpxmlwriter.cpp:26
QhpXmlWriter
Definition: qhpxmlwriter.h:23
convertToXML
QCString convertToXML(const QCString &s, bool keepEntities)
Definition: util.cpp:3948
util.h
A bunch of utility functions.
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108