Fix for UBSan build
[platform/upstream/doxygen.git] / src / dirdef.h
1 /******************************************************************************
2  *
3  * $Id: $
4  *
5  * Copyright (C) 1997-2012 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 DIRDEF_H
19 #define DIRDEF_H
20
21 #include "qtbc.h"
22 #include "sortdict.h"
23 #include "definition.h"
24
25 #include <qlist.h>
26
27 class FileList;
28 class ClassSDict;
29 class QStrList;
30 class FileDef;
31 class OutputList;
32 class UsedDir;
33 class FTextStream;
34
35 class DirDef;
36
37 /** A list of directories. */
38 class DirList : public QList<DirDef>
39 {
40   public:
41    int compareItems(GCI item1,GCI item2);
42 };
43
44 /** A model of a directory symbol. */
45 class DirDef : public Definition
46 {
47   public:
48     DirDef(const char *path);
49     virtual ~DirDef();
50
51     // accessors
52     DefType definitionType() const { return TypeDir; }
53     QCString getOutputFileBase() const;
54     QCString anchor() const { return QCString(); }
55     bool isLinkableInProject() const;
56     bool isLinkable() const;
57     QCString displayName(bool=TRUE) const { return m_dispName; }
58     QCString shortName() const { return m_shortName; }
59     void addSubDir(DirDef *subdir);
60     FileList *   getFiles() const        { return m_fileList; }
61     void addFile(FileDef *fd);
62     const DirList &subDirs() const { return m_subdirs; }
63     bool isCluster() const { return m_subdirs.count()>0; }
64     int level() const { return m_level; }
65     DirDef *parent() const { return m_parent; }
66     int dirCount() const { return m_dirCount; }
67     const QDict<UsedDir> *usedDirs() const { return m_usedDirs; }
68     bool isParentOf(DirDef *dir) const;
69     bool depGraphIsTrivial() const;
70
71     // generate output
72     void writeDocumentation(OutputList &ol);
73     void writeDepGraph(FTextStream &t);
74
75     static DirDef *mergeDirectoryInTree(const QCString &path);
76     bool visited;
77     void setDiskName(const QCString &name) { m_diskName = name; }
78
79   private:
80     friend void computeDirDependencies();
81
82     void writeDetailedDescription(OutputList &ol,const QCString &title);
83     void writeBriefDescription(OutputList &ol);
84     void writeDirectoryGraph(OutputList &ol);
85     void writeSubDirList(OutputList &ol);
86     void writeFileList(OutputList &ol);
87     void startMemberDeclarations(OutputList &ol);
88     void endMemberDeclarations(OutputList &ol);
89
90     void setLevel();
91     static DirDef *createNewDir(const char *path);
92     static bool matchPath(const QCString &path,QStrList &l);
93     void addUsesDependency(DirDef *usedDir,FileDef *srcFd,
94                            FileDef *dstFd,bool inherited);
95     void computeDependencies();
96
97     DirList m_subdirs;
98     QCString m_dispName;
99     QCString m_shortName;
100     QCString m_diskName;
101     FileList *m_fileList;                 // list of files in the group
102     int m_dirCount;
103     int m_level;
104     DirDef *m_parent;
105     QDict<UsedDir> *m_usedDirs;
106 };
107
108 /** Class representing a pair of FileDef objects */
109 class FilePair 
110 {
111   public:
112     FilePair(FileDef *src,FileDef *dst) : m_src(src), m_dst(dst) {}
113     const FileDef *source() const { return m_src; }
114     const FileDef *destination() const { return m_dst; }
115   private:
116     FileDef *m_src;
117     FileDef *m_dst;
118 };
119
120 /** A sorted dictionary of FilePair objects. */
121 class FilePairDict : public SDict<FilePair>
122 {
123   public:
124     FilePairDict(int size) : SDict<FilePair>(size) {}
125     int compareItems(GCI item1,GCI item2);
126 };
127
128 /** Usage information of a directory. */
129 class UsedDir
130 {
131   public:
132     UsedDir(DirDef *dir,bool inherited);
133     virtual ~UsedDir();
134     void addFileDep(FileDef *srcFd,FileDef *dstFd);
135     FilePair *findFilePair(const char *name);
136     const FilePairDict &filePairs() const { return m_filePairs; }
137     const DirDef *dir() const { return m_dir; }
138     bool inherited() const { return m_inherited; }
139
140   private:
141     DirDef *m_dir;
142     FilePairDict m_filePairs;
143     bool m_inherited;
144 };
145
146 /** A usage relation between two directories. */
147 class DirRelation
148 {
149   public:
150     DirRelation(const QCString &name,DirDef *src,UsedDir *dst) 
151       : m_name(name), m_src(src), m_dst(dst) {}
152     DirDef  *source() const      { return m_src; }
153     UsedDir *destination() const { return m_dst; }
154     void writeDocumentation(OutputList &ol);
155     QCString getOutputFileBase() const { return m_name; }
156
157   private:
158     QCString m_name;
159     DirDef  *m_src;
160     UsedDir *m_dst;
161 };
162
163 inline int DirList::compareItems(GCI item1,GCI item2)
164 {
165   return stricmp(((DirDef *)item1)->shortName(),((DirDef *)item2)->shortName());
166 }
167
168 /** A sorted dictionary of DirDef objects. */
169 class DirSDict : public SDict<DirDef>
170 {
171   public:
172     DirSDict(int size) : SDict<DirDef>(size) {}
173     int compareItems(GCI item1,GCI item2)
174     {
175       return stricmp(((DirDef *)item1)->shortName(),((DirDef *)item2)->shortName());
176     }
177 };
178
179
180 void buildDirectories();
181 void generateDirDocs(OutputList &ol);
182 void computeDirDependencies();
183 void writeDirDependencyGraph(const char *file);
184
185 #endif