1 /******************************************************************************
2  *
3  * Copyright (C) 1997-2021 by Dimitri van Heesch.
4  *
5  * Permission to use, copy, modify, and distribute this software and its
6  * documentation under the terms of the GNU General Public License is hereby
7  * granted. No representations are made about the suitability of this software
8  * for any purpose. It is provided "as is" without express or implied warranty.
9  * See the GNU General Public License for more details.
10  *
11  * Documents produced by Doxygen are derivative works derived from the
12  * input used in their production; they are not affected by this license.
13  *
14  */
15 
16 #ifndef INDEX_H
17 #define INDEX_H
18 
19 #include <utility>
20 #include <vector>
21 #include <memory>
22 
23 #include "qcstring.h"
24 
25 class Definition;
26 class DefinitionMutable;
27 class NamespaceDef;
28 class MemberDef;
29 class OutputList;
30 
31 /** \brief Abstract interface for index generators. */
32 class IndexIntf
33 {
34   public:
~IndexIntf()35     virtual ~IndexIntf() {}
36     virtual void initialize() = 0;
37     virtual void finalize() = 0;
38     virtual void incContentsDepth() = 0;
39     virtual void decContentsDepth() = 0;
40     virtual void addContentsItem(bool isDir, const QCString &name, const QCString &ref,
41                                  const QCString &file, const QCString &anchor, bool separateIndex,
42                                  bool addToNavIndex,const Definition *def) = 0;
43     virtual void addIndexItem(const Definition *context,const MemberDef *md,
44                               const QCString &sectionAnchor,const QCString &title) = 0;
45     virtual void addIndexFile(const QCString &name) = 0;
46     virtual void addImageFile(const QCString &name) = 0;
47     virtual void addStyleSheetFile(const QCString &name) = 0;
48 };
49 
50 /** \brief A list of index interfaces.
51  *
52  *  This class itself implements all methods of IndexIntf and
53  *  just forwards the calls to all items in the list.
54  */
55 class IndexList : public IndexIntf
56 {
57   private:
58     std::vector< std::unique_ptr<IndexIntf> > m_intfs;
59 
60     // For each index format we forward the method call.
61     // We use C++11 variadic templates and perfect forwarding to implement foreach() generically,
62     // and split the types of the methods from the arguments passed to allow implicit conversions.
63     template<class... Ts,class... As>
foreach(void (IndexIntf::* methodPtr)(Ts...),As &&...args)64     void foreach(void (IndexIntf::*methodPtr)(Ts...),As&&... args)
65     {
66       for (const auto &intf : m_intfs)
67       {
68         (intf.get()->*methodPtr)(std::forward<As>(args)...);
69       }
70     }
71 
72   public:
73     /** Creates a list of indexes */
IndexList()74     IndexList() { m_enabled=TRUE; }
75 
76     /** Add an index generator to the list, using a syntax similar to std::make_unique<T>() */
77     template<class T,class... As>
addIndex(As &&...args)78     void addIndex(As&&... args)
79     { m_intfs.push_back(std::make_unique<T>(std::forward<As>(args)...)); }
80 
disable()81     void disable()
82     { m_enabled = FALSE; }
enable()83     void enable()
84     { m_enabled = TRUE; }
isEnabled()85     bool isEnabled() const
86     { return m_enabled; }
87 
88     // IndexIntf implementation
initialize()89     void initialize()
90     { foreach(&IndexIntf::initialize); }
finalize()91     void finalize()
92     { foreach(&IndexIntf::finalize); }
incContentsDepth()93     void incContentsDepth()
94     { if (m_enabled) foreach(&IndexIntf::incContentsDepth); }
decContentsDepth()95     void decContentsDepth()
96     { if (m_enabled) foreach(&IndexIntf::decContentsDepth); }
97     void addContentsItem(bool isDir, const QCString &name, const QCString &ref,
98                          const QCString &file, const QCString &anchor,bool separateIndex=FALSE,bool addToNavIndex=FALSE,
99                          const Definition *def=0)
100     { if (m_enabled) foreach(&IndexIntf::addContentsItem,isDir,name,ref,file,anchor,separateIndex,addToNavIndex,def); }
101     void addIndexItem(const Definition *context,const MemberDef *md,const QCString &sectionAnchor=QCString(),const QCString &title=QCString())
102     { if (m_enabled) foreach(&IndexIntf::addIndexItem,context,md,sectionAnchor,title); }
addIndexFile(const QCString & name)103     void addIndexFile(const QCString &name)
104     { if (m_enabled) foreach(&IndexIntf::addIndexFile,name); }
addImageFile(const QCString & name)105     void addImageFile(const QCString &name)
106     { if (m_enabled) foreach(&IndexIntf::addImageFile,name); }
addStyleSheetFile(const QCString & name)107     void addStyleSheetFile(const QCString &name)
108     { if (m_enabled) foreach(&IndexIntf::addStyleSheetFile,name); }
109 
110   private:
111     bool m_enabled;
112 };
113 
114 
115 enum IndexSections
116 {
117   isTitlePageStart,
118   isTitlePageAuthor,
119   isMainPage,
120   isModuleIndex,
121   isDirIndex,
122   isNamespaceIndex,
123   isConceptIndex,
124   isClassHierarchyIndex,
125   isCompoundIndex,
126   isFileIndex,
127   isPageIndex,
128   isModuleDocumentation,
129   isDirDocumentation,
130   isNamespaceDocumentation,
131   isClassDocumentation,
132   isConceptDocumentation,
133   isFileDocumentation,
134   isExampleDocumentation,
135   isPageDocumentation,
136   isPageDocumentation2,
137   isEndIndex
138 };
139 
140 enum HighlightedItem
141 {
142   HLI_None=0,
143   HLI_Main,
144   HLI_Modules,
145   //HLI_Directories,
146   HLI_Namespaces,
147   HLI_ClassHierarchy,
148   HLI_InterfaceHierarchy,
149   HLI_ExceptionHierarchy,
150   HLI_Classes,
151   HLI_Concepts,
152   HLI_Interfaces,
153   HLI_Structs,
154   HLI_Exceptions,
155   HLI_AnnotatedClasses,
156   HLI_AnnotatedInterfaces,
157   HLI_AnnotatedStructs,
158   HLI_AnnotatedExceptions,
159   HLI_Files,
160   HLI_NamespaceMembers,
161   HLI_Functions,
162   HLI_Globals,
163   HLI_Pages,
164   HLI_Examples,
165   HLI_Search,
166   HLI_UserGroup,
167 
168   HLI_ClassVisible,
169   HLI_ConceptVisible,
170   HLI_InterfaceVisible,
171   HLI_StructVisible,
172   HLI_ExceptionVisible,
173   HLI_NamespaceVisible,
174   HLI_FileVisible
175 };
176 
177 enum ClassMemberHighlight
178 {
179   CMHL_All = 0,
180   CMHL_Functions,
181   CMHL_Variables,
182   CMHL_Typedefs,
183   CMHL_Enums,
184   CMHL_EnumValues,
185   CMHL_Properties,
186   CMHL_Events,
187   CMHL_Related,
188   CMHL_Total = CMHL_Related+1
189 };
190 
191 enum FileMemberHighlight
192 {
193   FMHL_All = 0,
194   FMHL_Functions,
195   FMHL_Variables,
196   FMHL_Typedefs,
197   FMHL_Sequences,
198   FMHL_Dictionaries,
199   FMHL_Enums,
200   FMHL_EnumValues,
201   FMHL_Defines,
202   FMHL_Total = FMHL_Defines+1
203 };
204 
205 enum NamespaceMemberHighlight
206 {
207   NMHL_All = 0,
208   NMHL_Functions,
209   NMHL_Variables,
210   NMHL_Typedefs,
211   NMHL_Sequences,
212   NMHL_Dictionaries,
213   NMHL_Enums,
214   NMHL_EnumValues,
215   NMHL_Total = NMHL_EnumValues+1
216 };
217 
218 enum ClassHighlight
219 {
220   CHL_All = 0,
221   CHL_Classes,
222   CHL_Structs,
223   CHL_Unions,
224   CHL_Interfaces,
225   CHL_Protocols,
226   CHL_Categories,
227   CHL_Exceptions,
228   CHL_Total = CHL_Exceptions+1
229 };
230 
231 void writeGraphInfo(OutputList &ol);
232 void writeIndexHierarchy(OutputList &ol);
233 
234 void countDataStructures();
235 
236 extern int annotatedClasses;
237 extern int annotatedInterfaces;
238 extern int annotatedStructs;
239 extern int annotatedExceptions;
240 extern int hierarchyClasses;
241 extern int hierarchyInterfaces;
242 extern int hierarchyExceptions;
243 extern int documentedFiles;
244 extern int documentedGroups;
245 extern int documentedNamespaces;
246 extern int documentedConcepts;
247 extern int indexedPages;
248 extern int documentedClassMembers[CMHL_Total];
249 extern int documentedFileMembers[FMHL_Total];
250 extern int documentedNamespaceMembers[NMHL_Total];
251 extern int documentedDirs;
252 extern int documentedPages;
253 
254 void startTitle(OutputList &ol,const QCString &fileName,const DefinitionMutable *def=0);
255 void endTitle(OutputList &ol,const QCString &fileName,const QCString &name);
256 void startFile(OutputList &ol,const QCString &name,const QCString &manName,
257                const QCString &title,HighlightedItem hli=HLI_None,
258                bool additionalIndices=FALSE,const QCString &altSidebarName=QCString());
259 void endFile(OutputList &ol,bool skipNavIndex=FALSE,bool skipEndContents=FALSE,
260              const QCString &navPath=QCString());
261 void endFileWithNavPath(const Definition *d,OutputList &ol);
262 
263 void initClassMemberIndices();
264 void initFileMemberIndices();
265 void initNamespaceMemberIndices();
266 void addClassMemberNameToIndex(const MemberDef *md);
267 void addFileMemberNameToIndex(const MemberDef *md);
268 void addNamespaceMemberNameToIndex(const MemberDef *md);
269 void sortMemberIndexLists();
270 QCString fixSpaces(const QCString &s);
271 
272 int countVisibleMembers(const NamespaceDef *nd);
273 
274 #endif
275