Line # Revision Author
1 1 moose #include <QtXml>
2 #include <QCoreApplication>
3 #include <iostream>
4
5 #define START() qDebug() << __PRETTY_FUNCTION__
6
7 class XRCHandler;
8 class XRCElement;
9
10 template<typename T>
11 class XRCElementFactory {
12 public:
13 XRCElementFactory(QString n) : name(n) { }
14 virtual ~XRCElementFactory() { }
15
16 virtual T operator()() = 0;
17
18 QString &getName() { return name; }
19
20 private:
21 QString name;
22 };
23
24 class XRCWindowElementFactory : public XRCElementFactory<SciQMWBase *> {
25 public:
26 XRCWindowElementFactory() : XRCElementFactory("window") { }
27 SciQMWBase *operator()() { return new SciQMWBase(app); }
28
29 private:
30 };
31
32 #if 0
33
34 app->addElementFactory(new XRCWindowElementFactory());
35
36 bool SciQApp::addElementFactory(XRCElementFactory *fac)
37 {
38 app->elementList[fac->getName()] = fac;
39 }
40
41
42
43 #endif
44
45 class XRCElementBase {
46 public:
47 XRCElementBase(XRCHandler *h, QString n, const QXmlAttributes &a) : hnd(h), atts(a), name(n) { }
48 virtual ~XRCElementBase() { }
49
50 virtual bool start(XRCHandler *, const QXmlAttributes &atts) = 0;
51 virtual bool end() = 0;
52 virtual bool characters(QString &ch) = 0;
53
54 private:
55 XRCHandler *hnd;
56 QXmlAttributes atts;
57 QString name;
58 };
59
60 class XRCHandler : public QXmlDefaultHandler {
61 public:
62 bool startDocument();
63 bool startElement ( const QString & namespaceURI, const QString & localName, const QString & qName, const QXmlAttributes & atts );
64 bool endElement ( const QString & namespaceURI, const QString & localName, const QString & qName );
65 bool endDocument ();
66 bool characters ( const QString & ch );
67
68 bool fatalError (const QXmlParseException & exception);
69
70 void push
71 private:
72 QStack<XRCTag> stack;
73 };
74
75 bool XRCHandler::fatalError (const QXmlParseException & exception)
76 {
77 START();
78
79 qWarning() << "Fatal error on line" << exception.lineNumber()
80 << ", column" << exception.columnNumber() << ":"
81 << exception.message();
82
83 return false;
84 }
85
86 bool XRCHandler::startDocument()
87 {
88 START();
89 return true;
90 }
91
92 bool XRCHandler::startElement ( const QString & namespaceURI, const QString & localName, const QString & qName, const QXmlAttributes & atts )
93 {
94 START();
95 qDebug() << "Start: " << namespaceURI << ":" << localName << ":" << qName;
96 return true;
97 }
98
99 bool XRCHandler::endElement ( const QString & namespaceURI, const QString & localName, const QString & qName )
100 {
101 START();
102 qDebug() << "End: " << namespaceURI << ":" << localName << ":" << qName;
103 return true;
104 }
105
106 bool XRCHandler::endDocument ()
107 {
108 START();
109 return true;
110 }
111
112 bool XRCHandler::characters ( const QString & ch )
113 {
114 START();
115 return true;
116 }
117
118 int main(int argc, char **argv)
119 {
120 QCoreApplication app(argc, argv);
121 if(argc < 2) {
122 qWarning() << "no file?";
123 exit(0);
124 }
125
126 QFile fh(argv[1]);
127 QXmlSimpleReader xmlReader;
128 QXmlInputSource *source = new QXmlInputSource(fh);
129
130 XRCHandler *handler = new XRCHandler;
131 xmlReader.setContentHandler(handler);
132 xmlReader.setErrorHandler(handler);
133
134 bool ok = xmlReader.parse(source);
135 if (!ok)
136 std::cout << "Parsing failed." << std::endl;
137
138 return 0;
139 }
140
141
142
143
144
145
146
147
148
149
150