Revision 1 (by moose, 2006/03/06 10:35:57) Initial Import
#include <QtXml>
#include <QCoreApplication>
#include <iostream>

#define START() qDebug() << __PRETTY_FUNCTION__

class XRCHandler;
class XRCElement;

template<typename T>
class XRCElementFactory {
	public:
		XRCElementFactory(QString n) : name(n) { }
		virtual ~XRCElementFactory() { }

		virtual T operator()() = 0;

		QString &getName() { return name; }

	private:
		QString name;
};

class XRCWindowElementFactory : public XRCElementFactory<SciQMWBase *> {
	public:
		XRCWindowElementFactory() : XRCElementFactory("window") { }
		SciQMWBase *operator()() { return new SciQMWBase(app); }

	private:
};

#if 0

app->addElementFactory(new XRCWindowElementFactory());

bool SciQApp::addElementFactory(XRCElementFactory *fac)
{
	app->elementList[fac->getName()] = fac;
}



#endif

class XRCElementBase {
	public:
		XRCElementBase(XRCHandler *h, QString n, const QXmlAttributes &a) : hnd(h), atts(a), name(n) { }
		virtual ~XRCElementBase() { }

		virtual bool start(XRCHandler *, const QXmlAttributes &atts) = 0;
		virtual bool end() = 0;
		virtual bool characters(QString &ch) = 0;

	private:
		XRCHandler *hnd;
		QXmlAttributes atts;
		QString name;
};

class XRCHandler : public QXmlDefaultHandler {
	public:
		bool startDocument();
		bool startElement ( const QString & namespaceURI, const QString & localName, const QString & qName, const QXmlAttributes & atts );
		bool endElement ( const QString & namespaceURI, const QString & localName, const QString & qName );
		bool endDocument ();
		bool characters ( const QString & ch );

		bool fatalError (const QXmlParseException & exception);

		void push
	private:
		QStack<XRCTag> stack;
};

bool XRCHandler::fatalError (const QXmlParseException & exception)
{
	START();

	qWarning() << "Fatal error on line" << exception.lineNumber()
		<< ", column" << exception.columnNumber() << ":"
		<< exception.message();

	return false;
}

bool XRCHandler::startDocument()
{
	START();
	return true;
}

bool XRCHandler::startElement ( const QString & namespaceURI, const QString & localName, const QString & qName, const QXmlAttributes & atts )
{
	START();
	qDebug() << "Start: " << namespaceURI << ":" << localName << ":" << qName;
	return true;
}

bool XRCHandler::endElement ( const QString & namespaceURI, const QString & localName, const QString & qName )
{
	START();
	qDebug() << "End: " << namespaceURI << ":" << localName << ":" << qName;
	return true;
}

bool XRCHandler::endDocument ()
{
	START();
	return true;
}

bool XRCHandler::characters ( const QString & ch )
{
	START();
	return true;
}

int main(int argc, char **argv)
{
	QCoreApplication app(argc, argv);
	if(argc < 2) {
		qWarning() << "no file?";
		exit(0);
	}

	QFile fh(argv[1]);
	QXmlSimpleReader xmlReader;
	QXmlInputSource *source = new QXmlInputSource(fh);

	XRCHandler *handler = new XRCHandler;
	xmlReader.setContentHandler(handler);
	xmlReader.setErrorHandler(handler);

	bool ok = xmlReader.parse(source);
	if (!ok)
		std::cout << "Parsing failed." << std::endl;

	return 0;
}