compoundhandler.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 "mainhandler.h"
17 #include "compoundhandler.h"
18 #include "dochandler.h"
19 #include "debug.h"
20 #include "graphhandler.h"
21 #include "sectionhandler.h"
22 #include "paramhandler.h"
23 #include "loamhandler.h"
24 #include "memberhandler.h"
25 
26 //----------------------------------------------------------------------------
27 
29  m_parent(parent)
30 {
32 }
33 
35 {
36 }
37 
39 {
40  m_curString = "";
41  m_refId = attrib.value("refid");
42  m_isLocal = attrib.value("local")=="yes";
43  m_parent->setDelegate(this);
44 }
45 
47 {
50  debug(2,"Found include %s\n",m_name.data());
51 }
52 
53 //----------------------------------------------------------------------------
54 
56  public QListIterator<QString>
57 {
58  public:
60  QListIterator<QString>(list), m_mainHandler(m) {}
61  virtual ~CompoundIdIterator() {}
62 
63  virtual void toFirst()
64  {
66  }
67  virtual void toLast()
68  {
70  }
71  virtual void toNext()
72  {
74  }
75  virtual void toPrev()
76  {
78  }
79  virtual ICompound *current() const
80  {
82  return id ? m_mainHandler->compoundById(id->utf8()) : 0;
83  }
84  virtual void release()
85  { delete this; }
86 
87  private:
89 };
90 
91 //----------------------------------------------------------------------------
92 
94 {
95  return m_parent->m_mainHandler->compoundById(m_id.utf8());
96 }
97 
98 //----------------------------------------------------------------------------
99 
101 {
102  public:
104  bool warning( const QXmlParseException & )
105  {
106  return FALSE;
107  }
108  bool error( const QXmlParseException & )
109  {
110  return FALSE;
111  }
113  {
114  debug(1,"Fatal error at line %d column %d: %s\n",
115  exception.lineNumber(),exception.columnNumber(),
116  exception.message().data());
117  return FALSE;
118  }
119  QString errorString() { return ""; }
120 
121  private:
123 };
124 
125 //----------------------------------------------------------------------------
126 
128 {
129  public:
131  {
132  m_map.setAutoDelete(TRUE);
133  m_map.insert("class", new int(ICompound::Class));
134  m_map.insert("struct", new int(ICompound::Struct));
135  m_map.insert("union", new int(ICompound::Union));
136  m_map.insert("interface",new int(ICompound::Interface));
137  m_map.insert("protocol", new int(ICompound::Protocol));
138  m_map.insert("category", new int(ICompound::Category));
139  m_map.insert("exception",new int(ICompound::Exception));
140  m_map.insert("file", new int(ICompound::File));
141  m_map.insert("namespace",new int(ICompound::Namespace));
142  m_map.insert("group", new int(ICompound::Group));
143  m_map.insert("page", new int(ICompound::Page));
144  m_map.insert("example", new int(ICompound::Example));
145  m_map.insert("dir", new int(ICompound::Dir));
146  }
148  {
149  }
151  {
152  int *val = m_map.find(s.utf8());
153  if (val==0)
154  {
155  debug(1,"Warning: `%s' is an invalid compound type\n",s.data());
156  return ICompound::Invalid;
157  }
158  else return (ICompound::CompoundKind)*val;
159  }
160  private:
161  QDict<int> m_map;
162 };
163 
165 
167 {
168  s_typeMap = new CompoundTypeMap;
169 }
170 
172 {
173  delete s_typeMap;
174 }
175 
176 //----------------------------------------------------------------------------
177 
179  : m_titleHandler(0),
180  m_includeDependencyGraph(0),
181  m_includedByDependencyGraph(0),
182  m_templateParamList(0),
183  m_brief(0),
184  m_detailed(0),
185  m_inheritanceGraph(0),
186  m_collaborationGraph(0),
187  m_programListing(0),
188  m_members(0),
189  m_xmlDir(xmlDir),
190  m_refCount(1),
191  m_memberDict(257),
192  m_memberNameDict(257),
193  m_mainHandler(0)
194 {
198  m_memberNameDict.setAutoDelete(TRUE);
202 
203  addStartHandler("doxygen");
204  addEndHandler("doxygen");
205 
206  addStartHandler("compounddef",this,&CompoundHandler::startCompound);
207  addEndHandler("compounddef",this,&CompoundHandler::endCompound);
208 
209  addStartHandler("compoundname");
210  addEndHandler("compoundname",this,&CompoundHandler::endCompoundName);
211 
213 
214  addStartHandler("basecompoundref",this,&CompoundHandler::startSuperClass);
215  addEndHandler("basecompoundref",this,&CompoundHandler::endSuperClass);
216 
217  addStartHandler("derivedcompoundref",this,&CompoundHandler::startSubClass);
218  addEndHandler("derivedcompoundref",this,&CompoundHandler::endSubClass);
219 
222 
224 
226 
228  addEndHandler("innerdir");
229 
231  addEndHandler("innerfile");
232 
234  addEndHandler("innerclass");
235 
237  addEndHandler("innernamespace");
238 
240  addEndHandler("innerpage");
241 
243  addEndHandler("innergroup");
244 
245  addStartHandler("templateparamlist",this,&CompoundHandler::startTemplateParamList);
246 
248 
249  addStartHandler("briefdescription",this,&CompoundHandler::startBriefDesc);
250 
251  addStartHandler("detaileddescription",this,&CompoundHandler::startDetailedDesc);
252 
254 
255  addStartHandler("collaborationgraph",this,&CompoundHandler::startCollaborationGraph);
256 
258 
260  addEndHandler("location");
261 
263 }
264 
266 {
267  debug(2,"CompoundHandler::~CompoundHandler()\n");
268  delete m_titleHandler;
269  delete m_brief;
270  delete m_detailed;
271  delete m_programListing;
272  delete m_inheritanceGraph;
273  delete m_collaborationGraph;
276  delete m_templateParamList;
277  delete m_members;
278 }
279 
281 {
282  SectionHandler *sectHandler = new SectionHandler(this);
283  sectHandler->startSection(attrib);
284  m_sections.append(sectHandler);
285 }
286 
288 {
289  DocHandler *docHandler = new DocHandler(this);
290  docHandler->startDoc(attrib);
291  m_brief = docHandler;
292 }
293 
295 {
296  DocHandler *docHandler = new DocHandler(this);
297  docHandler->startDoc(attrib);
298  m_detailed = docHandler;
299 }
300 
302 {
303  ProgramListingHandler *plHandler = new ProgramListingHandler(this);
304  plHandler->startProgramListing(attrib);
305  m_programListing = plHandler;
306 }
307 
309 {
310  IncludeHandler *inc = new IncludeHandler(this,"includes");
311  m_includes.append(inc);
312  inc->startInclude(attrib);
313 }
314 
316 {
317  IncludeHandler *inc = new IncludeHandler(this,"includedby");
318  m_includedBy.append(inc);
319  inc->startInclude(attrib);
320 }
321 
323 {
324  m_id = attrib.value("id");
325  m_kindString = attrib.value("kind");
326  m_kind = s_typeMap->map(m_kindString);
327  m_protection = attrib.value("prot");
328  debug(2,"startCompound(id=`%s' type=`%s')\n",m_id.data(),m_kindString.data());
329 }
330 
332 {
333  debug(2,"endCompound()\n");
334 }
335 
337 {
338  m_defFile = attrib.value("file");
339  m_defLine = attrib.value("line").toInt();
340  m_defBodyFile = attrib.value("bodyfile");
341  m_defBodyStart = attrib.value("bodystart").toInt();
342  m_defBodyEnd = attrib.value("bodyend").toInt();
343 }
344 
346 {
348  debug(2,"Compound name `%s'\n",m_name.data());
349 }
350 
352 {
353  m_innerCompounds.append(new QString(attrib.value("refid")));
354 }
355 
357 {
358  m_innerCompounds.append(new QString(attrib.value("refid")));
359 }
360 
362 {
363  m_innerCompounds.append(new QString(attrib.value("refid")));
364 }
365 
367 {
368  m_innerCompounds.append(new QString(attrib.value("refid")));
369 }
370 
372 {
373  m_innerCompounds.append(new QString(attrib.value("refid")));
374 }
375 
377 {
378  m_innerCompounds.append(new QString(attrib.value("refid")));
379 }
380 
382 {
385 }
386 
388 {
391 }
392 
394 {
396  QString protString = attrib.value("prot");
397  if (protString=="protected")
398  {
400  }
401  else if (protString=="private")
402  {
404  }
406  QString kindString = attrib.value("virt");
407  if (kindString=="virtual") kind = IRelatedCompound::Virtual;
408 
410  this,
411  attrib.value("refid"),
412  prot,
413  kind
414  );
415  debug(2,"super class id=`%s' prot=`%s' virt=`%s'\n",
416  attrib.value("refid").data(),
417  protString.data(),
418  kindString.data());
420  m_curString = "";
421 }
422 
424 {
426 }
427 
429 {
431  QString protString = attrib.value("prot");
432  if (protString=="protected") prot = IRelatedCompound::Protected;
433  else if (protString=="private") prot = IRelatedCompound::Private;
434 
436  QString kindString = attrib.value("virt");
437  if (kindString=="virtual") kind = IRelatedCompound::Virtual;
438 
440  this,
441  attrib.value("refid"),
442  prot,
443  kind
444  );
445  debug(2,"sub class id=`%s' prot=`%s' virt=`%s'\n",
446  attrib.value("refid").data(),
447  protString.data(),
448  kindString.data());
449  m_subClasses.append(sc);
450  m_curString = "";
451 }
452 
454 {
456 }
457 
459 {
461  m_titleHandler = new TitleHandler(this);
462  m_titleHandler->startTitle(attrib);
463 }
464 
465 bool CompoundHandler::parseXML(const char *compId)
466 {
467  QFile xmlFile(m_xmlDir+"/"+compId+".xml");
468  if (!xmlFile.exists()) return FALSE;
469  CompoundErrorHandler errorHandler;
470  QXmlInputSource source( xmlFile );
471  QXmlSimpleReader reader;
472  reader.setContentHandler( this );
473  reader.setErrorHandler( &errorHandler );
474  reader.parse( source );
475  return TRUE;
476 }
477 
479 {
480  m_mainHandler = mh;
482  SectionHandler *sec;
483  for (;(sec=msi.current());++msi)
484  {
485  sec->initialize(this);
486  }
487  if (m_members)
488  {
489  m_members->initialize(mh);
490  }
491 }
492 
494 {
495  m_memberDict.insert(mh->id()->latin1(),mh);
497  QList<MemberHandler> *mhl = m_memberNameDict.find(mh->id()->latin1());
498  if (mhl==0)
499  {
500  mhl = new QList<MemberHandler>;
501  m_memberNameDict.insert(mh->name()->latin1(),mhl);
502  }
503  mhl->append(mh);
504 }
505 
507 {
508  switch (m_kind)
509  {
510  case ICompound::Class: return (IClass *)this;
511  case ICompound::Struct: return (IStruct *)this;
512  case ICompound::Union: return (IUnion *)this;
513  case ICompound::Interface: return (IInterface *)this;
514  case ICompound::Protocol: return (IClass *)this;
515  case ICompound::Category: return (IClass *)this;
516  case ICompound::Exception: return (IException *)this;
517  case ICompound::File: return (IFile *)this;
518  case ICompound::Namespace: return (INamespace *)this;
519  case ICompound::Group: return (IGroup *)this;
520  case ICompound::Page: return (IPage *)this;
521  case ICompound::Example: return (IPage *)this;
522  case ICompound::Dir: return (IDir *)this;
523  default: return 0;
524  }
525  return 0;
526 }
527 
529 {
530  debug(2,"CompoundHandler::release() %d->%d\n",m_refCount,m_refCount-1);
531  if (--m_refCount<=0)
532  {
534  delete this;
535  }
536 }
537 
539 {
540  return new SectionIterator(m_sections);
541 }
542 
544 {
546  if (ml==0) return 0;
547  return new MemberIterator(*ml);
548 }
549 
551 {
552  m_inheritanceGraph = new GraphHandler(this,"inheritancegraph");
554 }
555 
557 {
558  m_collaborationGraph = new GraphHandler(this,"collaborationgraph");
560 }
561 
563 {
564  m_includeDependencyGraph = new GraphHandler(this,"incdepgraph");
566 }
567 
569 {
570  m_includedByDependencyGraph = new GraphHandler(this,"invincdepgraph");
572 }
573 
575 {
576  return m_brief;
577 }
578 
580 {
581  return m_detailed;
582 }
583 
584 IMember *CompoundHandler::memberById(const char *id) const
585 {
586  return (IFunction*)m_memberDict[id];
587 }
588 
590 {
591  return m_inheritanceGraph;
592 }
593 
595 {
596  return m_collaborationGraph;
597 }
598 
600 {
602 }
603 
605 {
607 }
608 
610 {
612 }
613 
615 {
617 }
618 
620 {
622 }
623 
625 {
626  return m_programListing;
627 }
628 
630 {
631  return new IncludeIterator(m_includes);
632 }
633 
635 {
636  return new IncludeIterator(m_includedBy);
637 }
638 
640 {
642 }
643 
645 {
646  return m_titleHandler;
647 }
648 
650 {
651  return m_members ? m_members->members() : 0;
652 }
653 
654 
StringImpl m_defBodyFile
IGraph * collaborationGraph() const
QList< IncludeHandler > m_includedBy
TitleHandler * m_titleHandler
The interface to a class in the object model.
Definition: doxmlintf.h:968
virtual void startInnerPage(const QXmlAttributes &attrib)
ISectionIterator * sections() const
virtual void endCompound()
IGraph * includeDependencyGraph() const
IIncludeIterator * includedBy() const
GraphHandler * m_inheritanceGraph
MainHandler * m_mainHandler
StringImpl m_kindString
void insertMember(MemberHandler *mh)
const MainHandler * m_mainHandler
virtual void startInnerNamespace(const QXmlAttributes &attrib)
CompoundKind kind() const
virtual void toLast()
virtual ~IncludeHandler()
virtual void startTemplateParamList(const QXmlAttributes &attrib)
virtual void startCollaborationGraph(const QXmlAttributes &attrib)
virtual ~CompoundHandler()
virtual const IString * id() const
CompoundKind m_kind
virtual void startIncludeDependencyGraph(const QXmlAttributes &attrib)
void append(const type *d)
Definition: qlist.h:73
StringImpl m_protection
virtual void toFirst()
virtual void startIncludes(const QXmlAttributes &attrib)
virtual ICompound * current() const
virtual void toNext()
bool parse(const QXmlInputSource &input)
Definition: qxml.cpp:2077
virtual const char * latin1() const =0
virtual void startTemplateParamList(const QXmlAttributes &attrib)
The interface to a struct in the object model.
Definition: doxmlintf.h:992
Interface to a directory in the object model.
Definition: doxmlintf.h:1074
const bool FALSE
Definition: qglobal.h:370
virtual IMemberReferenceIterator * members() const
Definition: loamhandler.cpp:72
virtual void startIncludedByDependencyGraph(const QXmlAttributes &attrib)
int columnNumber() const
Definition: qxml.cpp:231
QList< SectionHandler > m_sections
virtual ~CompoundTypeMap()
QList< QString > m_innerCompounds
const IString * kindString() const
void startInclude(const QXmlAttributes &attrib)
IDocRoot * detailedDescription() const
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
virtual void startBriefDesc(const QXmlAttributes &attrib)
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
The interface to a namespace in the object model.
Definition: doxmlintf.h:1030
virtual void startCompound(const QXmlAttributes &attrib)
QString value(int index) const
Definition: qxml.cpp:664
virtual void startIncludedBy(const QXmlAttributes &attrib)
void startGraph(const QXmlAttributes &attrib)
ICompound * toICompound() const
virtual void startTitle(const QXmlAttributes &attrib)
ParamIterator * templateParams()
Definition: paramhandler.h:95
IRelatedCompoundIterator * baseCompounds() const
bool parseXML(const char *compId)
The interface to a file in the object model.
Definition: doxmlintf.h:1038
The QXmlSimpleReader class provides an implementation of a simple XML reader (i.e. parser).
Definition: qxml.h:238
IGraph * includedByDependencyGraph() const
IParamIterator * templateParameters() const
virtual void startTitle(const QXmlAttributes &attrib)
Definition: dochandler.cpp:868
const IString * name() const
const char * data() const
Definition: qstring.h:542
type * getLast() const
Definition: qlist.h:96
DocHandler * m_detailed
void setContentHandler(QXmlContentHandler *handler)
Definition: qxml.cpp:2043
bool exists() const
Definition: qfile.cpp:183
void initialize(MainHandler *mh)
virtual void startSection(const QXmlAttributes &attrib)
QDict< int > m_map
StringImpl m_name
virtual void startDoc(const QXmlAttributes &attrib)
virtual void setDelegate(QXmlDefaultHandler *delegate)=0
virtual void startProgramListing(const QXmlAttributes &attrib)
virtual void endSuperClass()
void compoundhandler_exit()
Node representing a documentation block.
Definition: dochandler.h:1315
GraphHandler * m_includeDependencyGraph
const IDocTitle * title() const
ICompound::CompoundKind map(const QString &s)
void setName(const QString &str)
QDict< QList< MemberHandler > > m_memberNameDict
IDocProgramListing * source() const
type * current() const
Definition: qlist.h:146
QList< IncludeHandler > m_includes
QDict< MemberHandler > m_memberDict
virtual void toPrev()
virtual void endCompoundName()
static CompoundTypeMap * s_typeMap
IDocRoot * briefDescription() const
const IString * id() const
GraphHandler * m_includedByDependencyGraph
virtual ~CompoundIdIterator()
The interface to a compound in the object model.
Definition: doxmlintf.h:868
virtual void startLocation(const QXmlAttributes &attrib)
IGraph * inheritanceGraph() const
virtual void startSection(const QXmlAttributes &attrib)
friend class RelatedCompound
DocHandler * m_brief
QString stripWhiteSpace() const
Definition: qstring.cpp:13438
The QFile class is an I/O device that operates on files.
Definition: qfile.h:50
The interface to a page in the object model.
Definition: doxmlintf.h:1067
StringImpl m_refId
virtual void startDetailedDesc(const QXmlAttributes &attrib)
IMember * memberById(const char *id) const
GraphHandler * m_collaborationGraph
void compoundhandler_init()
virtual void startInnerClass(const QXmlAttributes &attrib)
The interface to a union in the object model.
Definition: doxmlintf.h:1006
The interface to a Java/IDL interface in the object model.
Definition: doxmlintf.h:1014
ICompoundIterator * nestedCompounds() const
IBaseHandler * m_parent
virtual void startProgramListing(const QXmlAttributes &attrib)
virtual void startInnerFile(const QXmlAttributes &attrib)
void unloadCompound(CompoundHandler *ch)
int toInt(bool *ok=0, int base=10) const
Definition: qstring.cpp:14045
bool error(const QXmlParseException &)
TemplateParamListHandler * m_templateParamList
QList< RelatedCompound > m_subClasses
The QXmlAttributes class provides XML attributes.
Definition: qxml.h:128
ListOfAllMembersHandler * m_members
virtual void startListOfAllMembers(const QXmlAttributes &attrib)
Definition: loamhandler.cpp:60
type * operator--()
Definition: qlist.h:150
virtual const IString * name() const
void initialize(MainHandler *m)
IRelatedCompoundIterator * derivedCompounds() const
QList< RelatedCompound > m_superClasses
StringImpl m_defFile
CompoundIdIterator(const MainHandler *m, const QList< QString > &list)
virtual void startSuperClass(const QXmlAttributes &attrib)
virtual void startInnerDir(const QXmlAttributes &attrib)
void addStartHandler(const char *key)
Definition: basehandler.h:91
virtual void startListOfAllMembers(const QXmlAttributes &attrib)
bool fatalError(const QXmlParseException &exception)
IMemberReferenceIterator * members() const
The QXmlInputSource class is the source where XML data is read from.
Definition: qxml.h:162
virtual ICompound * compound() const
IIncludeIterator * includes() const
The interface to a group in the object model.
Definition: doxmlintf.h:1055
QCString utf8() const
Definition: qstring.cpp:14507
virtual void endSubClass()
Node representing a program listing.
Definition: dochandler.h:871
CompoundHandler(const QString &dirName)
void setAutoDelete(bool enable)
Definition: qlist.h:99
void initialize(CompoundHandler *c)
int lineNumber() const
Definition: qxml.cpp:238
type * toLast()
Definition: qlist.h:136
virtual void release()
static QCString * s
Definition: config.cpp:1042
The interface to a Java/IDL exception in the object model.
Definition: doxmlintf.h:1024
def parent(G, child, parent_type)
Definition: graph.py:67
const bool TRUE
Definition: qglobal.h:371
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
virtual void startInnerGroup(const QXmlAttributes &attrib)
void initialize(MainHandler *mh)
Definition: loamhandler.cpp:18
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
bool warning(const QXmlParseException &)
ProgramListingHandler * m_programListing
#define ASSERT(x)
Definition: qglobal.h:590
virtual void startSubClass(const QXmlAttributes &attrib)
IMemberIterator * memberByName(const char *name) const
type * toFirst()
Definition: qlist.h:135
virtual void startInheritanceGraph(const QXmlAttributes &attrib)
IncludeHandler(IBaseHandler *parent, const char *endtag)