Chameleon

Chameleon Svn Source Tree

Root/branches/xZenu/src/util/doxygen/addon/doxmlparser/src/compoundhandler.cpp

Source at commit 1322 created 12 years 8 months ago.
By meklort, Add doxygen to utils folder
1/******************************************************************************
2 *
3 * $Id: compoundhandler.cpp,v 1.33 2002/10/13 21:01:58 dimitri Exp $
4 *
5 *
6 * Copyright (C) 1997-2006 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
28IncludeHandler::IncludeHandler(IBaseHandler *parent,const char *endtag) :
29 m_parent(parent)
30{
31 addEndHandler(endtag,this,&IncludeHandler::endInclude);
32}
33
34IncludeHandler::~IncludeHandler()
35{
36}
37
38void IncludeHandler::startInclude(const QXmlAttributes &attrib)
39{
40 m_curString = "";
41 m_refId = attrib.value("refid");
42 m_isLocal = attrib.value("local")=="yes";
43 m_parent->setDelegate(this);
44}
45
46void IncludeHandler::endInclude()
47{
48 m_name = m_curString;
49 m_parent->setDelegate(0);
50 debug(2,"Found include %s\n",m_name.data());
51}
52
53//----------------------------------------------------------------------------
54
55class CompoundIdIterator : public ICompoundIterator,
56 public QListIterator<QString>
57{
58 public:
59 CompoundIdIterator(const MainHandler *m,const QList<QString> &list) :
60 QListIterator<QString>(list), m_mainHandler(m) {}
61 virtual ~CompoundIdIterator() {}
62
63 virtual void toFirst()
64 {
65 QListIterator<QString>::toFirst();
66 }
67 virtual void toLast()
68 {
69 QListIterator<QString>::toLast();
70 }
71 virtual void toNext()
72 {
73 QListIterator<QString>::operator++();
74 }
75 virtual void toPrev()
76 {
77 QListIterator<QString>::operator--();
78 }
79 virtual ICompound *current() const
80 {
81 QString *id = QListIterator<QString>::current();
82 return id ? m_mainHandler->compoundById(*id) : 0;
83 }
84 virtual void release()
85 { delete this; }
86
87 private:
88 const MainHandler *m_mainHandler;
89};
90
91//----------------------------------------------------------------------------
92
93ICompound *RelatedCompound::compound() const
94{
95 return m_parent->m_mainHandler->compoundById(m_id);
96}
97
98//----------------------------------------------------------------------------
99
100class CompoundErrorHandler : public QXmlErrorHandler
101{
102 public:
103 virtual ~CompoundErrorHandler() {}
104 bool warning( const QXmlParseException & )
105 {
106 return FALSE;
107 }
108 bool error( const QXmlParseException & )
109 {
110 return FALSE;
111 }
112 bool fatalError( const QXmlParseException &exception )
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:
122 QString errorMsg;
123};
124
125//----------------------------------------------------------------------------
126
127class CompoundTypeMap
128{
129 public:
130 CompoundTypeMap()
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 }
147 virtual ~CompoundTypeMap()
148 {
149 }
150 ICompound::CompoundKind map(const QString &s)
151 {
152 int *val = m_map.find(s);
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
164static CompoundTypeMap *s_typeMap;
165
166void compoundhandler_init()
167{
168 s_typeMap = new CompoundTypeMap;
169}
170
171void compoundhandler_exit()
172{
173 delete s_typeMap;
174}
175
176//----------------------------------------------------------------------------
177
178CompoundHandler::CompoundHandler(const QString &xmlDir)
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{
195 m_superClasses.setAutoDelete(TRUE);
196 m_subClasses.setAutoDelete(TRUE);
197 m_sections.setAutoDelete(TRUE);
198 m_memberNameDict.setAutoDelete(TRUE);
199 m_innerCompounds.setAutoDelete(TRUE);
200 m_includes.setAutoDelete(TRUE);
201 m_includedBy.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
212 addStartHandler("title",this,&CompoundHandler::startTitle);
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
220 addStartHandler("includes",this,&CompoundHandler::startIncludes);
221 addStartHandler("includedby",this,&CompoundHandler::startIncludedBy);
222
223 addStartHandler("incdepgraph",this,&CompoundHandler::startIncludeDependencyGraph);
224
225 addStartHandler("invincdepgraph",this,&CompoundHandler::startIncludedByDependencyGraph);
226
227 addStartHandler("innerdir",this,&CompoundHandler::startInnerDir);
228 addEndHandler("innerdir");
229
230 addStartHandler("innerfile",this,&CompoundHandler::startInnerFile);
231 addEndHandler("innerfile");
232
233 addStartHandler("innerclass",this,&CompoundHandler::startInnerClass);
234 addEndHandler("innerclass");
235
236 addStartHandler("innernamespace",this,&CompoundHandler::startInnerNamespace);
237 addEndHandler("innernamespace");
238
239 addStartHandler("innerpage",this,&CompoundHandler::startInnerPage);
240 addEndHandler("innerpage");
241
242 addStartHandler("innergroup",this,&CompoundHandler::startInnerGroup);
243 addEndHandler("innergroup");
244
245 addStartHandler("templateparamlist",this,&CompoundHandler::startTemplateParamList);
246
247 addStartHandler("sectiondef",this,&CompoundHandler::startSection);
248
249 addStartHandler("briefdescription",this,&CompoundHandler::startBriefDesc);
250
251 addStartHandler("detaileddescription",this,&CompoundHandler::startDetailedDesc);
252
253 addStartHandler("inheritancegraph",this,&CompoundHandler::startInheritanceGraph);
254
255 addStartHandler("collaborationgraph",this,&CompoundHandler::startCollaborationGraph);
256
257 addStartHandler("programlisting",this,&CompoundHandler::startProgramListing);
258
259 addStartHandler("location",this,&CompoundHandler::startLocation);
260 addEndHandler("location");
261
262 addStartHandler("listofallmembers",this,&CompoundHandler::startListOfAllMembers);
263}
264
265CompoundHandler::~CompoundHandler()
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;
274 delete m_includeDependencyGraph;
275 delete m_includedByDependencyGraph;
276 delete m_templateParamList;
277 delete m_members;
278}
279
280void CompoundHandler::startSection(const QXmlAttributes& attrib)
281{
282 SectionHandler *sectHandler = new SectionHandler(this);
283 sectHandler->startSection(attrib);
284 m_sections.append(sectHandler);
285}
286
287void CompoundHandler::startBriefDesc(const QXmlAttributes& attrib)
288{
289 DocHandler *docHandler = new DocHandler(this);
290 docHandler->startDoc(attrib);
291 m_brief = docHandler;
292}
293
294void CompoundHandler::startDetailedDesc(const QXmlAttributes& attrib)
295{
296 DocHandler *docHandler = new DocHandler(this);
297 docHandler->startDoc(attrib);
298 m_detailed = docHandler;
299}
300
301void CompoundHandler::startProgramListing(const QXmlAttributes& attrib)
302{
303 ProgramListingHandler *plHandler = new ProgramListingHandler(this);
304 plHandler->startProgramListing(attrib);
305 m_programListing = plHandler;
306}
307
308void CompoundHandler::startIncludes(const QXmlAttributes& attrib)
309{
310 IncludeHandler *inc = new IncludeHandler(this,"includes");
311 m_includes.append(inc);
312 inc->startInclude(attrib);
313}
314
315void CompoundHandler::startIncludedBy(const QXmlAttributes& attrib)
316{
317 IncludeHandler *inc = new IncludeHandler(this,"includedby");
318 m_includedBy.append(inc);
319 inc->startInclude(attrib);
320}
321
322void CompoundHandler::startCompound(const QXmlAttributes& attrib)
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
331void CompoundHandler::endCompound()
332{
333 debug(2,"endCompound()\n");
334}
335
336void CompoundHandler::startLocation(const QXmlAttributes& attrib)
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
345void CompoundHandler::endCompoundName()
346{
347 m_name = m_curString.stripWhiteSpace();
348 debug(2,"Compound name `%s'\n",m_name.data());
349}
350
351void CompoundHandler::startInnerClass(const QXmlAttributes& attrib)
352{
353 m_innerCompounds.append(new QString(attrib.value("refid")));
354}
355
356void CompoundHandler::startInnerNamespace(const QXmlAttributes& attrib)
357{
358 m_innerCompounds.append(new QString(attrib.value("refid")));
359}
360
361void CompoundHandler::startInnerFile(const QXmlAttributes& attrib)
362{
363 m_innerCompounds.append(new QString(attrib.value("refid")));
364}
365
366void CompoundHandler::startInnerGroup(const QXmlAttributes& attrib)
367{
368 m_innerCompounds.append(new QString(attrib.value("refid")));
369}
370
371void CompoundHandler::startInnerPage(const QXmlAttributes& attrib)
372{
373 m_innerCompounds.append(new QString(attrib.value("refid")));
374}
375
376void CompoundHandler::startInnerDir(const QXmlAttributes& attrib)
377{
378 m_innerCompounds.append(new QString(attrib.value("refid")));
379}
380
381void CompoundHandler::startTemplateParamList(const QXmlAttributes& attrib)
382{
383 m_templateParamList = new TemplateParamListHandler(this);
384 m_templateParamList->startTemplateParamList(attrib);
385}
386
387void CompoundHandler::startListOfAllMembers(const QXmlAttributes& attrib)
388{
389 m_members = new ListOfAllMembersHandler(this);
390 m_members->startListOfAllMembers(attrib);
391}
392
393void CompoundHandler::startSuperClass(const QXmlAttributes& attrib)
394{
395 IRelatedCompound::Protection prot = IRelatedCompound::Public;
396 QString protString = attrib.value("prot");
397 if (protString=="protected")
398 {
399 prot = IRelatedCompound::Protected;
400 }
401 else if (protString=="private")
402 {
403 prot = IRelatedCompound::Private;
404 }
405 IRelatedCompound::Kind kind = IRelatedCompound::Normal;
406 QString kindString = attrib.value("virt");
407 if (kindString=="virtual") kind = IRelatedCompound::Virtual;
408
409 RelatedCompound *sc=new RelatedCompound(
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());
419 m_superClasses.append(sc);
420 m_curString = "";
421}
422
423void CompoundHandler::endSuperClass()
424{
425 m_superClasses.getLast()->setName(m_curString);
426}
427
428void CompoundHandler::startSubClass(const QXmlAttributes& attrib)
429{
430 IRelatedCompound::Protection prot = IRelatedCompound::Public;
431 QString protString = attrib.value("prot");
432 if (protString=="protected") prot = IRelatedCompound::Protected;
433 else if (protString=="private") prot = IRelatedCompound::Private;
434
435 IRelatedCompound::Kind kind = IRelatedCompound::Normal;
436 QString kindString = attrib.value("virt");
437 if (kindString=="virtual") kind = IRelatedCompound::Virtual;
438
439 RelatedCompound *sc = new RelatedCompound(
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
453void CompoundHandler::endSubClass()
454{
455 m_subClasses.getLast()->setName(m_curString);
456}
457
458void CompoundHandler::startTitle(const QXmlAttributes& attrib)
459{
460 ASSERT(m_titleHandler==0);
461 m_titleHandler = new TitleHandler(this);
462 m_titleHandler->startTitle(attrib);
463}
464
465bool 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
478void CompoundHandler::initialize(MainHandler *mh)
479{
480 m_mainHandler = mh;
481 QListIterator<SectionHandler> msi(m_sections);
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
493void CompoundHandler::insertMember(MemberHandler *mh)
494{
495 m_memberDict.insert(mh->id()->latin1(),mh);
496 mh->initialize(m_mainHandler);
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
506ICompound *CompoundHandler::toICompound() const
507{
508 switch (m_kind)
509 {
510 case IClass::Class: return (IClass *)this;
511 case IStruct::Struct: return (IStruct *)this;
512 case IUnion::Union: return (IUnion *)this;
513 case IException::Exception: return (IException *)this;
514 case IInterface::Interface: return (IInterface *)this;
515 case INamespace::Namespace: return (INamespace *)this;
516 case IFile::File: return (IFile *)this;
517 case IGroup::Group: return (IGroup *)this;
518 case IPage::Page: return (IPage *)this;
519 default: return 0;
520 }
521 return 0;
522}
523
524void CompoundHandler::release()
525{
526 debug(2,"CompoundHandler::release() %d->%d\n",m_refCount,m_refCount-1);
527 if (--m_refCount<=0)
528 {
529 m_mainHandler->unloadCompound(this);
530 delete this;
531 }
532}
533
534ISectionIterator *CompoundHandler::sections() const
535{
536 return new SectionIterator(m_sections);
537}
538
539IMemberIterator *CompoundHandler::memberByName(const char *name) const
540{
541 QList<MemberHandler> *ml = m_memberNameDict[name];
542 if (ml==0) return 0;
543 return new MemberIterator(*ml);
544}
545
546void CompoundHandler::startInheritanceGraph(const QXmlAttributes &attrib)
547{
548 m_inheritanceGraph = new GraphHandler(this,"inheritancegraph");
549 m_inheritanceGraph->startGraph(attrib);
550}
551
552void CompoundHandler::startCollaborationGraph(const QXmlAttributes &attrib)
553{
554 m_collaborationGraph = new GraphHandler(this,"collaborationgraph");
555 m_collaborationGraph->startGraph(attrib);
556}
557
558void CompoundHandler::startIncludeDependencyGraph(const QXmlAttributes &attrib)
559{
560 m_includeDependencyGraph = new GraphHandler(this,"incdepgraph");
561 m_includeDependencyGraph->startGraph(attrib);
562}
563
564void CompoundHandler::startIncludedByDependencyGraph(const QXmlAttributes &attrib)
565{
566 m_includedByDependencyGraph = new GraphHandler(this,"invincdepgraph");
567 m_includedByDependencyGraph->startGraph(attrib);
568}
569
570IDocRoot *CompoundHandler::briefDescription() const
571{
572 return m_brief;
573}
574
575IDocRoot *CompoundHandler::detailedDescription() const
576{
577 return m_detailed;
578}
579
580IMember *CompoundHandler::memberById(const char *id) const
581{
582 return (IFunction*)m_memberDict[id];
583}
584
585IGraph *CompoundHandler::inheritanceGraph() const
586{
587 return m_inheritanceGraph;
588}
589
590IGraph *CompoundHandler::collaborationGraph() const
591{
592 return m_collaborationGraph;
593}
594
595IGraph *CompoundHandler::includeDependencyGraph() const
596{
597 return m_includeDependencyGraph;
598}
599
600IGraph *CompoundHandler::includedByDependencyGraph() const
601{
602 return m_includedByDependencyGraph;
603}
604
605IRelatedCompoundIterator *CompoundHandler::baseCompounds() const
606{
607 return new RelatedCompoundIterator(m_superClasses);
608}
609
610IRelatedCompoundIterator *CompoundHandler::derivedCompounds() const
611{
612 return new RelatedCompoundIterator(m_subClasses);
613}
614
615ICompoundIterator *CompoundHandler::nestedCompounds() const
616{
617 return new CompoundIdIterator(m_mainHandler,m_innerCompounds);
618}
619
620IDocProgramListing *CompoundHandler::source() const
621{
622 return m_programListing;
623}
624
625IIncludeIterator *CompoundHandler::includes() const
626{
627 return new IncludeIterator(m_includes);
628}
629
630IIncludeIterator *CompoundHandler::includedBy() const
631{
632 return new IncludeIterator(m_includedBy);
633}
634
635IParamIterator *CompoundHandler::templateParameters() const
636{
637 return m_templateParamList ? m_templateParamList->templateParams() : 0;
638}
639
640const IDocTitle *CompoundHandler::title() const
641{
642 return m_titleHandler;
643}
644
645IMemberReferenceIterator *CompoundHandler::members() const
646{
647 return m_members ? m_members->members() : 0;
648}
649
650
651

Archive Download this file

Revision: 1322