91672499267084bd64b5ae6bc639012250caa373
[platform/upstream/doxygen.git] / src / filedef.h
1 /******************************************************************************
2  *
3  * 
4  *
5  * Copyright (C) 1997-2015 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 FILEDEF_H
19 #define FILEDEF_H
20
21 #include "index.h"
22 #include <qlist.h>
23 #include <qintdict.h>
24 #include <qdict.h>
25 #include "definition.h"
26 #include "sortdict.h"
27 #include "memberlist.h"
28
29 class MemberList;
30 class FileDef;
31 class FileList;
32 class ClassSDict;
33 class ClassDef;
34 class ClassList;
35 class MemberDef;
36 class OutputList;
37 class NamespaceDef;
38 class NamespaceSDict;
39 class MemberGroupSDict;
40 class PackageDef;
41 class DirDef;
42 class FTextStream;
43
44 /** Class representing the data associated with a \#include statement. */
45 struct IncludeInfo
46 {
47   IncludeInfo() : fileDef(0), local(FALSE), imported(FALSE), indirect(FALSE) {}
48   ~IncludeInfo() {}
49   FileDef *fileDef;
50   QCString includeName;
51   bool local;
52   bool imported;
53   bool indirect;
54 };
55
56 /** A model of a file symbol. 
57  *   
58  *  An object of this class contains all file information that is gathered.
59  *  This includes the members and compounds defined in the file.
60  *   
61  *  The member writeDocumentation() can be used to generate the page of
62  *  documentation to HTML and LaTeX.
63  */
64 class FileDef : public Definition
65 {
66   public:
67     //enum FileType { Source, Header, Unknown };
68
69     FileDef(const char *p,const char *n,const char *ref=0,const char *dn=0);
70    ~FileDef();
71
72     // ----------------------------------------------------------------------
73
74     DefType definitionType() const { return TypeFile; }
75
76     /*! Returns the unique file name (this may include part of the path). */
77     QCString name() const;
78     QCString displayName(bool=TRUE) const { return name(); }
79     QCString fileName() const { return m_fileName; }
80     
81     QCString getOutputFileBase() const;
82
83     QCString anchor() const { return QCString(); }
84
85     QCString getSourceFileBase() const;
86     
87     /*! Returns the name of the verbatim copy of this file (if any). */
88     QCString includeName() const;
89
90     QCString includeDependencyGraphFileName() const;
91
92     QCString includedByDependencyGraphFileName() const;
93     
94     /*! Returns the absolute path including the file name. */
95     QCString absFilePath() const { return m_filePath; }
96     
97     /*! Returns the name as it is used in the documentation */
98     const QCString &docName() const { return m_docname; }
99
100     /*! Returns TRUE if this file is a source file. */
101     bool isSource() const { return m_isSource; }
102
103     bool isDocumentationFile() const;
104     
105     Definition *getSourceDefinition(int lineNr) const;
106     MemberDef *getSourceMember(int lineNr) const;
107
108     /*! Returns the absolute path of this file. */ 
109     QCString getPath() const { return m_path; }
110
111     /*! Returns version of this file. */
112     QCString getVersion() const { return m_fileVersion; }
113     
114     bool isLinkableInProject() const;
115
116     bool isLinkable() const { return isLinkableInProject() || isReference(); }
117     bool isIncluded(const QCString &name) const;
118
119     PackageDef *packageDef() const { return m_package; }
120     DirDef *getDirDef() const      { return m_dir; }
121     NamespaceSDict *getUsedNamespaces() const;
122     SDict<Definition> *getUsedClasses() const      { return m_usingDeclList; }
123     QList<IncludeInfo> *includeFileList() const    { return m_includeList; }
124     QList<IncludeInfo> *includedByFileList() const { return m_includedByList; }
125     void getAllIncludeFilesRecursively(QStrList &incFiles) const;
126
127     MemberList *getMemberList(MemberListType lt) const;
128     const QList<MemberList> &getMemberLists() const { return m_memberLists; }
129
130     /* user defined member groups */
131     MemberGroupSDict *getMemberGroupSDict() const { return m_memberGroupSDict; }
132     NamespaceSDict *getNamespaceSDict() const     { return m_namespaceSDict; }
133     ClassSDict *getClassSDict() const             { return m_classSDict; }
134
135     QCString title() const;
136     bool hasDetailedDescription() const;
137     QCString fileVersion() const;
138
139     bool subGrouping() const { return m_subGrouping; }
140     
141     //---------------------------------
142
143     void addSourceRef(int line,Definition *d,MemberDef *md);
144
145     void writeDocumentation(OutputList &ol);
146     void writeMemberPages(OutputList &ol);
147     void writeQuickMemberLinks(OutputList &ol,MemberDef *currentMd) const;
148     void writeSummaryLinks(OutputList &ol);
149     void writeTagFile(FTextStream &t);
150
151     void startParsing();
152     void writeSource(OutputList &ol,bool sameTu,QStrList &filesInSameTu);
153     void parseSource(bool sameTu,QStrList &filesInSameTu);
154     void finishParsing();
155     void setDiskName(const QCString &name);
156
157     void insertMember(MemberDef *md);
158     void insertClass(ClassDef *cd);
159     void insertNamespace(NamespaceDef *nd);
160     void computeAnchors();
161
162     void setPackageDef(PackageDef *pd) { m_package=pd; }
163     void setDirDef(DirDef *dd) { m_dir=dd; }
164
165     void addUsingDirective(NamespaceDef *nd);
166     void addUsingDeclaration(Definition *def);
167     void combineUsingRelations();
168
169     bool generateSourceFile() const;
170     void sortMemberLists();
171
172     void addIncludeDependency(FileDef *fd,const char *incName,bool local,bool imported,bool indirect);
173     void addIncludedByDependency(FileDef *fd,const char *incName,bool local,bool imported);
174
175     void addMembersToMemberGroup();
176     void distributeMemberGroupDocumentation();
177     void findSectionsInDocumentation();
178     void addIncludedUsingDirectives();
179
180     void addListReferences();
181     //bool includes(FileDef *incFile,QDict<FileDef> *includedFiles) const;
182     //bool includesByName(const QCString &name) const;
183     bool visited;
184
185   protected:
186     /**
187      * Retrieves the file version from version control system.
188      */
189     void acquireFileVersion();
190
191   private: 
192     MemberList *createMemberList(MemberListType lt);
193     void addMemberToList(MemberListType lt,MemberDef *md);
194     void writeMemberDeclarations(OutputList &ol,MemberListType lt,const QCString &title);
195     void writeMemberDocumentation(OutputList &ol,MemberListType lt,const QCString &title);
196     void writeIncludeFiles(OutputList &ol);
197     void writeIncludeGraph(OutputList &ol);
198     void writeIncludedByGraph(OutputList &ol);
199     void writeMemberGroups(OutputList &ol);
200     void writeAuthorSection(OutputList &ol);
201     void writeSourceLink(OutputList &ol);
202     void writeNamespaceDeclarations(OutputList &ol,const QCString &title,
203             bool isConstantGroup);
204     void writeClassDeclarations(OutputList &ol,const QCString &title);
205     void writeInlineClasses(OutputList &ol);
206     void startMemberDeclarations(OutputList &ol);
207     void endMemberDeclarations(OutputList &ol);
208     void startMemberDocumentation(OutputList &ol);
209     void endMemberDocumentation(OutputList &ol);
210     void writeDetailedDescription(OutputList &ol,const QCString &title);
211     void writeBriefDescription(OutputList &ol);
212
213     QDict<IncludeInfo>   *m_includeDict;
214     QList<IncludeInfo>   *m_includeList;
215     QDict<IncludeInfo>   *m_includedByDict;
216     QList<IncludeInfo>   *m_includedByList;
217     NamespaceSDict       *m_usingDirList;
218     SDict<Definition>    *m_usingDeclList;
219     QCString              m_path;
220     QCString              m_filePath;
221     QCString              m_inclDepFileName;
222     QCString              m_inclByDepFileName;
223     QCString              m_outputDiskName;
224     QCString              m_fileName;
225     QCString              m_docname;
226     QIntDict<Definition> *m_srcDefDict;
227     QIntDict<MemberDef>  *m_srcMemberDict;
228     bool                  m_isSource;
229     QCString              m_fileVersion;
230     PackageDef           *m_package;
231     DirDef               *m_dir;
232     QList<MemberList>     m_memberLists;
233     MemberGroupSDict     *m_memberGroupSDict;
234     NamespaceSDict       *m_namespaceSDict;
235     ClassSDict           *m_classSDict;
236     bool                  m_subGrouping;
237 };
238
239 /** Class representing a list of FileDef objects. */
240 class FileList : public QList<FileDef>
241 {
242   public:
243     FileList() : m_pathName("tmp") {}
244     FileList(const char *path) : QList<FileDef>(), m_pathName(path) {}
245    ~FileList() {}
246     QCString path() const { return m_pathName; }
247   private:
248     int compareValues(const FileDef *md1,const FileDef *md2) const
249     {
250       return qstricmp(md1->name(),md2->name());
251     }
252     QCString m_pathName;
253 };
254
255 class OutputNameList : public QList<FileList>
256 {
257   public:
258     OutputNameList() : QList<FileList>() {}
259    ~OutputNameList() {}
260  private:
261     int compareValues(const FileList *fl1,const FileList *fl2) const
262     {
263       return qstricmp(fl1->path(),fl2->path());
264     }
265 };
266
267 class OutputNameDict : public QDict<FileList>
268 {
269   public:
270     OutputNameDict(int size) : QDict<FileList>(size) {}
271    ~OutputNameDict() {}
272 };
273
274 class Directory;
275
276 /** Class representing an entry (file or sub directory) in a directory */
277 class DirEntry
278 {
279   public:
280     enum EntryKind { Dir, File };
281     DirEntry(DirEntry *parent,FileDef *fd)  
282        : m_parent(parent), m_name(fd->name()), m_kind(File), m_fd(fd), 
283          m_isLast(FALSE) { }
284     DirEntry(DirEntry *parent,QCString name)              
285        : m_parent(parent), m_name(name), m_kind(Dir), 
286          m_fd(0), m_isLast(FALSE) { }
287     virtual ~DirEntry() { }
288     EntryKind kind() const { return m_kind; }
289     FileDef *file()  const { return m_fd; }
290     bool isLast() const    { return m_isLast; }
291     void setLast(bool b)   { m_isLast=b; }
292     DirEntry *parent() const { return m_parent; }
293     QCString name() const  { return m_name; }
294     QCString path() const  { return parent() ? parent()->path()+"/"+name() : name(); }
295
296   protected:
297     DirEntry *m_parent;
298     QCString m_name;
299
300   private:
301     EntryKind m_kind;
302     FileDef   *m_fd;
303     bool m_isLast;
304 };
305
306 /** Class representing a directory tree of DirEntry objects. */
307 class Directory : public DirEntry
308 {
309   public:
310     Directory(Directory *parent,const QCString &name) 
311        : DirEntry(parent,name)
312     { m_children.setAutoDelete(TRUE); }
313     virtual ~Directory()              {}
314     void addChild(DirEntry *d)        { m_children.append(d); d->setLast(TRUE); }
315     QList<DirEntry> &children()       { return m_children; }
316     void rename(const QCString &name) { m_name=name; }
317     void reParent(Directory *parent)  { m_parent=parent; }
318
319   private:
320     QList<DirEntry> m_children;
321 };
322
323 void generateFileTree();
324
325 #endif
326