mainhandler.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * $Id$
4  *
5  *
6  * Copyright (C) 1997-2015 by Dimitri van Heesch.
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation under the terms of the GNU General Public License is hereby
10  * granted. No representations are made about the suitability of this software
11  * for any purpose. It is provided "as is" without express or implied warranty.
12  * See the GNU General Public License for more details.
13  *
14  */
15 
16 #include <qxml.h>
17 #include "mainhandler.h"
18 #include "compoundhandler.h"
19 #include "sectionhandler.h"
20 #include "graphhandler.h"
21 #include "dochandler.h"
22 #include "memberhandler.h"
23 #include "debug.h"
24 
25 
27 {
28  public:
29  virtual ~ErrorHandler() {}
30  bool warning( const QXmlParseException & )
31  {
32  return FALSE;
33  }
34  bool error( const QXmlParseException & )
35  {
36  return FALSE;
37  }
39  {
40  debug(1,"Fatal error at line %d column %d: %s\n",
41  exception.lineNumber(),exception.columnNumber(),
42  exception.message().data());
43  return FALSE;
44  }
45  QString errorString() { return ""; }
46 
47  private:
49 };
50 
51 //--------------------------------------------------------------------------
52 
54  public QListIterator<CompoundEntry>
55 {
56  public:
58  QListIterator<CompoundEntry>(list), m_mainHandler(m) {}
60 
61  virtual void toFirst()
62  {
64  }
65  virtual void toLast()
66  {
68  }
69  virtual void toNext()
70  {
72  }
73  virtual void toPrev()
74  {
76  }
77  virtual ICompound *current() const
78  {
80  return ch ? m_mainHandler->compoundById(ch->id.utf8()) : 0;
81  }
82  virtual void release()
83  { delete this; }
84 
85  private:
87 };
88 
89 //--------------------------------------------------------------------------
90 
91 MainHandler::MainHandler() : m_compoundDict(2999), m_compoundNameDict(2999),
92  m_memberDict(12251), m_memberNameDict(12251),
93  m_compoundsLoaded(1009)
94 {
96  m_memberNameDict.setAutoDelete(TRUE);
97  addStartHandler("doxygenindex");
98  addEndHandler("doxygenindex");
100  addEndHandler("compound");
102  addEndHandler("member",this,&MainHandler::endMember);
104  addEndHandler("name",this,&MainHandler::endName);
105  m_curCompound = 0;
107 }
108 
110 {
111  debug(2,"MainHandler::~MainHandler()\n");
112 }
113 
115 {
116  m_curCompound = new CompoundEntry(257);
117  m_curCompound->id = attrib.value("refid");
120 }
121 
122 void MainHandler::startName(const QXmlAttributes& /*attrib*/)
123 {
124  m_curString = "";
125 }
126 
128 {
129  if (m_insideMember)
130  {
132  }
133  else
134  {
137  }
138 }
139 
141 {
143  m_curMember = new MemberEntry;
144  m_curMember->id = attrib.value("refid");
147 }
148 
150 {
152  QList<CompoundEntry> *cel=0;
153  if ((cel=m_memberNameDict.find(m_curMember->name.utf8()))==0)
154  {
155  cel = new QList<CompoundEntry>;
156  m_memberNameDict.insert(m_curMember->name.utf8(),cel);
157  }
158  cel->append(m_curCompound);
160 }
161 
163 {
164  ::setDebugLevel(level);
165 }
166 
168 {
170  CompoundEntry *ce;
171  for (cli.toFirst();(ce=cli.current());++cli)
172  {
173  debug(2,"compound id=`%s' name=`%s'\n",ce->id.data(),ce->name.data());
174  QDictIterator<MemberEntry> mdi(ce->memberDict);
175  MemberEntry *me;
176  for (mdi.toFirst();(me=mdi.current());++mdi)
177  {
178  debug(2," member id=`%s' name=`%s'\n",me->id.data(),me->name.data());
179  }
180  }
181 }
182 
183 bool MainHandler::readXMLDir(const char * xmlDirName)
184 {
185  m_xmlDirName = xmlDirName;
186  QString xmlFileName=m_xmlDirName+"/index.xml";
187  QFile xmlFile(xmlFileName);
188  //printf("Trying %s xmlFile.exists()=%d isReadable()=%d\n",
189  // xmlFileName.data(),xmlFile.exists(),xmlFile.isReadable());
190  if (xmlFile.exists())
191  {
192  ErrorHandler errorHandler;
193  QXmlInputSource source( xmlFile );
194  QXmlSimpleReader reader;
195  reader.setContentHandler( this );
196  reader.setErrorHandler( &errorHandler );
197  reader.parse( source );
198  dump();
199  return TRUE;
200  }
201  return FALSE;
202 }
203 
205 {
206  return new CompoundEntryIterator(this,m_compounds);
207 }
208 
209 ICompound *MainHandler::compoundById(const char *id) const
210 {
211  QString ids = id;
212  if (ids.isEmpty()) return 0;
214  if (ch) // compound already in memory
215  {
216  ch->addref(); // returning alias -> increase reference counter
217  return ch->toICompound();
218  }
219  CompoundEntry *ce = m_compoundDict.find(ids.utf8());
220  if (ce==0) return 0; // id not found
221  // create and load a new compound
222  ch = new CompoundHandler(m_xmlDirName);
223  if (!ch->parseXML(id))
224  {
225  // compound could not be initialized.
226  delete ch;
227  return 0;
228  }
229 
230  // we disregard the constness here, because the object stays conceptually
231  // unchanged.
232  MainHandler *that = (MainHandler *)this;
233  ch->initialize(that);
234  //printf("loading compound %s in memory\n",id);
235  that->m_compoundsLoaded.insert(id,ch);
236  return ch->toICompound();
237 }
238 
240 {
241  //printf("unloading compound %s from memory\n",ch->id()->latin1());
242  bool result = m_compoundsLoaded.remove(ch->id()->latin1());
243  if (!result) debug(1,"Failed to unload component!\n");
244 }
245 
247 {
248  QString nameStr = name;
249  if (nameStr.isEmpty()) return 0;
251  if (ce==0) return 0; // name not found
252  return compoundById(ce->id.utf8());
253 }
254 
255 ICompound *MainHandler::memberById(const char *id) const
256 {
257  QString ids = id;
258  if (ids.isEmpty()) return 0;
259  MemberEntry *me = m_memberDict[id];
260  if (me==0) return 0; // id not found
261  return compoundById(me->compound->id.utf8());
262 }
263 
265 {
266  QString nameStr = name;
267  if (nameStr.isEmpty()) return 0;
269  if (cel==0) return 0; // name not found
270  return new CompoundEntryIterator(this,*cel);
271 }
272 
274 {
278  dochandler_init();
280  return new MainHandler;
281 }
282 
284 {
285  //printf("MainHandler::release()\n");
286  QDictIterator<CompoundHandler> chi(m_compoundsLoaded);
287  CompoundHandler *ch;
288  for (chi.toFirst();(ch=chi.current());++chi)
289  {
290  debug(1,"Compound %s not released\n",ch->name()->latin1());
291  }
293  dochandler_exit();
297  delete this;
298 }
299 
static QCString name
Definition: declinfo.cpp:673
CompoundEntry * m_curCompound
Definition: mainhandler.h:70
virtual void release()
bool isEmpty() const
Definition: qstring.h:682
void dochandler_exit()
Definition: dochandler.cpp:90
QDict< MemberEntry > memberDict
Definition: mainhandler.h:42
static QCString result
void memberhandler_exit()
const MainHandler * m_mainHandler
Definition: mainhandler.cpp:86
virtual ICompound * current() const
Definition: mainhandler.cpp:77
void setDebugLevel(int level)
void append(const type *d)
Definition: qlist.h:73
void memberhandler_init()
virtual void endName()
bool error(const QXmlParseException &)
Definition: mainhandler.cpp:34
bool parse(const QXmlInputSource &input)
Definition: qxml.cpp:2077
virtual void addref()
virtual const char * latin1() const =0
const bool FALSE
Definition: qglobal.h:370
int columnNumber() const
Definition: qxml.cpp:231
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
void setErrorHandler(QXmlErrorHandler *handler)
Definition: qxml.cpp:2051
The QXmlErrorHandler class provides an interface to report errors in XML data.
Definition: qxml.h:420
type * operator++()
Definition: qlist.h:148
QString message() const
Definition: qxml.cpp:224
QString value(int index) const
Definition: qxml.cpp:664
bool warning(const QXmlParseException &)
Definition: mainhandler.cpp:30
bool readXMLDir(const char *dirName)
virtual void release()
Definition: mainhandler.cpp:82
ICompound * toICompound() const
CompoundEntry * compound
Definition: mainhandler.h:35
bool parseXML(const char *compId)
QDict< MemberEntry > m_memberDict
Definition: mainhandler.h:75
The QXmlSimpleReader class provides an implementation of a simple XML reader (i.e. parser).
Definition: qxml.h:238
bool m_insideMember
Definition: mainhandler.h:79
void graphhandler_init()
void dochandler_init()
Definition: dochandler.cpp:84
def cli(ctx)
Definition: main.py:7
const IString * name() const
const char * data() const
Definition: qstring.h:542
bool fatalError(const QXmlParseException &exception)
Definition: mainhandler.cpp:38
MemberEntry * m_curMember
Definition: mainhandler.h:71
void setContentHandler(QXmlContentHandler *handler)
Definition: qxml.cpp:2043
bool exists() const
Definition: qfile.cpp:183
virtual ~ErrorHandler()
Definition: mainhandler.cpp:29
void initialize(MainHandler *mh)
QString name
Definition: mainhandler.h:30
void compoundhandler_exit()
virtual void endMember()
QDict< CompoundEntry > m_compoundNameDict
Definition: mainhandler.h:74
virtual ICompound * memberById(const char *id) const
CompoundEntryIterator(const MainHandler *m, const QList< CompoundEntry > &list)
Definition: mainhandler.cpp:57
virtual void startName(const QXmlAttributes &attrib)
virtual void toNext()
Definition: mainhandler.cpp:69
type * current() const
Definition: qlist.h:146
ICompound * compoundById(const char *id) const
const IString * id() const
virtual void toPrev()
Definition: mainhandler.cpp:73
virtual ICompoundIterator * memberByName(const char *name) const
The interface to a compound in the object model.
Definition: doxmlintf.h:868
The QFile class is an I/O device that operates on files.
Definition: qfile.h:50
void sectionhandler_init()
virtual void startMember(const QXmlAttributes &attrib)
QList< CompoundEntry > m_compounds
Definition: mainhandler.h:72
void compoundhandler_init()
virtual void toFirst()
Definition: mainhandler.cpp:61
void unloadCompound(CompoundHandler *ch)
QDict< CompoundHandler > m_compoundsLoaded
Definition: mainhandler.h:78
void sectionhandler_exit()
virtual ~MainHandler()
QDict< CompoundEntry > m_compoundDict
Definition: mainhandler.h:73
QString errorMsg
Definition: mainhandler.cpp:48
The QXmlAttributes class provides XML attributes.
Definition: qxml.h:128
QString id
Definition: mainhandler.h:29
type * operator--()
Definition: qlist.h:150
void addStartHandler(const char *key)
Definition: basehandler.h:91
IDoxygen * createObjectModel()
virtual void toLast()
Definition: mainhandler.cpp:65
QString errorString()
Definition: mainhandler.cpp:45
The QXmlInputSource class is the source where XML data is read from.
Definition: qxml.h:162
virtual ICompound * compoundByName(const char *name) const
void graphhandler_exit()
virtual void startCompound(const QXmlAttributes &attrib)
QCString utf8() const
Definition: qstring.cpp:14507
QDict< QList< CompoundEntry > > m_memberNameDict
Definition: mainhandler.h:76
ICompoundIterator * compounds() const
void setAutoDelete(bool enable)
Definition: qlist.h:99
int lineNumber() const
Definition: qxml.cpp:238
type * toLast()
Definition: qlist.h:136
QString m_xmlDirName
Definition: mainhandler.h:77
const bool TRUE
Definition: qglobal.h:371
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
The QXmlParseException class is used to report errors with the QXmlErrorHandler interface.
Definition: qxml.h:185
void addEndHandler(const char *key)
Definition: basehandler.h:101
virtual ~CompoundEntryIterator()
Definition: mainhandler.cpp:59
type * toFirst()
Definition: qlist.h:135