Skip to content

Commit 0815bb7

Browse files
committed
Refactoring: OutputList & OutputGen
- Initialized member variables inside the class - Added copy & assign operators for OutputGenerator and Derived classes. - throw a runtime exception when OutputGenerator is copied while is file is still in progress. - Added clone method to make a copy of OutputList. - Moved the implementation of enable() & disable() and friend into OutputGen instead of having the same implementation in each derived class. - Made m_dir and m_fileName readonly (members dir() and fileName()) - Removed call to new while adding generators to OutputList - Replaced QStack by std::stack for the "enabled" state.
1 parent 8b3efba commit 0815bb7

17 files changed

+515
-433
lines changed

src/code.l

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <ctype.h>
3737
#include <qregexp.h>
3838
#include <qdir.h>
39+
#include <qstack.h>
3940

4041
#include "code.h"
4142
#include "entry.h"

src/docbookgen.cpp

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ inline void writeDocbookCodeString(FTextStream &t,const char *s, int &col)
8989
{
9090
case '\t':
9191
{
92-
static int tabSize = Config_getInt(TAB_SIZE);
92+
int tabSize = Config_getInt(TAB_SIZE);
9393
int spacesToNextTabStop = tabSize - (col%tabSize);
9494
col+=spacesToNextTabStop;
9595
while (spacesToNextTabStop--) t << "&#32;";
@@ -140,7 +140,6 @@ DocbookCodeGenerator::DocbookCodeGenerator(FTextStream &t)
140140

141141
DocbookCodeGenerator::DocbookCodeGenerator()
142142
{
143-
m_prettyCode=Config_getBool(DOCBOOK_PROGRAMLISTING);
144143
}
145144

146145
DocbookCodeGenerator::~DocbookCodeGenerator() {}
@@ -255,25 +254,24 @@ void DocbookCodeGenerator::endCodeFragment()
255254
m_t << "</computeroutput></literallayout>" << endl;
256255
}
257256

258-
DocbookGenerator::DocbookGenerator() : OutputGenerator()
257+
DocbookGenerator::DocbookGenerator() : OutputGenerator(Config_getString(DOCBOOK_OUTPUT))
259258
{
260259
DB_GEN_C
261-
m_dir=Config_getString(DOCBOOK_OUTPUT);
262-
//insideTabbing=FALSE;
263-
//firstDescItem=TRUE;
264-
//disableLinks=FALSE;
265-
//m_indent=0;
266-
//templateMemberItem = FALSE;
267-
m_prettyCode=Config_getBool(DOCBOOK_PROGRAMLISTING);
268-
m_denseText = FALSE;
269-
m_inGroup = FALSE;
270-
m_inDetail = FALSE;
271-
m_levelListItem = 0;
272-
m_descTable = FALSE;
273-
m_inLevel = -1;
274-
m_firstMember = FALSE;
275-
for (size_t i = 0 ; i < sizeof(m_inListItem) / sizeof(*m_inListItem) ; i++) m_inListItem[i] = FALSE;
276-
for (size_t i = 0 ; i < sizeof(m_inSimpleSect) / sizeof(*m_inSimpleSect) ; i++) m_inSimpleSect[i] = FALSE;
260+
}
261+
262+
DocbookGenerator::DocbookGenerator(const DocbookGenerator &og) : OutputGenerator(og)
263+
{
264+
}
265+
266+
DocbookGenerator &DocbookGenerator::operator=(const DocbookGenerator &og)
267+
{
268+
OutputGenerator::operator=(og);
269+
return *this;
270+
}
271+
272+
std::unique_ptr<OutputGenerator> DocbookGenerator::clone() const
273+
{
274+
return std::make_unique<DocbookGenerator>(*this);
277275
}
278276

279277
DocbookGenerator::~DocbookGenerator()
@@ -428,7 +426,7 @@ DB_GEN_C2("IndexSections " << is)
428426
void DocbookGenerator::endIndexSection(IndexSections is)
429427
{
430428
DB_GEN_C2("IndexSections " << is)
431-
static bool sourceBrowser = Config_getBool(SOURCE_BROWSER);
429+
bool sourceBrowser = Config_getBool(SOURCE_BROWSER);
432430
switch (is)
433431
{
434432
case isTitlePageStart:
@@ -913,7 +911,7 @@ DB_GEN_C
913911
t << " <imagedata width=\"50%\" align=\"center\" valign=\"middle\" scalefit=\"0\" fileref=\""
914912
<< relPath << fileName << ".png\">" << "</imagedata>" << endl;
915913
t << " </imageobject>" << endl;
916-
d.writeImage(t,m_dir,relPath,fileName,FALSE);
914+
d.writeImage(t,dir(),relPath,fileName,FALSE);
917915
t << " </mediaobject>" << endl;
918916
t << " </informalfigure>" << endl;
919917
t << "</para>" << endl;
@@ -1104,7 +1102,7 @@ DB_GEN_C
11041102
void DocbookGenerator::endGroupCollaboration(DotGroupCollaboration &g)
11051103
{
11061104
DB_GEN_C
1107-
g.writeGraph(t,GOF_BITMAP,EOF_DocBook,Config_getString(DOCBOOK_OUTPUT),m_fileName,relPath,FALSE);
1105+
g.writeGraph(t,GOF_BITMAP,EOF_DocBook,dir(),fileName(),relPath,FALSE);
11081106
}
11091107
void DocbookGenerator::startDotGraph()
11101108
{
@@ -1113,7 +1111,7 @@ DB_GEN_C
11131111
void DocbookGenerator::endDotGraph(DotClassGraph &g)
11141112
{
11151113
DB_GEN_C
1116-
g.writeGraph(t,GOF_BITMAP,EOF_DocBook,Config_getString(DOCBOOK_OUTPUT),m_fileName,relPath,TRUE,FALSE);
1114+
g.writeGraph(t,GOF_BITMAP,EOF_DocBook,dir(),fileName(),relPath,TRUE,FALSE);
11171115
}
11181116
void DocbookGenerator::startInclDepGraph()
11191117
{
@@ -1122,7 +1120,7 @@ DB_GEN_C
11221120
void DocbookGenerator::endInclDepGraph(DotInclDepGraph &g)
11231121
{
11241122
DB_GEN_C
1125-
QCString fn = g.writeGraph(t,GOF_BITMAP,EOF_DocBook,Config_getString(DOCBOOK_OUTPUT), m_fileName,relPath,FALSE);
1123+
QCString fn = g.writeGraph(t,GOF_BITMAP,EOF_DocBook,dir(),fileName(),relPath,FALSE);
11261124
}
11271125
void DocbookGenerator::startCallGraph()
11281126
{
@@ -1131,7 +1129,7 @@ DB_GEN_C
11311129
void DocbookGenerator::endCallGraph(DotCallGraph &g)
11321130
{
11331131
DB_GEN_C
1134-
QCString fn = g.writeGraph(t,GOF_BITMAP,EOF_DocBook,Config_getString(DOCBOOK_OUTPUT), m_fileName,relPath,FALSE);
1132+
QCString fn = g.writeGraph(t,GOF_BITMAP,EOF_DocBook,dir(),fileName(),relPath,FALSE);
11351133
}
11361134
void DocbookGenerator::startDirDepGraph()
11371135
{
@@ -1140,7 +1138,7 @@ DB_GEN_C
11401138
void DocbookGenerator::endDirDepGraph(DotDirDeps &g)
11411139
{
11421140
DB_GEN_C
1143-
QCString fn = g.writeGraph(t,GOF_BITMAP,EOF_DocBook,Config_getString(DOCBOOK_OUTPUT), m_fileName,relPath,FALSE);
1141+
QCString fn = g.writeGraph(t,GOF_BITMAP,EOF_DocBook,dir(),fileName(),relPath,FALSE);
11441142
}
11451143
void DocbookGenerator::startMemberDocList()
11461144
{

src/docbookgen.h

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/******************************************************************************
22
*
3-
*
3+
*
44
*
55
* Copyright (C) 1997-2015 by Dimitri van Heesch.
66
*
@@ -15,6 +15,7 @@
1515
#ifndef DOCBOOKGEN_H
1616
#define DOCBOOKGEN_H
1717

18+
#include "config.h"
1819
#include "outputgen.h"
1920

2021
class DocbookCodeGenerator : public CodeOutputInterface
@@ -57,16 +58,16 @@ class DocbookCodeGenerator : public CodeOutputInterface
5758

5859
private:
5960
FTextStream m_t;
60-
bool m_streamSet = FALSE;
61+
bool m_streamSet = false;
6162
QCString m_refId;
6263
QCString m_external;
6364
int m_lineNumber = -1;
6465
int m_col = 0;
65-
bool m_insideCodeLine = FALSE;
66-
bool m_insideSpecialHL = FALSE;
66+
bool m_insideCodeLine = false;
67+
bool m_insideSpecialHL = false;
6768
QCString m_relPath;
6869
QCString m_sourceFileName;
69-
bool m_prettyCode = FALSE;
70+
bool m_prettyCode = Config_getBool(DOCBOOK_PROGRAMLISTING);
7071
};
7172

7273

@@ -97,20 +98,14 @@ class DocbookGenerator : public OutputGenerator
9798
{
9899
public:
99100
DocbookGenerator();
100-
~DocbookGenerator();
101+
DocbookGenerator(const DocbookGenerator &o);
102+
DocbookGenerator &operator=(const DocbookGenerator &o);
103+
virtual ~DocbookGenerator();
104+
virtual std::unique_ptr<OutputGenerator> clone() const;
105+
101106
static void init();
102107

103-
///////////////////////////////////////////////////////////////
104-
// generic generator methods
105-
///////////////////////////////////////////////////////////////
106-
void enable()
107-
{ if (m_genStack->top()) m_active=*m_genStack->top(); else m_active=TRUE; }
108-
void disable() { m_active=FALSE; }
109-
void enableIf(OutputType o) { if (o==Docbook) enable(); }
110-
void disableIf(OutputType o) { if (o==Docbook) disable(); }
111-
void disableIfNot(OutputType o) { if (o!=Docbook) disable(); }
112-
bool isEnabled(OutputType o) { return (o==Docbook && m_active); }
113-
OutputGenerator *get(OutputType o) { return (o==Docbook) ? this : 0; }
108+
OutputType type() const { return Docbook; }
114109

115110
// --- CodeOutputInterface
116111
void codify(const char *text)
@@ -343,21 +338,19 @@ class DocbookGenerator : public OutputGenerator
343338
void addWord(const char *,bool) {DB_GEN_EMPTY}
344339

345340
private:
346-
DocbookGenerator(const DocbookGenerator &o);
347-
DocbookGenerator &operator=(const DocbookGenerator &o);
348-
341+
349342
QCString relPath;
350343
DocbookCodeGenerator m_codeGen;
351-
bool m_prettyCode;
352-
bool m_denseText;
353-
bool m_inGroup;
354-
bool m_inDetail;
355-
int m_levelListItem;
356-
bool m_inListItem[20];
357-
bool m_inSimpleSect[20];
358-
bool m_descTable;
359-
int m_inLevel;
360-
bool m_firstMember;
344+
bool m_prettyCode = Config_getBool(DOCBOOK_PROGRAMLISTING);
345+
bool m_denseText = false;
346+
bool m_inGroup = false;
347+
bool m_inDetail = false;
348+
int m_levelListItem = 0;
349+
bool m_inListItem[20] = { false, };
350+
bool m_inSimpleSect[20] = { false, };
351+
bool m_descTable = false;
352+
int m_inLevel = -1;
353+
bool m_firstMember = false;
361354
};
362355

363356
#endif

src/doxygen.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7586,7 +7586,6 @@ static void generateFileSources()
75867586
{
75877587
msg("Generating code for file %s...\n",fd->docName().data());
75887588
fd->writeSource(*g_outputList,nullptr);
7589-
75907589
}
75917590
else if (!fd->isReference() && Doxygen::parseSourcesNeeded)
75927591
// we needed to parse the sources even if we do not show them
@@ -11383,10 +11382,10 @@ void generateOutput()
1138311382
bool generateDocbook = Config_getBool(GENERATE_DOCBOOK);
1138411383

1138511384

11386-
g_outputList = new OutputList(TRUE);
11385+
g_outputList = new OutputList;
1138711386
if (generateHtml)
1138811387
{
11389-
g_outputList->add(new HtmlGenerator);
11388+
g_outputList->add<HtmlGenerator>();
1139011389
HtmlGenerator::init();
1139111390

1139211391
// add HTML indexers that are enabled
@@ -11405,22 +11404,22 @@ void generateOutput()
1140511404
}
1140611405
if (generateLatex)
1140711406
{
11408-
g_outputList->add(new LatexGenerator);
11407+
g_outputList->add<LatexGenerator>();
1140911408
LatexGenerator::init();
1141011409
}
1141111410
if (generateDocbook)
1141211411
{
11413-
g_outputList->add(new DocbookGenerator);
11412+
g_outputList->add<DocbookGenerator>();
1141411413
DocbookGenerator::init();
1141511414
}
1141611415
if (generateMan)
1141711416
{
11418-
g_outputList->add(new ManGenerator);
11417+
g_outputList->add<ManGenerator>();
1141911418
ManGenerator::init();
1142011419
}
1142111420
if (generateRtf)
1142211421
{
11423-
g_outputList->add(new RTFGenerator);
11422+
g_outputList->add<RTFGenerator>();
1142411423
RTFGenerator::init();
1142511424
}
1142611425
if (Config_getBool(USE_HTAGS))
@@ -11533,7 +11532,7 @@ void generateOutput()
1153311532
generateDirDocs(*g_outputList);
1153411533
g_s.end();
1153511534

11536-
if (g_outputList->count()>0)
11535+
if (g_outputList->size()>0)
1153711536
{
1153811537
writeIndexHierarchy(*g_outputList);
1153911538
}

src/filedef.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,11 +1151,11 @@ void FileDefImpl::writeQuickMemberLinks(OutputList &ol,const MemberDef *currentM
11511151
/*! Write a source listing of this file to the output */
11521152
void FileDefImpl::writeSource(OutputList &ol,ClangTUParser *clangParser)
11531153
{
1154-
static bool generateTreeView = Config_getBool(GENERATE_TREEVIEW);
1155-
static bool filterSourceFiles = Config_getBool(FILTER_SOURCE_FILES);
1156-
static bool latexSourceCode = Config_getBool(LATEX_SOURCE_CODE);
1157-
static bool docbookSourceCode = Config_getBool(DOCBOOK_PROGRAMLISTING);
1158-
static bool rtfSourceCode = Config_getBool(RTF_SOURCE_CODE);
1154+
bool generateTreeView = Config_getBool(GENERATE_TREEVIEW);
1155+
bool filterSourceFiles = Config_getBool(FILTER_SOURCE_FILES);
1156+
bool latexSourceCode = Config_getBool(LATEX_SOURCE_CODE);
1157+
bool docbookSourceCode = Config_getBool(DOCBOOK_PROGRAMLISTING);
1158+
bool rtfSourceCode = Config_getBool(RTF_SOURCE_CODE);
11591159
DevNullCodeDocInterface devNullIntf;
11601160
QCString title = m_docname;
11611161
if (!m_fileVersion.isEmpty())

0 commit comments

Comments
 (0)