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{
175 if (docStr.isEmpty()) return;
176
177 auto count=std::count_if(m_outputGenList.begin(),m_outputGenList.end(),
178 [](const auto &e) { return e.enabled; });
179 // we want to validate irrespective of the number of output formats
180 // specified as:
181 // - when only XML format there should be warnings as well (XML has its own write routines)
182 // - no formats there should be warnings as well
183 auto parser { createDocParser() };
184 auto ast { validatingParseDoc(*parser.get(),
185 fileName,startLine,
186 ctx,md,docStr,indexWords,isExample,exampleName,
187 singleLine,linkFromIndex,markdownSupport) };
188 if (ast && count>0) writeDoc(ast.get(),ctx,md);
189}
190
191void OutputList::startFile(const QCString &name,const QCString &manName,const QCString &title, int hierarchyLevel)
192{
193 newId();
194 m_codeGenList.setId(m_id);
195 foreach(&OutputGenIntf::startFile,name,manName,title,m_id,hierarchyLevel);
196}
197
198void OutputList::parseText(const QCString &textStr)
199{
200
201 auto count=std::count_if(m_outputGenList.begin(),m_outputGenList.end(),
202 [](const auto &e) { return e.enabled; });
203
204 // we want to validate irrespective of the number of output formats
205 // specified as:
206 // - when only XML format there should be warnings as well (XML has its own write routines)
207 // - no formats there should be warnings as well
208 auto parser { createDocParser() };
209 auto ast { validatingParseText(*parser.get(), textStr) };
210
211 if (ast && count>0) writeDoc(ast.get(),nullptr,nullptr);
212}
213
214//--------------------------------------------------------------------------
215
217{
218 int orgSize = static_cast<int>(m_lineOffset.size());
219 if (orgSize<lineNr)
220 {
221 m_lineOffset.resize(lineNr);
222 for (int i=orgSize;i<lineNr;i++) // output lines can be skipped due to hidden comments so fill in the gap
223 {
224 //printf("%p: startCodeLine(%d) offset=%zu\n",(void*)this,i,m_calls.size());
225 m_lineOffset[i]=m_calls.size();
226 }
227 }
228}
229
231{
232 m_calls.emplace_back([]() { return true; },
233 [=](OutputCodeList *ol) { ol->codify(s); },
235 );
236}
237
239{
241 m_calls.emplace_back([]() { return true; },
242 [=](OutputCodeList *ol) { ol->startSpecialComment(); },
243 true
244 );
245}
246
248{
249 m_calls.emplace_back([]() { return true; },
250 [=](OutputCodeList *ol) { ol->endSpecialComment(); },
251 true
252 );
254}
255
257 const QCString &ref,const QCString &file,
258 const QCString &anchor,const QCString &name,
259 const QCString &tooltip)
260{
261 m_calls.emplace_back([](){ return true; },
262 [=](OutputCodeList *ol) { ol->writeCodeLink(type,ref,file,anchor,name,tooltip); },
264 );
265}
266
267void OutputCodeRecorder::writeLineNumber(const QCString &ref,const QCString &file,const QCString &anchor,
268 int lineNumber, bool writeLineAnchor)
269{
270 startNewLine(lineNumber);
271 m_calls.emplace_back([&]() { return m_showLineNumbers; },
272 [=](OutputCodeList *ol) { ol->writeLineNumber(ref,file,anchor,lineNumber,writeLineAnchor); },
274 );
275}
276
277void OutputCodeRecorder::writeTooltip(const QCString &id, const DocLinkInfo &docInfo, const QCString &decl,
278 const QCString &desc, const SourceLinkInfo &defInfo, const SourceLinkInfo &declInfo)
279{
280 m_calls.emplace_back([](){ return true; },
281 [=](OutputCodeList *ol) { ol->writeTooltip(id,docInfo,decl,desc,defInfo,declInfo); },
283 );
284}
285
287{
288 startNewLine(lineNr);
289 m_calls.emplace_back([](){ return true; },
290 [=](OutputCodeList *ol) { ol->startCodeLine(lineNr); },
292 );
293}
294
296{
297 m_calls.emplace_back([](){ return true; },
298 [=](OutputCodeList *ol) { ol->endCodeLine(); },
300 );
301}
302
304{
305 m_calls.emplace_back([]() { return true; },
306 [=](OutputCodeList *ol) { ol->startFontClass(c); },
308 );
309}
310
312{
313 m_calls.emplace_back([]() { return true; },
314 [=](OutputCodeList *ol){ ol->endFontClass(); },
316 );
317}
318
320{
321 m_calls.emplace_back([]() { return true; },
322 [=](OutputCodeList *ol){ ol->writeCodeAnchor(name); },
324 );
325}
326
330
334
335void OutputCodeRecorder::startFold(int lineNr,const QCString &startMarker,const QCString &endMarker)
336{
337 m_calls.emplace_back([]() { return true; },
338 [=](OutputCodeList *ol) { ol->startFold(lineNr,startMarker,endMarker); },
340 );
341}
342
344{
345 m_calls.emplace_back([]() { return true; },
346 [=](OutputCodeList *ol) { ol->endFold(); },
348 );
349}
350
351void OutputCodeRecorder::replay(OutputCodeList &ol,int startLine,int endLine,bool showLineNumbers,bool
352 stripCodeComments,size_t stripIndentAmount)
353{
354 size_t startIndex = startLine>0 && startLine<=(int)m_lineOffset.size() ? m_lineOffset[startLine-1] : 0;
355 size_t endIndex = endLine>0 && endLine <=(int)m_lineOffset.size() ? m_lineOffset[ endLine-1] : m_calls.size();
356 //printf("startIndex=%zu endIndex=%zu\n",startIndex,endIndex);
357
358 // configure run time properties of the rendering
360 ol.setStripIndentAmount(stripIndentAmount);
361 m_showLineNumbers = showLineNumbers;
362
363 bool insideSpecialComment = false;
364 // in case the start of the special comment marker is outside of the fragment, start it here
365 if (startIndex<endIndex && m_calls[startIndex].insideSpecialComment)
366 {
368 insideSpecialComment = true;
369 }
370
371 // render the requested fragment of the pre-recorded output
372 for (size_t i=startIndex; i<endIndex; i++)
373 {
374 if (m_calls[i].condition())
375 {
376 insideSpecialComment = m_calls[i].insideSpecialComment;
377 m_calls[i].function(&ol);
378 }
379 }
380
381 // if we end the fragment inside a special comment, make sure we end it,
382 // and also the code line
383 if (insideSpecialComment)
384 {
386 ol.endCodeLine();
387 }
388}
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:770
void enable(OutputType o)
std::vector< OutputGenElem > m_outputGenList
Definition outputlist.h:769
void writeDoc(const IDocNodeAST *ast, const Definition *ctx, const MemberDef *md)
Definition outputlist.h:384
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 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)
void pushGeneratorState()
void disableAllBut(OutputType o)
void popGeneratorState()
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)
IDocParserPtr createDocParser()
factory function to create a parser
Definition docparser.cpp:54
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)
#define AtomicInt
Definition doxygen.h:31
OutputType
Definition outputgen.h:59
static AtomicInt g_outId
CodeSymbolType
Definition types.h:319