Doxygen
Loading...
Searching...
No Matches
outputlist.cpp
Go to the documentation of this file.
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/*! \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 <atomic>
26
27#include "outputlist.h"
28#include "outputgen.h"
29#include "config.h"
30#include "message.h"
31#include "definition.h"
32#include "docparser.h"
33#include "vhdldocgen.h"
34#include "doxygen.h"
35
37
43
49
51{
52 if (this!=&ol)
53 {
54 m_id = ol.m_id;
57 }
58 return *this;
59}
60
62{
63 m_codeGenList.clear();
64 for (auto &e : m_outputGenList)
65 {
66 e.intf->addCodeGen(m_codeGenList);
67 }
68 m_codeGenList.setId(m_id);
69}
70
72{
73 m_id = ++g_outId;
74}
75
77{
78 for (const auto &e : m_outputGenList)
79 {
80 //printf("output %d isEnabled=%d\n",og->type(),og->isEnabled());
81 m_codeGenList.setEnabledFiltered(e.intf->type(),e.enabled);
82 }
83}
84
86{
87 //printf("disableAllBut(%d)\n",o);
88 for (auto &e : m_outputGenList)
89 {
90 if (e.intf->type()!=o) e.setEnabled(false);
91 }
93}
94
96{
97 //printf("enableAll()\n");
98 for (auto &e : m_outputGenList)
99 {
100 e.setEnabled(true);
101 }
102 syncEnabled();
103}
104
106{
107 //printf("enableAll()\n");
108 for (auto &e : m_outputGenList)
109 {
110 e.setEnabled(false);
111 }
112 syncEnabled();
113}
114
116{
117 //printf("disable(%d)\n",o);
118 for (auto &e : m_outputGenList)
119 {
120 if (e.intf->type()==o) e.setEnabled(false);
121 }
122 syncEnabled();
123}
124
126{
127 //printf("enable(%d)\n",o);
128 for (auto &e : m_outputGenList)
129 {
130 if (e.intf->type()==o) e.setEnabled(true);
131 }
132 syncEnabled();
133}
134
136{
137 for (const auto &e : m_outputGenList)
138 {
139 if (e.intf->type()==o) { return e.enabled; }
140 }
141 return false;
142}
143
145{
146 //printf("pushGeneratorState()\n");
147 for (auto &e : m_outputGenList)
148 {
149 e.enabledStack.push(e.enabled);
150 }
151 syncEnabled();
152}
153
155{
156 //printf("popGeneratorState()\n");
157 for (auto &e : m_outputGenList)
158 {
159 if (!e.enabledStack.empty())
160 {
161 e.enabled = e.enabledStack.top();
162 e.enabledStack.pop();
163 }
164 }
165 syncEnabled();
166}
167
168void OutputList::generateDoc(const QCString &fileName,int startLine,
169 const Definition *ctx,const MemberDef * md,
170 const QCString &docStr,bool indexWords,
171 bool isExample,const QCString &exampleName,
172 bool singleLine,bool linkFromIndex,
173 bool markdownSupport,
174 bool autolinkSupport)
175{
176 if (docStr.isEmpty()) return;
177
178 auto count=std::count_if(m_outputGenList.begin(),m_outputGenList.end(),
179 [](const auto &e) { return e.enabled; });
180 // we want to validate irrespective of the number of output formats
181 // specified as:
182 // - when only XML format there should be warnings as well (XML has its own write routines)
183 // - no formats there should be warnings as well
184 auto parser { createDocParser() };
185 auto ast { validatingParseDoc(*parser.get(),
186 fileName,startLine,
187 ctx,md,docStr,indexWords,isExample,exampleName,
188 singleLine,linkFromIndex,markdownSupport,autolinkSupport) };
189 if (ast && count>0) writeDoc(ast.get(),ctx,md);
190}
191
192void OutputList::startFile(const QCString &name,const QCString &manName,const QCString &title, int hierarchyLevel)
193{
194 newId();
195 m_codeGenList.setId(m_id);
196 foreach(&OutputGenIntf::startFile,name,manName,title,m_id,hierarchyLevel);
197}
198
199void OutputList::parseText(const QCString &textStr)
200{
201
202 auto count=std::count_if(m_outputGenList.begin(),m_outputGenList.end(),
203 [](const auto &e) { return e.enabled; });
204
205 // we want to validate irrespective of the number of output formats
206 // specified as:
207 // - when only XML format there should be warnings as well (XML has its own write routines)
208 // - no formats there should be warnings as well
209 auto parser { createDocParser() };
210 auto ast { validatingParseText(*parser.get(), textStr) };
211
212 if (ast && count>0) writeDoc(ast.get(),nullptr,nullptr);
213}
214
215//--------------------------------------------------------------------------
216
218{
219 int orgSize = static_cast<int>(m_lineOffset.size());
220 if (orgSize<lineNr)
221 {
222 m_lineOffset.resize(lineNr);
223 for (int i=orgSize;i<lineNr;i++) // output lines can be skipped due to hidden comments so fill in the gap
224 {
225 //printf("%p: startCodeLine(%d) offset=%zu\n",(void*)this,i,m_calls.size());
226 m_lineOffset[i]=m_calls.size();
227 }
228 }
229}
230
232{
233 m_calls.emplace_back([]() { return true; },
234 [=](OutputCodeList *ol) { ol->codify(s); },
236 );
237}
238
240{
242 m_calls.emplace_back([]() { return true; },
243 [=](OutputCodeList *ol) { ol->startSpecialComment(); },
244 true
245 );
246}
247
249{
250 m_calls.emplace_back([]() { return true; },
251 [=](OutputCodeList *ol) { ol->endSpecialComment(); },
252 true
253 );
255}
256
258 const QCString &ref,const QCString &file,
259 const QCString &anchor,const QCString &name,
260 const QCString &tooltip)
261{
262 m_calls.emplace_back([](){ return true; },
263 [=](OutputCodeList *ol) { ol->writeCodeLink(type,ref,file,anchor,name,tooltip); },
265 );
266}
267
268void OutputCodeRecorder::writeLineNumber(const QCString &ref,const QCString &file,const QCString &anchor,
269 int lineNumber, bool writeLineAnchor)
270{
271 startNewLine(lineNumber);
272 m_calls.emplace_back([&]() { return m_showLineNumbers; },
273 [=](OutputCodeList *ol) { ol->writeLineNumber(ref,file,anchor,lineNumber,writeLineAnchor); },
275 );
276}
277
278void OutputCodeRecorder::writeTooltip(const QCString &id, const DocLinkInfo &docInfo, const QCString &decl,
279 const QCString &desc, const SourceLinkInfo &defInfo, const SourceLinkInfo &declInfo)
280{
281 m_calls.emplace_back([](){ return true; },
282 [=](OutputCodeList *ol) { ol->writeTooltip(id,docInfo,decl,desc,defInfo,declInfo); },
284 );
285}
286
288{
289 startNewLine(lineNr);
290 m_calls.emplace_back([](){ return true; },
291 [=](OutputCodeList *ol) { ol->startCodeLine(lineNr); },
293 );
294}
295
297{
298 m_calls.emplace_back([](){ return true; },
299 [=](OutputCodeList *ol) { ol->endCodeLine(); },
301 );
302}
303
305{
306 m_calls.emplace_back([]() { return true; },
307 [=](OutputCodeList *ol) { ol->startFontClass(c); },
309 );
310}
311
313{
314 m_calls.emplace_back([]() { return true; },
315 [=](OutputCodeList *ol){ ol->endFontClass(); },
317 );
318}
319
321{
322 m_calls.emplace_back([]() { return true; },
323 [=](OutputCodeList *ol){ ol->writeCodeAnchor(name); },
325 );
326}
327
331
335
336void OutputCodeRecorder::startFold(int lineNr,const QCString &startMarker,const QCString &endMarker)
337{
338 m_calls.emplace_back([]() { return true; },
339 [=](OutputCodeList *ol) { ol->startFold(lineNr,startMarker,endMarker); },
341 );
342}
343
345{
346 m_calls.emplace_back([]() { return true; },
347 [=](OutputCodeList *ol) { ol->endFold(); },
349 );
350}
351
352void OutputCodeRecorder::replay(OutputCodeList &ol,int startLine,int endLine,bool showLineNumbers,bool
353 stripCodeComments,size_t stripIndentAmount)
354{
355 size_t startIndex = startLine>0 && startLine<=(int)m_lineOffset.size() ? m_lineOffset[startLine-1] : 0;
356 size_t endIndex = endLine>0 && endLine <=(int)m_lineOffset.size() ? m_lineOffset[ endLine-1] : m_calls.size();
357 //printf("startIndex=%zu endIndex=%zu\n",startIndex,endIndex);
358
359 // configure run time properties of the rendering
361 ol.setStripIndentAmount(stripIndentAmount);
362 m_showLineNumbers = showLineNumbers;
363
364 bool insideSpecialComment = false;
365 // in case the start of the special comment marker is outside of the fragment, start it here
366 if (startIndex<endIndex && m_calls[startIndex].insideSpecialComment)
367 {
369 insideSpecialComment = true;
370 }
371
372 // render the requested fragment of the pre-recorded output
373 for (size_t i=startIndex; i<endIndex; i++)
374 {
375 if (m_calls[i].condition())
376 {
377 insideSpecialComment = m_calls[i].insideSpecialComment;
378 m_calls[i].function(&ol);
379 }
380 }
381
382 // if we end the fragment inside a special comment, make sure we end it,
383 // and also the code line
384 if (insideSpecialComment)
385 {
387 ol.endCodeLine();
388 }
389
390 ol.stripCodeComments(false);
392}
The common base class of all entity definitions found in the sources.
Definition definition.h:76
A model of a class/file/namespace member symbol.
Definition memberdef.h:48
Class representing a list of different code generators.
Definition outputlist.h:164
void endCodeLine()
Definition outputlist.h:266
void endSpecialComment()
Definition outputlist.h:243
void startSpecialComment()
Definition outputlist.h:240
void setStripIndentAmount(size_t amount)
Definition outputlist.h:246
void stripCodeComments(bool b)
Definition outputlist.h:237
void startFontClass(const QCString &c) override
void startFold(int lineNr, const QCString &startMarker, const QCString &endMarker) override
void writeTooltip(const QCString &id, const DocLinkInfo &docInfo, const QCString &decl, const QCString &desc, const SourceLinkInfo &defInfo, const SourceLinkInfo &declInfo) override
void endFold() override
void startCodeFragment(const QCString &style) override
void startCodeLine(int) override
void stripCodeComments(bool) override
Definition outputlist.h:116
void endFontClass() override
void startNewLine(int lineNr)
void writeCodeLink(CodeSymbolType type, const QCString &ref, const QCString &file, const QCString &anchor, const QCString &name, const QCString &tooltip) override
void codify(const QCString &s) override
std::vector< size_t > m_lineOffset
Definition outputlist.h:153
std::vector< CallInfo > m_calls
Definition outputlist.h:152
void replay(OutputCodeList &ol, int startLine, int endLine, bool showLineNumbers, bool stripComment, size_t stripIndentAmount)
void startSpecialComment() override
OutputType type() const override
Definition outputlist.h:114
void writeCodeAnchor(const QCString &name) override
void endSpecialComment() override
void endCodeFragment(const QCString &style) override
void endCodeLine() override
void writeLineNumber(const QCString &ref, const QCString &file, const QCString &anchor, int lineNumber, bool writeLineAnchor) override
virtual void startFile(const QCString &name, const QCString &manName, const QCString &title, int id, int hierarchyLevel)=0
bool isEnabled(OutputType o)
void disable(OutputType o)
OutputCodeList m_codeGenList
Definition outputlist.h:779
void enable(OutputType o)
std::vector< OutputGenElem > m_outputGenList
Definition outputlist.h:778
void writeDoc(const IDocNodeAST *ast, const Definition *ctx, const MemberDef *md)
Definition outputlist.h:385
OutputList & operator=(const OutputList &ol)
void startFile(const QCString &name, const QCString &manName, const QCString &title, int hierarchyLevel=0)
void newId()
void disableAll()
void syncEnabled()
void pushGeneratorState()
void disableAllBut(OutputType o)
void popGeneratorState()
void generateDoc(const QCString &fileName, int startLine, const Definition *ctx, const MemberDef *md, const QCString &docStr, bool indexWords, bool isExample, const QCString &exampleName, bool singleLine, bool linkFromIndex, bool markdownSupport=Config_getBool(MARKDOWN_SUPPORT), bool autolinkSupport=Config_getBool(AUTOLINK_SUPPORT))
void enableAll()
void parseText(const QCString &textStr)
void refreshCodeGenerators()
This is an alternative implementation of QCString.
Definition qcstring.h:101
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
IDocNodeASTPtr validatingParseText(IDocParser &parserIntf, const QCString &input)
IDocNodeASTPtr validatingParseDoc(IDocParser &parserIntf, const QCString &fileName, int startLine, const Definition *ctx, const MemberDef *md, const QCString &input, bool indexWords, bool isExample, const QCString &exampleName, bool singleLine, bool linkFromIndex, bool markdownSupport, bool autolinkSupport)
IDocParserPtr createDocParser()
factory function to create a parser
Definition docparser.cpp:55
#define AtomicInt
Definition doxygen.h:31
OutputType
Definition outputgen.h:59
static AtomicInt g_outId
CodeSymbolType
Definition types.h:481