~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to qmake/generators/xmloutput.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the qmake application of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
#ifndef __XMLOUTPUT_H__
 
29
#define __XMLOUTPUT_H__
 
30
 
 
31
#include <qtextstream.h>
 
32
#include <qstack.h>
 
33
 
 
34
class XmlOutput
 
35
{
 
36
public:
 
37
    enum ConverstionType {
 
38
        NoConversion,       // No change
 
39
        EscapeConversion,   // Use '\"'
 
40
        XMLConversion       // Use &quot;
 
41
    };
 
42
    enum XMLFormat {
 
43
        NoNewLine,          // No new lines, unless added manually
 
44
        NewLine             // All properties & tags indented on new lines
 
45
    };
 
46
    enum XMLState {
 
47
        Bare,               // Not in tag or attribute
 
48
        Tag,                // <tagname attribute1="value"
 
49
        Attribute           //  attribute2="value">
 
50
    };
 
51
    enum XMLType {
 
52
        tNothing,           // No XML output, and not state change
 
53
        tRaw,               // Raw text (no formating)
 
54
        tDeclaration,       // <?xml version="x.x" encoding="xxx"?>
 
55
        tTag,               // <tagname attribute1="value"
 
56
        tCloseTag,          // Closes an open tag
 
57
        tAttribute,         //  attribute2="value">
 
58
        tData,              // Tag data (formating done)
 
59
        tComment,           // <!-- Comment -->
 
60
        tCDATA              // <![CDATA[ ... ]]>
 
61
    };
 
62
 
 
63
    XmlOutput(QTextStream &file, ConverstionType type = XMLConversion);
 
64
    ~XmlOutput();
 
65
 
 
66
    // Settings
 
67
    void setIndentString(const QString &indentString);
 
68
    QString indentString();
 
69
    void setIndentLevel(int level);
 
70
    int indentLevel();
 
71
    void setState(XMLState state);
 
72
    XMLState state();
 
73
 
 
74
 
 
75
    struct xml_output {
 
76
        XMLType xo_type;    // Type of struct instance
 
77
        QString xo_text;    // Tag/Attribute name/xml version
 
78
        QString xo_value;   // Value of attributes/xml encoding
 
79
 
 
80
        xml_output(XMLType type, const QString &text, const QString &value)
 
81
            : xo_type(type), xo_text(text), xo_value(value) {}
 
82
        xml_output(const xml_output &xo)
 
83
            : xo_type(xo.xo_type), xo_text(xo.xo_text), xo_value(xo.xo_value) {}
 
84
    };
 
85
 
 
86
    // Streams
 
87
    XmlOutput& operator<<(const QString& o);
 
88
    XmlOutput& operator<<(const xml_output& o);
 
89
 
 
90
private:
 
91
    void increaseIndent();
 
92
    void decreaseIndent();
 
93
    void updateIndent();
 
94
 
 
95
    QString doConversion(const QString &text);
 
96
 
 
97
    // Output functions
 
98
    void newTag(const QString &tag);
 
99
    void newTagOpen(const QString &tag);
 
100
    void closeOpen();
 
101
    void closeTag();
 
102
    void closeTo(const QString &tag);
 
103
    void closeAll();
 
104
 
 
105
    void addDeclaration(const QString &version, const QString &encoding);
 
106
    void addRaw(const QString &rawText);
 
107
    void addAttribute(const QString &attribute, const QString &value);
 
108
    void addData(const QString &data);
 
109
 
 
110
    // Data
 
111
    QTextStream &xmlFile;
 
112
    QString indent;
 
113
 
 
114
    QString currentIndent;
 
115
    int currentLevel;
 
116
    XMLState currentState;
 
117
 
 
118
    XMLFormat format;
 
119
    ConverstionType conversion;
 
120
    QStack<QString> tagStack;
 
121
};
 
122
 
 
123
inline XmlOutput::xml_output noxml()
 
124
{
 
125
    return XmlOutput::xml_output(XmlOutput::tNothing, QString(), QString());
 
126
}
 
127
 
 
128
inline XmlOutput::xml_output raw(const QString &rawText)
 
129
{
 
130
    return XmlOutput::xml_output(XmlOutput::tRaw, rawText, QString());
 
131
}
 
132
 
 
133
inline XmlOutput::xml_output declaration(const QString &version = QString("1.0"),
 
134
                                         const QString &encoding = QString())
 
135
{
 
136
    return XmlOutput::xml_output(XmlOutput::tDeclaration, version, encoding);
 
137
}
 
138
 
 
139
inline XmlOutput::xml_output decl(const QString &version = QString("1.0"),
 
140
                                  const QString &encoding = QString())
 
141
{
 
142
    return declaration(version, encoding);
 
143
}
 
144
 
 
145
inline XmlOutput::xml_output tag(const QString &name)
 
146
{
 
147
    return XmlOutput::xml_output(XmlOutput::tTag, name, QString());
 
148
}
 
149
 
 
150
inline XmlOutput::xml_output closetag()
 
151
{
 
152
    return XmlOutput::xml_output(XmlOutput::tCloseTag, QString(), QString());
 
153
}
 
154
 
 
155
inline XmlOutput::xml_output closetag(const QString &toTag)
 
156
{
 
157
    return XmlOutput::xml_output(XmlOutput::tCloseTag, toTag, QString());
 
158
}
 
159
 
 
160
inline XmlOutput::xml_output closeall()
 
161
{
 
162
    return XmlOutput::xml_output(XmlOutput::tCloseTag, QString(), QString("all"));
 
163
}
 
164
 
 
165
inline XmlOutput::xml_output attribute(const QString &name,
 
166
                                       const QString &value)
 
167
{
 
168
    return XmlOutput::xml_output(XmlOutput::tAttribute, name, value);
 
169
}
 
170
 
 
171
inline XmlOutput::xml_output attr(const QString &name,
 
172
                                  const QString &value)
 
173
{
 
174
    return attribute(name, value);
 
175
}
 
176
 
 
177
inline XmlOutput::xml_output data(const QString &text = QString())
 
178
{
 
179
    return XmlOutput::xml_output(XmlOutput::tData, text, QString());
 
180
}
 
181
 
 
182
inline XmlOutput::xml_output comment(const QString &text)
 
183
{
 
184
    return XmlOutput::xml_output(XmlOutput::tComment, text, QString());
 
185
}
 
186
 
 
187
inline XmlOutput::xml_output cdata(const QString &text)
 
188
{
 
189
    return XmlOutput::xml_output(XmlOutput::tCDATA, text, QString());
 
190
}
 
191
 
 
192
#endif // __XMLOUTPUT_H__