1 /******************************************************************************
3 * $Id: classdef.h,v 1.39 2001/03/19 19:27:39 root Exp $
5 * Copyright (C) 1997-2012 by Dimitri van Heesch.
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.
13 * Documents produced by Doxygen are derivative works derived from the
14 * input used in their production; they are not affected by this license.
28 #include "memberlist.h"
29 #include "definition.h"
41 class MemberNameInfoSDict;
43 class MemberGroupSDict;
51 /** A model of a compound symbol.
53 * A compound can be a class, struct, union, interface, or exception.
54 * \note This class should be renamed to CompoundDef
56 class ClassDef : public Definition
59 /** The various compound types */
60 enum CompoundType { Class, //=Entry::CLASS_SEC,
61 Struct, //=Entry::STRUCT_SEC,
62 Union, //=Entry::UNION_SEC,
63 Interface, //=Entry::INTERFACE_SEC,
64 Protocol, //=Entry::PROTOCOL_SEC,
65 Category, //=Entry::CATEGORY_SEC,
66 Exception //=Entry::EXCEPTION_SEC
69 /** Creates a new compound definition.
70 * \param fileName full path and file name in which this compound was
72 * \param startLine line number where the definition of this compound
74 * \param name the name of this compound (including scope)
75 * \param ct the kind of Compound
76 * \param ref the tag file from which this compound is extracted
77 * or 0 if the compound doesn't come from a tag file
78 * \param fName the file name as found in the tag file.
79 * This overwrites the file that doxygen normally
80 * generates based on the compound type & name.
81 * \param isSymbol If TRUE this class name is added as a publicly
82 * visible (and referencable) symbol.
83 * \param isJavaEnum If TRUE this class is actually a Java enum.
84 * I didn't add this to CompoundType to avoid having
85 * to adapt all translators.
87 ClassDef(const char *fileName,int startLine,
88 const char *name,CompoundType ct,
89 const char *ref=0,const char *fName=0,
90 bool isSymbol=TRUE,bool isJavaEnum=FALSE);
91 /** Destroys a compound definition. */
94 //-----------------------------------------------------------------------------------
96 //-----------------------------------------------------------------------------------
98 /** Used for RTTI, this is a class */
99 DefType definitionType() const { return TypeClass; }
101 /** Returns the unique base name (without extension) of the class's file on disk */
102 QCString getOutputFileBase() const;
103 QCString getInstanceOutputFileBase() const;
104 QCString getFileBase() const;
106 /** Returns the base name for the source code file */
107 QCString getSourceFileBase() const;
109 /** If this class originated from a tagfile, this will return the tag file reference */
110 QCString getReference() const;
112 /** Returns TRUE if this class is imported via a tag file */
113 bool isReference() const;
115 /** Returns TRUE if this is a local class definition, see EXTRACT_LOCAL_CLASSES */
116 bool isLocal() const;
118 /** returns the classes nested into this class */
119 ClassSDict *getClassSDict();
121 /** returns TRUE if this class has documentation */
122 bool hasDocumentation() const;
124 /** Returns the name as it is appears in the documentation */
125 QCString displayName(bool includeScope=TRUE) const;
127 /** Returns the type of compound this is, i.e. class/struct/union/.. */
128 CompoundType compoundType() const;
130 /** Returns the type of compound as a string */
131 QCString compoundTypeString() const;
133 /** Returns the list of base classes from which this class directly
136 BaseClassList *baseClasses() const;
138 /** Returns the list of sub classes that directly derive from this class
140 BaseClassList *subClasses() const;
142 /** Returns a dictionary of all members. This includes any inherited
143 * members. Members are sorted alphabetically.
145 MemberNameInfoSDict *memberNameInfoSDict() const;
147 /** Return the protection level (Public,Protected,Private) in which
148 * this compound was found.
150 Protection protection() const;
152 /** returns TRUE iff a link is possible to this item within this project.
154 bool isLinkableInProject() const;
156 /** return TRUE iff a link to this class is possible (either within
157 * this project, or as a cross-reference to another project).
159 bool isLinkable() const;
161 /** the class is visible in a class diagram, or class hierarchy */
162 bool isVisibleInHierarchy();
164 /** Returns the template arguments of this class
165 * Will return 0 if not applicable.
167 ArgumentList *templateArguments() const;
169 /** Returns the namespace this compound is in, or 0 if it has a global
172 NamespaceDef *getNamespaceDef() const;
174 /** Returns the file in which this compound's definition can be found.
175 * Should not return 0 (but it might be a good idea to check anyway).
177 FileDef *getFileDef() const;
179 /** Returns the Java package this class is in or 0 if not applicable.
182 MemberDef *getMemberByName(const QCString &) const;
184 /** Returns TRUE iff \a bcd is a direct or indirect base class of this
185 * class. This function will recusively traverse all branches of the
188 bool isBaseClass(ClassDef *bcd,bool followInstances,int level=0);
190 /** returns TRUE iff \a md is a member of this class or of the
191 * the public/protected members of a base class
193 bool isAccessibleMember(MemberDef *md);
195 /** Returns a sorted dictionary with all template instances found for
196 * this template class. Returns 0 if not a template or no instances.
198 QDict<ClassDef> *getTemplateInstances() const;
200 /** Returns the template master of which this class is an instance.
201 * Returns 0 if not applicable.
203 ClassDef *templateMaster() const;
205 /** Returns TRUE if this class is a template */
206 bool isTemplate() const;
208 IncludeInfo *includeInfo() const;
210 UsesClassDict *usedImplementationClasses() const;
212 UsesClassDict *usedByImplementationClasses() const;
214 UsesClassDict *usedInterfaceClasses() const;
216 bool isTemplateArgument() const;
218 /** Returns the definition of a nested compound if
219 * available, or 0 otherwise.
220 * @param name The name of the nested compound
222 virtual Definition *findInnerCompound(const char *name);
224 /** Returns the template parameter lists that form the template
225 * declaration of this class.
227 * Example: <code>template<class T> class TC {};</code>
228 * will return a list with one ArgumentList containing one argument
229 * with type="class" and name="T".
231 void getTemplateParameterLists(QList<ArgumentList> &lists) const;
233 QCString qualifiedNameWithTemplateParameters(
234 QList<ArgumentList> *actualParams=0) const;
236 /** Returns TRUE if there is at least one pure virtual member in this
239 bool isAbstract() const;
241 /** Returns TRUE if this class is implemented in Objective-C */
242 bool isObjectiveC() const;
244 /** Returns TRUE if this class is implemented in C# */
245 bool isCSharp() const;
247 /** Returns TRUE if this class is marked as final */
248 bool isFinal() const;
250 /** Returns TRUE if this class is marked as sealed */
251 bool isSealed() const;
253 /** Returns TRUE if this class represents an Objective-C 2.0 extension (nameless category) */
254 bool isExtension() const;
256 /** Returns the class of which this is a category (Objective-C only) */
257 ClassDef *categoryOf() const;
259 /** Returns the name of the class including outer classes, but not
260 * including namespaces.
262 QCString className() const;
264 /** Returns the members in the list identified by \a lt */
265 MemberList *getMemberList(MemberList::ListType lt);
267 /** Returns the list containing the list of members sorted per type */
268 const QList<MemberList> &getMemberLists() const;
270 /** Returns the member groups defined for this class */
271 MemberGroupSDict *getMemberGroupSDict() const;
273 QDict<int> *getTemplateBaseClassNames() const;
275 ClassDef *getVariableInstance(const char *templSpec);
277 bool isUsedOnly() const;
279 QCString anchor() const;
280 bool isEmbeddedInOuterScope() const;
282 bool isSimple() const;
284 const ClassList *taggedInnerClasses() const;
285 ClassDef *tagLessReference() const;
287 MemberDef *isSmartPointer() const;
289 bool isJavaEnum() const;
291 bool isGeneric() const;
293 //-----------------------------------------------------------------------------------
295 //-----------------------------------------------------------------------------------
297 void insertBaseClass(ClassDef *,const char *name,Protection p,Specifier s,const char *t=0);
298 void insertSubClass(ClassDef *,Protection p,Specifier s,const char *t=0);
299 void setIncludeFile(FileDef *fd,const char *incName,bool local,bool force);
300 void insertMember(MemberDef *);
301 void insertUsedFile(const char *);
302 bool addExample(const char *anchor,const char *name, const char *file);
303 void mergeCategory(ClassDef *category);
304 void setNamespace(NamespaceDef *nd);
305 void setFileDef(FileDef *fd);
306 void setSubGrouping(bool enabled);
307 void setProtection(Protection p);
308 void setGroupDefForAllMembers(GroupDef *g,Grouping::GroupPri_t pri,const QCString &fileName,int startLine,bool hasDocs);
309 void addInnerCompound(Definition *d);
310 ClassDef *insertTemplateInstance(const QCString &fileName,int startLine,
311 const QCString &templSpec,bool &freshInstance);
312 void addUsedClass(ClassDef *cd,const char *accessName,Protection prot);
313 void addUsedByClass(ClassDef *cd,const char *accessName,Protection prot);
314 void setIsStatic(bool b);
315 void setCompoundType(CompoundType t);
316 void setClassName(const char *name);
317 void setClassSpecifier(int spec);
319 void setTemplateArguments(ArgumentList *al);
320 void setTemplateBaseClassNames(QDict<int> *templateNames);
321 void setTemplateMaster(ClassDef *tm);
322 void setTypeConstraints(ArgumentList *al);
323 void addMembersToTemplateInstance(ClassDef *cd,const char *templSpec);
324 void makeTemplateArgument(bool b=TRUE);
325 void setCategoryOf(ClassDef *cd);
326 void setUsedOnly(bool b);
328 void addTaggedInnerClass(ClassDef *cd);
329 void setTagLessReference(ClassDef *cd);
331 //-----------------------------------------------------------------------------------
333 //-----------------------------------------------------------------------------------
335 void findSectionsInDocumentation();
336 void addMembersToMemberGroup();
337 void addListReferences();
338 void computeAnchors();
340 void sortMemberLists();
341 void distributeMemberGroupDocumentation();
342 void writeDocumentation(OutputList &ol);
343 void writeDocumentationForInnerClasses(OutputList &ol);
344 void writeMemberPages(OutputList &ol);
345 void writeMemberList(OutputList &ol);
346 void writeDeclaration(OutputList &ol,MemberDef *md,bool inGroup,
347 ClassDef *inheritedFrom,const char *inheritId);
348 void writeQuickMemberLinks(OutputList &ol,MemberDef *md) const;
349 void writeSummaryLinks(OutputList &ol);
350 void reclassifyMember(MemberDef *md,MemberDef::MemberType t);
351 void writeInlineDocumentation(OutputList &ol);
352 void writeDeclarationLink(OutputList &ol,bool &found,
353 const char *header,bool localNames);
354 void removeMemberFromLists(MemberDef *md);
355 void addGroupedInheritedMembers(OutputList &ol,MemberList::ListType lt,
356 ClassDef *inheritedFrom,const QCString &inheritId);
357 int countMembersIncludingGrouped(MemberList::ListType lt,ClassDef *inheritedFrom,bool additional);
362 void addUsedInterfaceClasses(MemberDef *md,const char *typeStr);
364 bool hasNonReferenceSuperClass();
365 void showUsedFiles(OutputList &ol);
368 void writeTagFileMarker();
369 void writeDocumentationContents(OutputList &ol,const QCString &pageTitle);
370 void internalInsertMember(MemberDef *md,Protection prot,bool addToAllList);
371 QCString getMemberListFileName() const;
372 void addMemberToList(MemberList::ListType lt,MemberDef *md,bool isBrief);
373 MemberList *createMemberList(MemberList::ListType lt);
374 void writeInheritedMemberDeclarations(OutputList &ol,MemberList::ListType lt,const QCString &title,ClassDef *inheritedFrom,bool invert,QPtrDict<void> *visitedClasses);
375 void writeMemberDeclarations(OutputList &ol,MemberList::ListType lt,const QCString &title,
376 const char *subTitle=0,bool showInline=FALSE,ClassDef *inheritedFrom=0,int lt2=-1,bool invert=FALSE,QPtrDict<void> *visitedClasses=0);
377 void writeMemberDocumentation(OutputList &ol,MemberList::ListType lt,const QCString &title,bool showInline=FALSE);
378 void writeSimpleMemberDocumentation(OutputList &ol,MemberList::ListType lt);
379 void writePlainMemberDeclaration(OutputList &ol,MemberList::ListType lt,bool inGroup,ClassDef *inheritedFrom,const char *inheritId);
380 void writeBriefDescription(OutputList &ol,bool exampleFlag);
381 void writeDetailedDescription(OutputList &ol,const QCString &pageType,bool exampleFlag,
382 const QCString &title,const QCString &anchor=QCString());
383 void writeIncludeFiles(OutputList &ol);
384 //void writeAllMembersLink(OutputList &ol);
385 void writeInheritanceGraph(OutputList &ol);
386 void writeCollaborationGraph(OutputList &ol);
387 void writeMemberGroups(OutputList &ol,bool showInline=FALSE);
388 void writeNestedClasses(OutputList &ol,const QCString &title);
389 void writeInlineClasses(OutputList &ol);
390 void startMemberDeclarations(OutputList &ol);
391 void endMemberDeclarations(OutputList &ol);
392 void startMemberDocumentation(OutputList &ol);
393 void endMemberDocumentation(OutputList &ol);
394 void writeAuthorSection(OutputList &ol);
395 void writeMoreLink(OutputList &ol,const QCString &anchor);
396 void writeDetailedDocumentationBody(OutputList &ol);
398 int countInheritedDecMembersRec(MemberList::ListType lt,ClassDef *inheritedFrom);
399 int countInheritedDecMembers(MemberList::ListType lt);
400 int countAdditionalInheritedMembers();
401 void writeAdditionalInheritedMembers(OutputList &ol);
402 void addClassAttributes(OutputList &ol);
404 ClassDefImpl *m_impl;
408 /** Class that contains information about a usage relation.
412 UsesClassDef(ClassDef *cd) : classDef(cd)
414 accessors = new QDict<void>(17);
421 void addAccessor(const char *s)
423 if (accessors->find(s)==0)
425 accessors->insert(s,(void *)666);
428 /** Class definition that this relation uses. */
431 /** Dictionary of member variable names that form the edge labels of the
434 QDict<void> *accessors;
436 /** Template arguments used for the base class */
437 QCString templSpecifiers;
442 /** Dictionary of usage relations.
444 class UsesClassDict : public QDict<UsesClassDef>
447 UsesClassDict(int size) : QDict<UsesClassDef>(size) {}
451 /** Iterator class to iterate over a dictionary of usage relations.
453 class UsesClassDictIterator : public QDictIterator<UsesClassDef>
456 UsesClassDictIterator(const QDict<UsesClassDef> &d)
457 : QDictIterator<UsesClassDef>(d) {}
458 ~UsesClassDictIterator() {}
461 /** Class that contains information about an inheritance relation.
465 BaseClassDef(ClassDef *cd,const char *n,Protection p,
466 Specifier v,const char *t) :
467 classDef(cd), usedName(n), prot(p), virt(v), templSpecifiers(t) {}
469 /** Class definition that this relation inherits from. */
472 /** name used in the inheritance list
473 * (may be a typedef name instead of the class name)
477 /** Protection level of the inheritance relation:
478 * Public, Protected, or Private
482 /** Virtualness of the inheritance relation:
487 /** Template arguments used for the base class */
488 QCString templSpecifiers;
491 /** List of base classes.
493 * The classes are alphabetically sorted on name if inSort() is used.
495 class BaseClassList : public QList<BaseClassDef>
499 int compareItems(GCI item1,GCI item2)
501 ClassDef *c1=((BaseClassDef *)item1)->classDef;
502 ClassDef *c2=((BaseClassDef *)item2)->classDef;
506 return stricmp(c1->name(),c2->name());
510 /** Iterator for a list of base classes.
512 class BaseClassListIterator : public QListIterator<BaseClassDef>
515 BaseClassListIterator(const BaseClassList &bcl) :
516 QListIterator<BaseClassDef>(bcl) {}