summaryrefslogtreecommitdiffstats
path: root/addon/doxmlparser/src/mainhandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'addon/doxmlparser/src/mainhandler.cpp')
-rw-r--r--addon/doxmlparser/src/mainhandler.cpp289
1 files changed, 219 insertions, 70 deletions
diff --git a/addon/doxmlparser/src/mainhandler.cpp b/addon/doxmlparser/src/mainhandler.cpp
index 7d0e682..99cb665 100644
--- a/addon/doxmlparser/src/mainhandler.cpp
+++ b/addon/doxmlparser/src/mainhandler.cpp
@@ -3,7 +3,7 @@
* $Id$
*
*
- * Copyright (C) 1997-2001 by Dimitri van Heesch.
+ * Copyright (C) 1997-2002 by Dimitri van Heesch.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation under the terms of the GNU General Public License is hereby
@@ -15,112 +15,261 @@
#include <qxml.h>
#include "mainhandler.h"
+#include "compoundhandler.h"
+#include "debug.h"
-MainHandler::MainHandler() : m_compoundDict(10007), m_compoundNameDict(10007)
+class ErrorHandler : public QXmlErrorHandler
+{
+ public:
+ virtual ~ErrorHandler() {}
+ bool warning( const QXmlParseException & )
+ {
+ return FALSE;
+ }
+ bool error( const QXmlParseException & )
+ {
+ return FALSE;
+ }
+ bool fatalError( const QXmlParseException &exception )
+ {
+ debug(1,"Fatal error at line %d column %d: %s\n",
+ exception.lineNumber(),exception.columnNumber(),
+ exception.message().data());
+ return FALSE;
+ }
+ QString errorString() { return ""; }
+
+ private:
+ QString errorMsg;
+};
+
+//--------------------------------------------------------------------------
+
+class CompoundEntryIterator : public ICompoundIterator,
+ public QListIterator<CompoundEntry>
+{
+ public:
+ CompoundEntryIterator(const MainHandler *m,const QList<CompoundEntry> &list) :
+ QListIterator<CompoundEntry>(list), m_mainHandler(m) {}
+ virtual ~CompoundEntryIterator() {}
+
+ virtual void toFirst()
+ {
+ QListIterator<CompoundEntry>::toFirst();
+ }
+ virtual void toLast()
+ {
+ QListIterator<CompoundEntry>::toLast();
+ }
+ virtual void toNext()
+ {
+ QListIterator<CompoundEntry>::operator++();
+ }
+ virtual void toPrev()
+ {
+ QListIterator<CompoundEntry>::operator--();
+ }
+ virtual ICompound *current() const
+ {
+ CompoundEntry *ch = QListIterator<CompoundEntry>::current();
+ return ch ? m_mainHandler->compoundById(ch->id) : 0;
+ }
+ virtual void release()
+ { delete this; }
+
+ private:
+ const MainHandler *m_mainHandler;
+};
+
+//--------------------------------------------------------------------------
+
+MainHandler::MainHandler() : m_compoundDict(2999), m_compoundNameDict(2999),
+ m_memberDict(12251), m_memberNameDict(12251),
+ m_compoundsLoaded(1009)
{
m_compounds.setAutoDelete(TRUE);
+ m_memberNameDict.setAutoDelete(TRUE);
addStartHandler("doxygen");
- addStartHandler("compounddef",this,&MainHandler::startCompound);
addEndHandler("doxygen");
- addEndHandler("compounddef");
+ addStartHandler("compound",this,&MainHandler::startCompound);
+ addEndHandler("compound");
+ addStartHandler("member",this,&MainHandler::startMember);
+ addEndHandler("member",this,&MainHandler::endMember);
+ addStartHandler("name",this,&MainHandler::startName);
+ addEndHandler("name",this,&MainHandler::endName);
+ m_curCompound = 0;
}
MainHandler::~MainHandler()
{
- printf("MainHandler::~MainHandler()\n");
+ debug(2,"MainHandler::~MainHandler()\n");
}
void MainHandler::startCompound(const QXmlAttributes& attrib)
{
- CompoundHandler *compHandler = new CompoundHandler(this);
- compHandler->startCompound(attrib);
- m_compounds.append(compHandler);
+ m_curCompound = new CompoundEntry(257);
+ m_curCompound->id = attrib.value("id");
+ m_compounds.append(m_curCompound);
+ m_compoundDict.insert(m_curCompound->id,m_curCompound);
}
-void MainHandler::insertMemberById(const QString &id,IMember *h)
+void MainHandler::startName(const QXmlAttributes& /*attrib*/)
{
- m_memberDict.insert(id,h);
+ m_curString = "";
}
-void MainHandler::insertMemberByName(const QString &name,IMember *h)
+void MainHandler::endName()
{
- QList<IMember> *ml = m_memberNameDict[name];
- if (ml)
+ m_curCompound->name = m_curString;
+}
+
+void MainHandler::startMember(const QXmlAttributes& attrib)
+{
+ m_curString = "";
+ m_curMember = new MemberEntry;
+ m_curMember->id = attrib.value("id");
+ m_curMember->compound = m_curCompound;
+ m_memberDict.insert(m_curMember->id,m_curMember);
+}
+
+void MainHandler::endMember()
+{
+ m_curMember->name = m_curString;
+ m_curCompound->memberDict.insert(m_curString,m_curMember);
+ QList<CompoundEntry> *cel=0;
+ if ((cel=m_memberNameDict.find(m_curString))==0)
{
- ml->append(h);
+ cel = new QList<CompoundEntry>;
+ m_memberNameDict.insert(m_curString,cel);
}
- else
+ cel->append(m_curCompound);
+}
+
+void MainHandler::setDebugLevel(int level)
+{
+ ::setDebugLevel(level);
+}
+
+void MainHandler::dump()
+{
+ QListIterator<CompoundEntry> cli(m_compounds);
+ CompoundEntry *ce;
+ for (cli.toFirst();(ce=cli.current());++cli)
{
- ml = new QList<IMember>;
- ml->append(h);
- m_memberNameDict.insert(name,ml);
+ debug(2,"compound id=`%s' name=`%s'\n",ce->id.data(),ce->name.data());
+ QDictIterator<MemberEntry> mdi(ce->memberDict);
+ MemberEntry *me;
+ for (mdi.toFirst();(me=mdi.current());++mdi)
+ {
+ debug(2," member id=`%s' name=`%s'\n",me->id.data(),me->name.data());
+ }
}
}
-void MainHandler::initialize()
+bool MainHandler::readXMLDir(const char * xmlDirName)
{
- QListIterator<ICompound> mci(m_compounds);
- CompoundHandler *compHandler;
- for (;(compHandler=(CompoundHandler *)mci.current());++mci)
+ m_xmlDirName = xmlDirName;
+ QString xmlFileName=m_xmlDirName+"/index.xml";
+ QFile xmlFile(xmlFileName);
+ //printf("Trying %s xmlFile.exists()=%d isReadable()=%d\n",
+ // xmlFileName.data(),xmlFile.exists(),xmlFile.isReadable());
+ if (xmlFile.exists())
{
- compHandler->initialize(this);
- m_compoundNameDict.insert(compHandler->name(),compHandler);
- m_compoundDict.insert(compHandler->id(),compHandler);
+ ErrorHandler errorHandler;
+ QXmlInputSource source( xmlFile );
+ QXmlSimpleReader reader;
+ reader.setContentHandler( this );
+ reader.setErrorHandler( &errorHandler );
+ reader.parse( source );
+ dump();
+ return TRUE;
}
+ return FALSE;
+}
+
+ICompoundIterator *MainHandler::compounds() const
+{
+ return new CompoundEntryIterator(this,m_compounds);
+}
- // for each member
- QDictIterator< QList<IMember> > mndi(m_memberNameDict);
- QList<IMember> *ml;
- for (;(ml=mndi.current());++mndi)
+ICompound *MainHandler::compoundById(const QString &id) const
+{
+ if (id.isEmpty()) return 0;
+ CompoundHandler *ch = m_compoundsLoaded[id];
+ if (ch) // compound already in memory
{
- QListIterator<IMember> mli(*ml);
- IMember *mem;
- for (;(mem=mli.current());++mli)
- {
- ((MemberHandler*)mem)->initialize(this);
- }
+ ch->addref(); // returning alias -> increase reference counter
+ return ch;
+ }
+ CompoundEntry *ce = m_compoundDict.find(id);
+ if (ce==0) return 0; // id not found
+ // create and load a new compound
+ ch = new CompoundHandler(m_xmlDirName);
+ if (!ch->parseXML(id))
+ {
+ // compound could not be initialized.
+ delete ch;
+ return 0;
}
+ // we disregard the constness here, because the object stays conceptually
+ // unchanged.
+ MainHandler *that = (MainHandler *)this;
+ ch->initialize(that);
+ that->m_compoundsLoaded.insert(id,ch);
+ return ch;
}
-class ErrorHandler : public QXmlErrorHandler
+void MainHandler::unloadCompound(CompoundHandler *ch)
{
- public:
- virtual ~ErrorHandler() {}
- bool warning( const QXmlParseException & )
- {
- return FALSE;
- }
- bool error( const QXmlParseException & )
- {
- return FALSE;
- }
- bool fatalError( const QXmlParseException &exception )
- {
- fprintf(stderr,"Fatal error at line %d column %d: %s\n",
- exception.lineNumber(),exception.columnNumber(),
- exception.message().data());
- return FALSE;
- }
- QString errorString() { return ""; }
+ m_compoundsLoaded.remove(ch->id());
+}
- private:
- QString errorMsg;
-};
+ICompound *MainHandler::compoundByName(const QString &name) const
+{
+ if (name.isEmpty()) return 0;
+ CompoundEntry *ce = m_compoundNameDict[name];
+ if (ce==0) return 0; // name not found
+ return compoundById(ce->id);
+}
-IDoxygen *createObjectModelFromXML(const char * xmlFileName)
+ICompound *MainHandler::memberById(const QString &id) const
{
- QFile xmlFile(xmlFileName);
- MainHandler * handler = new MainHandler;
- ErrorHandler errorHandler;
- QXmlInputSource source( xmlFile );
- QXmlSimpleReader reader;
- reader.setContentHandler( handler );
- reader.setErrorHandler( &errorHandler );
- reader.parse( source );
- printf("<---------- initialize ----------->\n");
- handler->initialize();
- printf("<-------- end initialize --------->\n");
- return handler;
+ if (id.isEmpty()) return 0;
+ MemberEntry *me = m_memberDict[id];
+ if (me==0) return 0; // id not found
+ return compoundById(me->id);
+}
+
+ICompoundIterator *MainHandler::memberByName(const QString &name) const
+{
+ if (name.isEmpty()) return 0;
+ QList<CompoundEntry> *cel = m_memberNameDict[name];
+ if (cel==0) return 0; // name not found
+ return new CompoundEntryIterator(this,*cel);
+}
+
+IDoxygen *createObjectModel()
+{
+ compoundhandler_init();
+ sectionhandler_init();
+ memberhandler_init();
+ dochandler_init();
+ return new MainHandler;
+}
+
+void MainHandler::release()
+{
+ QDictIterator<CompoundHandler> chi(m_compoundsLoaded);
+ CompoundHandler *ch;
+ for (chi.toFirst();(ch=chi.current());++chi)
+ {
+ debug(1,"Compound %s not released\n",ch->name().data());
+ }
+ dochandler_exit();
+ memberhandler_exit();
+ sectionhandler_exit();
+ compoundhandler_exit();
+ delete this;
}