|
1 /****************************************************************************** |
|
2 * |
|
3 * |
|
4 * |
|
5 * Copyright (C) 1997-2008 by Dimitri van Heesch. |
|
6 * |
|
7 * Permission to use, copy, modify, and distribute this software and its |
|
8 * documentation under the terms of the GNU General Public License is hereby |
|
9 * granted. No representations are made about the suitability of this software |
|
10 * for any purpose. It is provided "as is" without express or implied warranty. |
|
11 * See the GNU General Public License for more details. |
|
12 * |
|
13 * Documents produced by Doxygen are derivative works derived from the |
|
14 * input used in their production; they are not affected by this license. |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef CLASSDEF_H |
|
19 #define CLASSDEF_H |
|
20 |
|
21 #include "qtbc.h" |
|
22 #include <qlist.h> |
|
23 #include <qdict.h> |
|
24 #include <qstrlist.h> |
|
25 |
|
26 //#include "entry.h" |
|
27 #include "memberlist.h" |
|
28 #include "definition.h" |
|
29 #include "sortdict.h" |
|
30 |
|
31 class MemberDict; |
|
32 class ClassList; |
|
33 class ClassSDict; |
|
34 class OutputList; |
|
35 class FileDef; |
|
36 class BaseClassList; |
|
37 class NamespaceDef; |
|
38 class MemberDef; |
|
39 class ExampleSDict; |
|
40 class MemberNameInfoSDict; |
|
41 class UsesClassDict; |
|
42 class MemberGroupSDict; |
|
43 class QTextStream; |
|
44 class PackageDef; |
|
45 class GroupDef; |
|
46 class StringDict; |
|
47 struct IncludeInfo; |
|
48 class ClassDefImpl; |
|
49 |
|
50 /*! \brief This class contains all information about a compound. |
|
51 * |
|
52 * A compound can be a class, struct, union, interface, or exception. |
|
53 * \note This class should be renamed to CompoundDef |
|
54 */ |
|
55 class ClassDef : public Definition |
|
56 { |
|
57 public: |
|
58 /*! The various compound types */ |
|
59 enum CompoundType { Class, //=Entry::CLASS_SEC, |
|
60 Struct, //=Entry::STRUCT_SEC, |
|
61 Union, //=Entry::UNION_SEC, |
|
62 Interface, //=Entry::INTERFACE_SEC, |
|
63 Protocol, //=Entry::PROTOCOL_SEC, |
|
64 Category, //=Entry::CATEGORY_SEC, |
|
65 Exception //=Entry::EXCEPTION_SEC |
|
66 }; |
|
67 |
|
68 /*! Creates a new compound definition. |
|
69 * \param fileName full path and file name in which this compound was |
|
70 * found. |
|
71 * \param startLine line number where the definition of this compound |
|
72 * starts. |
|
73 * \param name the name of this compound (including scope) |
|
74 * \param ct the kind of Compound |
|
75 * \param ref the tag file from which this compound is extracted |
|
76 * or 0 if the compound doesn't come from a tag file |
|
77 * \param fName the file name as found in the tag file. |
|
78 * This overwrites the file that doxygen normally |
|
79 * generates based on the compound type & name. |
|
80 * \param isSymbol If TRUE this class name is added as a publicly |
|
81 * visible (and referencable) symbol. |
|
82 */ |
|
83 ClassDef(const char *fileName,int startLine, |
|
84 const char *name,CompoundType ct, |
|
85 const char *ref=0,const char *fName=0, |
|
86 bool isSymbol=TRUE); |
|
87 /*! Destroys a compound definition. */ |
|
88 ~ClassDef(); |
|
89 |
|
90 //----------------------------------------------------------------------------------- |
|
91 // --- getters |
|
92 //----------------------------------------------------------------------------------- |
|
93 |
|
94 /*! Used for RTTI, this is a class */ |
|
95 DefType definitionType() const { return TypeClass; } |
|
96 |
|
97 /*! Returns the unique base name (without extension) of the class's file on disk */ |
|
98 QCString getOutputFileBase() const; |
|
99 QCString getInstanceOutputFileBase() const; |
|
100 QCString getFileBase() const; |
|
101 |
|
102 /*! Returns the base name for the source code file */ |
|
103 QCString getSourceFileBase() const; |
|
104 |
|
105 /*! If this class originated from a tagfile, this will return the tag file reference */ |
|
106 QCString getReference() const; |
|
107 |
|
108 /*! Returns TRUE if this class is imported via a tag file */ |
|
109 bool isReference() const; |
|
110 |
|
111 /*! Returns TRUE if this is a local class definition, see EXTRACT_LOCAL_CLASSES */ |
|
112 bool isLocal() const; |
|
113 |
|
114 /*! returns the classes nested into this class */ |
|
115 ClassSDict *getInnerClasses(); |
|
116 |
|
117 /*! returns TRUE if this class has documentation */ |
|
118 bool hasDocumentation() const; |
|
119 |
|
120 /*! Returns the name as it is appears in the documentation */ |
|
121 QCString displayName() const; |
|
122 |
|
123 /*! Returns the type of compound this is, i.e. class/struct/union/.. */ |
|
124 CompoundType compoundType() const; |
|
125 |
|
126 /*! Returns the type of compound as a string */ |
|
127 QCString compoundTypeString() const; |
|
128 |
|
129 /*! Returns the list of base classes from which this class directly |
|
130 * inherits. |
|
131 */ |
|
132 BaseClassList *baseClasses() const; |
|
133 |
|
134 /*! Returns the list of sub classes that directly derive from this class |
|
135 */ |
|
136 BaseClassList *subClasses() const; |
|
137 |
|
138 /*! Returns a dictionary of all members. This includes any inherited |
|
139 * members. Members are sorted alphabetically. |
|
140 */ |
|
141 MemberNameInfoSDict *memberNameInfoSDict() const; |
|
142 |
|
143 /*! Return the protection level (Public,Protected,Private) in which |
|
144 * this compound was found. |
|
145 */ |
|
146 Protection protection() const; |
|
147 |
|
148 /*! returns TRUE iff a link is possible to this item within this project. |
|
149 */ |
|
150 bool isLinkableInProject() const; |
|
151 |
|
152 /*! return TRUE iff a link to this class is possible (either within |
|
153 * this project, or as a cross-reference to another project). |
|
154 */ |
|
155 bool isLinkable() const; |
|
156 |
|
157 /*! the class is visible in a class diagram, or class hierarchy */ |
|
158 bool isVisibleInHierarchy(); |
|
159 |
|
160 /*! Returns the template arguments of this class |
|
161 * Will return 0 if not applicable. |
|
162 */ |
|
163 ArgumentList *templateArguments() const; |
|
164 |
|
165 /*! Returns the namespace this compound is in, or 0 if it has a global |
|
166 * scope. |
|
167 */ |
|
168 NamespaceDef *getNamespaceDef() const; |
|
169 |
|
170 /*! Returns the file in which this compound's definition can be found. |
|
171 * Should not return 0 (but it might be a good idea to check anyway). |
|
172 */ |
|
173 FileDef *getFileDef() const; |
|
174 |
|
175 /*! Returns the Java package this class is in or 0 if not applicable. |
|
176 */ |
|
177 |
|
178 MemberDef *getMemberByName(const QCString &) const; |
|
179 |
|
180 /*! Returns TRUE iff \a bcd is a direct or indirect base class of this |
|
181 * class. This function will recusively traverse all branches of the |
|
182 * inheritance tree. |
|
183 */ |
|
184 bool isBaseClass(ClassDef *bcd,bool followInstances,int level=0); |
|
185 |
|
186 /*! returns TRUE iff \a md is a member of this class or of the |
|
187 * the public/protected members of a base class |
|
188 */ |
|
189 bool isAccessibleMember(MemberDef *md); |
|
190 |
|
191 /*! Returns a sorted dictionary with all template instances found for |
|
192 * this template class. Returns 0 if not a template or no instances. |
|
193 */ |
|
194 QDict<ClassDef> *getTemplateInstances() const; |
|
195 |
|
196 /*! Returns the template master of which this class is an instance. |
|
197 * Returns 0 if not applicable. |
|
198 */ |
|
199 ClassDef *templateMaster() const; |
|
200 |
|
201 /*! Returns TRUE if this class is a template */ |
|
202 bool isTemplate() const; |
|
203 |
|
204 IncludeInfo *includeInfo() const; |
|
205 |
|
206 UsesClassDict *usedImplementationClasses() const; |
|
207 |
|
208 UsesClassDict *usedByImplementationClasses() const; |
|
209 |
|
210 UsesClassDict *usedInterfaceClasses() const; |
|
211 |
|
212 bool isTemplateArgument() const; |
|
213 |
|
214 /*! Returns the definition of a nested compound if |
|
215 * available, or 0 otherwise. |
|
216 * @param name The name of the nested compound |
|
217 */ |
|
218 virtual Definition *findInnerCompound(const char *name); |
|
219 |
|
220 /*! Returns the template parameter lists that form the template |
|
221 * declaration of this class. |
|
222 * |
|
223 * Example: <code>template<class T> class TC {};</code> |
|
224 * will return a list with one ArgumentList containing one argument |
|
225 * with type="class" and name="T". |
|
226 */ |
|
227 void getTemplateParameterLists(QList<ArgumentList> &lists) const; |
|
228 |
|
229 QCString qualifiedNameWithTemplateParameters( |
|
230 QList<ArgumentList> *actualParams=0) const; |
|
231 |
|
232 /*! Returns TRUE if there is at least one pure virtual member in this |
|
233 * class. |
|
234 */ |
|
235 bool isAbstract() const; |
|
236 |
|
237 /*! Returns TRUE if this class is implemented in Objective-C */ |
|
238 bool isObjectiveC() const; |
|
239 |
|
240 /*! Returns the class of which this is a category (Objective-C only) */ |
|
241 ClassDef *categoryOf() const; |
|
242 |
|
243 /*! Returns the name of the class including outer classes, but not |
|
244 * including namespaces. |
|
245 */ |
|
246 QCString className() const; |
|
247 |
|
248 /*! Returns the members in the list identified by \a lt */ |
|
249 MemberList *getMemberList(MemberList::ListType lt); |
|
250 |
|
251 /*! Returns the list containing the list of members sorted per type */ |
|
252 const QList<MemberList> &getMemberLists() const; |
|
253 |
|
254 /*! Returns the member groups defined for this class */ |
|
255 MemberGroupSDict *getMemberGroupSDict() const; |
|
256 |
|
257 QDict<int> *getTemplateBaseClassNames() const; |
|
258 |
|
259 ClassDef *getVariableInstance(const char *templSpec); |
|
260 |
|
261 bool isUsedOnly() const; |
|
262 |
|
263 //----------------------------------------------------------------------------------- |
|
264 // --- setters ---- |
|
265 //----------------------------------------------------------------------------------- |
|
266 |
|
267 void insertBaseClass(ClassDef *,const char *name,Protection p,Specifier s,const char *t=0); |
|
268 void insertSubClass(ClassDef *,Protection p,Specifier s,const char *t=0); |
|
269 void setIncludeFile(FileDef *fd,const char *incName,bool local,bool force); |
|
270 void insertMember(MemberDef *); |
|
271 void insertUsedFile(const char *); |
|
272 bool addExample(const char *anchor,const char *name, const char *file); |
|
273 void mergeCategory(ClassDef *category); |
|
274 void setNamespace(NamespaceDef *nd); |
|
275 void setFileDef(FileDef *fd); |
|
276 void setSubGrouping(bool enabled); |
|
277 void setProtection(Protection p); |
|
278 void setGroupDefForAllMembers(GroupDef *g,Grouping::GroupPri_t pri,const QCString &fileName,int startLine,bool hasDocs); |
|
279 void addInnerCompound(Definition *d); |
|
280 ClassDef *insertTemplateInstance(const QCString &fileName,int startLine, |
|
281 const QCString &templSpec,bool &freshInstance); |
|
282 void addUsedClass(ClassDef *cd,const char *accessName); |
|
283 void addUsedByClass(ClassDef *cd,const char *accessName); |
|
284 void setIsStatic(bool b); |
|
285 void setIsObjectiveC(bool b); |
|
286 void setCompoundType(CompoundType t); |
|
287 void setClassName(const char *name); |
|
288 |
|
289 void setTemplateArguments(ArgumentList *al); |
|
290 void setTemplateBaseClassNames(QDict<int> *templateNames); |
|
291 void setTemplateMaster(ClassDef *tm); |
|
292 void setTypeConstraints(ArgumentList *al); |
|
293 void addMembersToTemplateInstance(ClassDef *cd,const char *templSpec); |
|
294 void makeTemplateArgument(bool b=TRUE); |
|
295 void setCategoryOf(ClassDef *cd); |
|
296 void setUsedOnly(bool b); |
|
297 |
|
298 //----------------------------------------------------------------------------------- |
|
299 // --- actions ---- |
|
300 //----------------------------------------------------------------------------------- |
|
301 |
|
302 void findSectionsInDocumentation(); |
|
303 void addMembersToMemberGroup(); |
|
304 void addListReferences(); |
|
305 void computeAnchors(); |
|
306 void mergeMembers(); |
|
307 void distributeMemberGroupDocumentation(); |
|
308 void writeDocumentation(OutputList &ol); |
|
309 void writeDocumentationForInnerClasses(OutputList &ol); |
|
310 void writeMemberPages(OutputList &ol); |
|
311 void writeMemberList(OutputList &ol); |
|
312 void writeDeclaration(OutputList &ol,MemberDef *md,bool inGroup); |
|
313 void writeQuickMemberLinks(OutputList &ol,MemberDef *md) const; |
|
314 void reclassifyMember(MemberDef *md,MemberDef::MemberType t); |
|
315 |
|
316 bool visited; |
|
317 |
|
318 protected: |
|
319 void addUsedInterfaceClasses(MemberDef *md,const char *typeStr); |
|
320 bool hasExamples(); |
|
321 bool hasNonReferenceSuperClass(); |
|
322 void showUsedFiles(OutputList &ol); |
|
323 |
|
324 private: |
|
325 void internalInsertMember(MemberDef *md,Protection prot,bool addToAllList); |
|
326 QCString getMemberListFileName() const; |
|
327 void addMemberToList(MemberList::ListType lt,MemberDef *md,bool isBrief); |
|
328 MemberList *createMemberList(MemberList::ListType lt); |
|
329 void writeMemberDeclarations(OutputList &ol,MemberList::ListType lt,const QCString &title, |
|
330 const char *subTitle=0); |
|
331 void writeMemberDocumentation(OutputList &ol,MemberList::ListType lt,const QCString &title); |
|
332 void writePlainMemberDeclaration(OutputList &ol,MemberList::ListType lt,bool inGroup); |
|
333 void writeBriefDescription(OutputList &ol,bool exampleFlag); |
|
334 void writeDetailedDescription(OutputList &ol,const QCString &pageType,bool exampleFlag, |
|
335 const QCString &title); |
|
336 void writeIncludeFiles(OutputList &ol); |
|
337 void writeAllMembersLink(OutputList &ol); |
|
338 void writeInheritanceGraph(OutputList &ol); |
|
339 void writeCollaborationGraph(OutputList &ol); |
|
340 void writeMemberGroups(OutputList &ol); |
|
341 void writeNestedClasses(OutputList &ol,const QCString &title); |
|
342 void startMemberDeclarations(OutputList &ol); |
|
343 void endMemberDeclarations(OutputList &ol); |
|
344 void startMemberDocumentation(OutputList &ol); |
|
345 void endMemberDocumentation(OutputList &ol); |
|
346 void writeAuthorSection(OutputList &ol); |
|
347 |
|
348 ClassDefImpl *m_impl; |
|
349 |
|
350 }; |
|
351 |
|
352 /*! \brief Class that contains information about a usage relation. |
|
353 */ |
|
354 struct UsesClassDef |
|
355 { |
|
356 UsesClassDef(ClassDef *cd) : classDef(cd) |
|
357 { |
|
358 accessors = new QDict<void>(17); |
|
359 containment = TRUE; |
|
360 } |
|
361 ~UsesClassDef() |
|
362 { |
|
363 delete accessors; |
|
364 } |
|
365 void addAccessor(const char *s) |
|
366 { |
|
367 if (accessors->find(s)==0) |
|
368 { |
|
369 accessors->insert(s,(void *)666); |
|
370 } |
|
371 } |
|
372 /*! Class definition that this relation uses. */ |
|
373 ClassDef *classDef; |
|
374 |
|
375 /*! Dictionary of member variable names that form the edge labels of the |
|
376 * usage relation. |
|
377 */ |
|
378 QDict<void> *accessors; |
|
379 |
|
380 /*! Template arguments used for the base class */ |
|
381 QCString templSpecifiers; |
|
382 |
|
383 bool containment; |
|
384 }; |
|
385 |
|
386 /*! \brief Dictionary of usage relations. |
|
387 */ |
|
388 class UsesClassDict : public QDict<UsesClassDef> |
|
389 { |
|
390 public: |
|
391 UsesClassDict(int size) : QDict<UsesClassDef>(size) {} |
|
392 ~UsesClassDict() {} |
|
393 }; |
|
394 |
|
395 /*! \brief Iterator class to iterate over a dictionary of usage relations. |
|
396 */ |
|
397 class UsesClassDictIterator : public QDictIterator<UsesClassDef> |
|
398 { |
|
399 public: |
|
400 UsesClassDictIterator(const QDict<UsesClassDef> &d) |
|
401 : QDictIterator<UsesClassDef>(d) {} |
|
402 ~UsesClassDictIterator() {} |
|
403 }; |
|
404 |
|
405 /*! \brief Class that contains information about an inheritance relation. |
|
406 */ |
|
407 struct BaseClassDef |
|
408 { |
|
409 BaseClassDef(ClassDef *cd,const char *n,Protection p, |
|
410 Specifier v,const char *t) : |
|
411 classDef(cd), usedName(n), prot(p), virt(v), templSpecifiers(t) {} |
|
412 |
|
413 /*! Class definition that this relation inherits from. */ |
|
414 ClassDef *classDef; |
|
415 |
|
416 /*! name used in the inheritance list |
|
417 * (may be a typedef name instead of the class name) |
|
418 */ |
|
419 QCString usedName; |
|
420 |
|
421 /*! Protection level of the inheritance relation: |
|
422 * Public, Protected, or Private |
|
423 */ |
|
424 Protection prot; |
|
425 |
|
426 /*! Virtualness of the inheritance relation: |
|
427 * Normal, or Virtual |
|
428 */ |
|
429 Specifier virt; |
|
430 |
|
431 /*! Template arguments used for the base class */ |
|
432 QCString templSpecifiers; |
|
433 }; |
|
434 |
|
435 /*! \brief list of base classes |
|
436 * |
|
437 * The classes are alphabetically sorted on name if inSort() is used. |
|
438 */ |
|
439 class BaseClassList : public QList<BaseClassDef> |
|
440 { |
|
441 public: |
|
442 ~BaseClassList() {} |
|
443 int compareItems(GCI item1,GCI item2) |
|
444 { |
|
445 ClassDef *c1=((BaseClassDef *)item1)->classDef; |
|
446 ClassDef *c2=((BaseClassDef *)item2)->classDef; |
|
447 if (c1==0 || c2==0) |
|
448 return FALSE; |
|
449 else |
|
450 return stricmp(c1->name(),c2->name()); |
|
451 } |
|
452 }; |
|
453 |
|
454 /*! \brief Iterator for a list of base classes |
|
455 */ |
|
456 class BaseClassListIterator : public QListIterator<BaseClassDef> |
|
457 { |
|
458 public: |
|
459 BaseClassListIterator(const BaseClassList &bcl) : |
|
460 QListIterator<BaseClassDef>(bcl) {} |
|
461 }; |
|
462 |
|
463 #endif |