59c3efb0ec27bd09d258dc6f2994339711872dc5
[platform/upstream/doxygen.git] / src / outputlist.cpp
1 /******************************************************************************
2  *
3  * 
4  *
5  * Copyright (C) 1997-2014 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 /*! \file
19  *  This class represents a list of output generators that work in "parallel".
20  *  The class only knows about the abstract base class OutputGenerators.
21  *  All output is produced by calling a method of this class, which forwards
22  *  the call to all output generators.
23  */
24
25 #include "outputlist.h"
26 #include "outputgen.h"
27 #include "config.h"
28 #include "message.h"
29 #include "definition.h"
30 #include "docparser.h"
31 #include "vhdldocgen.h"
32
33 OutputList::OutputList(bool)
34 {
35   //printf("OutputList::OutputList()\n");
36   m_outputs.setAutoDelete(TRUE);
37 }
38
39 OutputList::~OutputList()
40 {
41   //printf("OutputList::~OutputList()\n");
42 }
43
44 void OutputList::add(const OutputGenerator *og)
45 {
46   if (og) m_outputs.append(og);
47 }
48
49 void OutputList::disableAllBut(OutputGenerator::OutputType o)
50 {
51   QListIterator<OutputGenerator> it(m_outputs);
52   OutputGenerator *og;
53   for (it.toFirst();(og=it.current());++it)
54   {
55     og->disableIfNot(o);
56   }
57 }
58
59 void OutputList::enableAll()
60 {
61   QListIterator<OutputGenerator> it(m_outputs);
62   OutputGenerator *og;
63   for (it.toFirst();(og=it.current());++it)
64   {
65     og->enable();
66   }
67 }
68
69 void OutputList::disableAll()
70 {
71   QListIterator<OutputGenerator> it(m_outputs);
72   OutputGenerator *og;
73   for (it.toFirst();(og=it.current());++it)
74   {
75     og->disable();
76   }
77 }
78
79 void OutputList::disable(OutputGenerator::OutputType o)
80 {
81   QListIterator<OutputGenerator> it(m_outputs);
82   OutputGenerator *og;
83   for (it.toFirst();(og=it.current());++it)
84   {
85     og->disableIf(o);
86   }
87 }
88
89 void OutputList::enable(OutputGenerator::OutputType o)
90 {
91   QListIterator<OutputGenerator> it(m_outputs);
92   OutputGenerator *og;
93   for (it.toFirst();(og=it.current());++it)
94   {
95     og->enableIf(o);
96   }
97 }
98
99 bool OutputList::isEnabled(OutputGenerator::OutputType o)
100 {
101   bool result=FALSE;
102   QListIterator<OutputGenerator> it(m_outputs);
103   OutputGenerator *og;
104   for (it.toFirst();(og=it.current());++it)
105   {
106     result=result || og->isEnabled(o);
107   }
108   return result;
109 }
110
111 void OutputList::pushGeneratorState()
112 {
113   QListIterator<OutputGenerator> it(m_outputs);
114   OutputGenerator *og;
115   for (it.toFirst();(og=it.current());++it)
116   {
117     og->pushGeneratorState();
118   }
119 }
120
121 void OutputList::popGeneratorState()
122 {
123   QListIterator<OutputGenerator> it(m_outputs);
124   OutputGenerator *og;
125   for (it.toFirst();(og=it.current());++it)
126   {
127     og->popGeneratorState();
128   }
129 }
130
131 bool OutputList::generateDoc(const char *fileName,int startLine,
132                   Definition *ctx,MemberDef * md,
133                   const QCString &docStr,bool indexWords,
134                   bool isExample,const char *exampleName,
135                   bool singleLine,bool linkFromIndex)
136 {
137   int count=0;
138   if (docStr.isEmpty()) return TRUE;
139
140   QListIterator<OutputGenerator> it(m_outputs);
141   OutputGenerator *og;
142   for (it.toFirst();(og=it.current());++it)
143   {
144     if (og->isEnabled()) count++;
145   }
146   if (count==0) return TRUE; // no output formats enabled.
147
148   DocRoot *root=0;
149   root = validatingParseDoc(fileName,startLine,
150                             ctx,md,docStr,indexWords,isExample,exampleName,
151                             singleLine,linkFromIndex);
152
153   writeDoc(root,ctx,md);
154
155   bool isEmpty = root->isEmpty();
156
157   delete root;
158
159   return isEmpty;
160 }
161
162 void OutputList::writeDoc(DocRoot *root,Definition *ctx,MemberDef *md)
163 {
164   QListIterator<OutputGenerator> it(m_outputs);
165   OutputGenerator *og;
166   for (it.toFirst();(og=it.current());++it)
167   {
168     //printf("og->printDoc(extension=%s)\n",
169     //    ctx?ctx->getDefFileExtension().data():"<null>");
170     if (og->isEnabled()) og->writeDoc(root,ctx,md);
171   }
172
173   VhdlDocGen::setFlowMember(0);
174 }
175
176 bool OutputList::parseText(const QCString &textStr)
177 {
178   int count=0;
179   QListIterator<OutputGenerator> it(m_outputs);
180   OutputGenerator *og;
181   for (it.toFirst();(og=it.current());++it)
182   {
183     if (og->isEnabled()) count++;
184   }
185   if (count==0) return TRUE; // no output formats enabled.
186
187   DocText *root = validatingParseText(textStr);
188
189   for (it.toFirst();(og=it.current());++it)
190   {
191     if (og->isEnabled()) og->writeDoc(root,0,0);
192   }
193
194   bool isEmpty = root->isEmpty();
195
196   delete root;
197
198   return isEmpty;
199 }
200
201
202 //--------------------------------------------------------------------------
203 // Create some overloaded definitions of the forall function.
204 // Using template functions here would have made it a little less
205 // portable (I guess).
206
207 // zero arguments
208 void OutputList::forall(void (OutputGenerator::*func)())
209 {
210   QListIterator<OutputGenerator> it(m_outputs);
211   OutputGenerator *og;
212   for (it.toFirst();(og=it.current());++it)
213   {
214     if (og->isEnabled()) (og->*func)();
215   }
216 }
217
218 // one argument
219 #define FORALL1(a1,p1)                                        \
220 void OutputList::forall(void (OutputGenerator::*func)(a1),a1) \
221 {                                                             \
222   QListIterator<OutputGenerator> it(m_outputs);               \
223   OutputGenerator *og;                                        \
224   for (it.toFirst();(og=it.current());++it)                   \
225   {                                                           \
226     if (og->isEnabled()) (og->*func)(p1);                     \
227   }                                                           \
228 }
229
230 // two arguments
231 #define FORALL2(a1,a2,p1,p2)                                        \
232 void OutputList::forall(void (OutputGenerator::*func)(a1,a2),a1,a2) \
233 {                                                                   \
234   QListIterator<OutputGenerator> it(m_outputs);                     \
235   OutputGenerator *og;                                              \
236   for (it.toFirst();(og=it.current());++it)                         \
237   {                                                                 \
238     if (og->isEnabled()) (og->*func)(p1,p2);                        \
239   }                                                                 \
240 }
241
242 // three arguments
243 #define FORALL3(a1,a2,a3,p1,p2,p3)                                        \
244 void OutputList::forall(void (OutputGenerator::*func)(a1,a2,a3),a1,a2,a3) \
245 {                                                                         \
246   QListIterator<OutputGenerator> it(m_outputs);                           \
247   OutputGenerator *og;                                                    \
248   for (it.toFirst();(og=it.current());++it)                               \
249   {                                                                       \
250     if (og->isEnabled()) (og->*func)(p1,p2,p3);                           \
251   }                                                                       \
252 }
253
254 // four arguments
255 #define FORALL4(a1,a2,a3,a4,p1,p2,p3,p4)                                        \
256 void OutputList::forall(void (OutputGenerator::*func)(a1,a2,a3,a4),a1,a2,a3,a4) \
257 {                                                                               \
258   QListIterator<OutputGenerator> it(m_outputs);                                 \
259   OutputGenerator *og;                                                          \
260   for (it.toFirst();(og=it.current());++it)                                     \
261   {                                                                             \
262     if (og->isEnabled()) (og->*func)(p1,p2,p3,p4);                              \
263   }                                                                             \
264 }
265
266 // five arguments
267 #define FORALL5(a1,a2,a3,a4,a5,p1,p2,p3,p4,p5)                                        \
268 void OutputList::forall(void (OutputGenerator::*func)(a1,a2,a3,a4,a5),a1,a2,a3,a4,a5) \
269 {                                                                                     \
270   QListIterator<OutputGenerator> it(m_outputs);                                       \
271   OutputGenerator *og;                                                                \
272   for (it.toFirst();(og=it.current());++it)                                           \
273   {                                                                                   \
274     if (og->isEnabled()) (og->*func)(p1,p2,p3,p4,p5);                                 \
275   }                                                                                   \
276 }
277
278 // six arguments
279 #define FORALL6(a1,a2,a3,a4,a5,a6,p1,p2,p3,p4,p5,p6)                                  \
280 void OutputList::forall(void (OutputGenerator::*func)(a1,a2,a3,a4,a5,a6),a1,a2,a3,a4,a5,a6) \
281 {                                                                                     \
282   QListIterator<OutputGenerator> it(m_outputs);                                       \
283   OutputGenerator *og;                                                                \
284   for (it.toFirst();(og=it.current());++it)                                           \
285   {                                                                                   \
286     if (og->isEnabled()) (og->*func)(p1,p2,p3,p4,p5,p6);                              \
287   }                                                                                   \
288 }
289
290 // seven arguments
291 #define FORALL7(a1,a2,a3,a4,a5,a6,a7,p1,p2,p3,p4,p5,p6,p7)                      \
292 void OutputList::forall(void (OutputGenerator::*func)(a1,a2,a3,a4,a5,a6,a7),a1,a2,a3,a4,a5,a6,a7) \
293 {                                                                                     \
294   QListIterator<OutputGenerator> it(m_outputs);                                       \
295   OutputGenerator *og;                                                                \
296   for (it.toFirst();(og=it.current());++it)                                           \
297   {                                                                                   \
298     if (og->isEnabled()) (og->*func)(p1,p2,p3,p4,p5,p6,p7);                           \
299   }                                                                                   \
300 }
301
302
303 // eight arguments
304 #define FORALL8(a1,a2,a3,a4,a5,a6,a7,a8,p1,p2,p3,p4,p5,p6,p7,p8)                      \
305 void OutputList::forall(void (OutputGenerator::*func)(a1,a2,a3,a4,a5,a6,a7,a8),a1,a2,a3,a4,a5,a6,a7,a8) \
306 {                                                                                     \
307   QListIterator<OutputGenerator> it(m_outputs);                                       \
308   OutputGenerator *og;                                                                \
309   for (it.toFirst();(og=it.current());++it)                                           \
310   {                                                                                   \
311     if (og->isEnabled()) (og->*func)(p1,p2,p3,p4,p5,p6,p7,p8);                        \
312   }                                                                                   \
313 }
314
315 // now instantiate only the ones we need.
316
317 FORALL1(const char *a1,a1)
318 FORALL1(char a1,a1)
319 FORALL1(int a1,a1)
320 FORALL1(const DotClassGraph &a1,a1)
321 FORALL1(const DotInclDepGraph &a1,a1)
322 FORALL1(const DotCallGraph &a1,a1)
323 FORALL1(const DotDirDeps &a1,a1)
324 FORALL1(const DotGfxHierarchyTable &a1,a1)
325 FORALL1(const DotGroupCollaboration &a1,a1)
326 FORALL1(SectionTypes a1,a1)
327 #if defined(HAS_BOOL_TYPE) || defined(Q_HAS_BOOL_TYPE)
328 FORALL1(bool a1,a1)
329 FORALL2(bool a1,int a2,a1,a2)
330 FORALL2(bool a1,bool a2,a1,a2)
331 FORALL2(const char *a1,bool a2,a1,a2)
332 FORALL4(const char *a1,const char *a2,const char *a3,bool a4,a1,a2,a3,a4)
333 #endif
334 FORALL2(int a1,bool a2,a1,a2)
335 FORALL2(bool a1,const char *a2,a1,a2)
336 FORALL2(ParamListTypes a1,const char *a2,a1,a2)
337 FORALL1(IndexSections a1,a1)
338 FORALL2(const char *a1,const char *a2,a1,a2)
339 FORALL2(const char *a1,int a2,a1,a2)
340 FORALL2(const char *a1,SectionInfo::SectionType a2,a1,a2)
341 FORALL3(bool a1,HighlightedItem a2,const char *a3,a1,a2,a3)
342 FORALL3(bool a1,bool a2,bool a3,a1,a2,a3)
343 FORALL3(const ClassDiagram &a1,const char *a2,const char *a3,a1,a2,a3)
344 FORALL3(const char *a1,const char *a2,const char *a3,a1,a2,a3)
345 FORALL3(const char *a1,const char *a2,bool a3,a1,a2,a3)
346 FORALL3(const char *a1,int a2,const char *a3,a1,a2,a3)
347 FORALL3(const char *a1,const char *a2,SectionInfo::SectionType a3,a1,a2,a3)
348 FORALL3(uchar a1,uchar a2,uchar a3,a1,a2,a3)
349 FORALL3(Definition *a1,const char *a2,bool a3,a1,a2,a3)
350 FORALL4(SectionTypes a1,const char *a2,const char *a3,const char *a4,a1,a2,a3,a4)
351 FORALL4(const char *a1,const char *a2,const char *a3,const char *a4,a1,a2,a3,a4)
352 FORALL4(const char *a1,const char *a2,const char *a3,int a4,a1,a2,a3,a4)
353 FORALL5(const char *a1,const char *a2,const char *a3,const char *a4,const char *a5,a1,a2,a3,a4,a5)
354 FORALL5(const char *a1,const char *a2,const char *a3,const char *a4,bool a5,a1,a2,a3,a4,a5)
355 FORALL6(const char *a1,const char *a2,const char *a3,const char *a4,const char *a5,const char *a6,a1,a2,a3,a4,a5,a6)
356 FORALL6(const char *a1,const DocLinkInfo &a2,const char *a3,const char *a4,const SourceLinkInfo &a5,const SourceLinkInfo &a6,a1,a2,a3,a4,a5,a6)
357
358
359 //--------------------------------------------------------------------------