From 0815bb7d5c99fccdbdba24fb933f9e7fce29bbc6 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Sun, 9 Aug 2020 20:55:22 +0200 Subject: 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. --- src/code.l | 1 + src/docbookgen.cpp | 50 ++++++++++---------- src/docbookgen.h | 53 +++++++++------------ src/doxygen.cpp | 15 +++--- src/filedef.cpp | 10 ++-- src/htmlgen.cpp | 136 +++++++++++++++++++++++++++++------------------------ src/htmlgen.h | 54 +++++++++------------ src/latexgen.cpp | 100 ++++++++++++++++++++------------------- src/latexgen.h | 49 +++++++++---------- src/mangen.cpp | 26 ++++++---- src/mangen.h | 53 +++++++++------------ src/outputgen.cpp | 113 +++++++++++++++++++++++++++++++++++--------- src/outputgen.h | 134 ++++++++++++++++++++++++++-------------------------- src/outputlist.cpp | 26 ++++++++-- src/outputlist.h | 15 ++++-- src/rtfgen.cpp | 44 +++++++++-------- src/rtfgen.h | 69 ++++++++++++--------------- 17 files changed, 515 insertions(+), 433 deletions(-) diff --git a/src/code.l b/src/code.l index 6627498..56b0e0f 100644 --- a/src/code.l +++ b/src/code.l @@ -36,6 +36,7 @@ #include #include #include +#include #include "code.h" #include "entry.h" diff --git a/src/docbookgen.cpp b/src/docbookgen.cpp index e5c9a6b..da7987b 100644 --- a/src/docbookgen.cpp +++ b/src/docbookgen.cpp @@ -89,7 +89,7 @@ inline void writeDocbookCodeString(FTextStream &t,const char *s, int &col) { case '\t': { - static int tabSize = Config_getInt(TAB_SIZE); + int tabSize = Config_getInt(TAB_SIZE); int spacesToNextTabStop = tabSize - (col%tabSize); col+=spacesToNextTabStop; while (spacesToNextTabStop--) t << " "; @@ -140,7 +140,6 @@ DocbookCodeGenerator::DocbookCodeGenerator(FTextStream &t) DocbookCodeGenerator::DocbookCodeGenerator() { - m_prettyCode=Config_getBool(DOCBOOK_PROGRAMLISTING); } DocbookCodeGenerator::~DocbookCodeGenerator() {} @@ -255,25 +254,24 @@ void DocbookCodeGenerator::endCodeFragment() m_t << "" << endl; } -DocbookGenerator::DocbookGenerator() : OutputGenerator() +DocbookGenerator::DocbookGenerator() : OutputGenerator(Config_getString(DOCBOOK_OUTPUT)) { DB_GEN_C - m_dir=Config_getString(DOCBOOK_OUTPUT); - //insideTabbing=FALSE; - //firstDescItem=TRUE; - //disableLinks=FALSE; - //m_indent=0; - //templateMemberItem = FALSE; - m_prettyCode=Config_getBool(DOCBOOK_PROGRAMLISTING); - m_denseText = FALSE; - m_inGroup = FALSE; - m_inDetail = FALSE; - m_levelListItem = 0; - m_descTable = FALSE; - m_inLevel = -1; - m_firstMember = FALSE; - for (size_t i = 0 ; i < sizeof(m_inListItem) / sizeof(*m_inListItem) ; i++) m_inListItem[i] = FALSE; - for (size_t i = 0 ; i < sizeof(m_inSimpleSect) / sizeof(*m_inSimpleSect) ; i++) m_inSimpleSect[i] = FALSE; +} + +DocbookGenerator::DocbookGenerator(const DocbookGenerator &og) : OutputGenerator(og) +{ +} + +DocbookGenerator &DocbookGenerator::operator=(const DocbookGenerator &og) +{ + OutputGenerator::operator=(og); + return *this; +} + +std::unique_ptr DocbookGenerator::clone() const +{ + return std::make_unique(*this); } DocbookGenerator::~DocbookGenerator() @@ -428,7 +426,7 @@ DB_GEN_C2("IndexSections " << is) void DocbookGenerator::endIndexSection(IndexSections is) { DB_GEN_C2("IndexSections " << is) - static bool sourceBrowser = Config_getBool(SOURCE_BROWSER); + bool sourceBrowser = Config_getBool(SOURCE_BROWSER); switch (is) { case isTitlePageStart: @@ -913,7 +911,7 @@ DB_GEN_C t << " " << "" << endl; t << " " << endl; - d.writeImage(t,m_dir,relPath,fileName,FALSE); + d.writeImage(t,dir(),relPath,fileName,FALSE); t << " " << endl; t << " " << endl; t << "" << endl; @@ -1104,7 +1102,7 @@ DB_GEN_C void DocbookGenerator::endGroupCollaboration(DotGroupCollaboration &g) { DB_GEN_C - g.writeGraph(t,GOF_BITMAP,EOF_DocBook,Config_getString(DOCBOOK_OUTPUT),m_fileName,relPath,FALSE); + g.writeGraph(t,GOF_BITMAP,EOF_DocBook,dir(),fileName(),relPath,FALSE); } void DocbookGenerator::startDotGraph() { @@ -1113,7 +1111,7 @@ DB_GEN_C void DocbookGenerator::endDotGraph(DotClassGraph &g) { DB_GEN_C - g.writeGraph(t,GOF_BITMAP,EOF_DocBook,Config_getString(DOCBOOK_OUTPUT),m_fileName,relPath,TRUE,FALSE); + g.writeGraph(t,GOF_BITMAP,EOF_DocBook,dir(),fileName(),relPath,TRUE,FALSE); } void DocbookGenerator::startInclDepGraph() { @@ -1122,7 +1120,7 @@ DB_GEN_C void DocbookGenerator::endInclDepGraph(DotInclDepGraph &g) { DB_GEN_C - QCString fn = g.writeGraph(t,GOF_BITMAP,EOF_DocBook,Config_getString(DOCBOOK_OUTPUT), m_fileName,relPath,FALSE); + QCString fn = g.writeGraph(t,GOF_BITMAP,EOF_DocBook,dir(),fileName(),relPath,FALSE); } void DocbookGenerator::startCallGraph() { @@ -1131,7 +1129,7 @@ DB_GEN_C void DocbookGenerator::endCallGraph(DotCallGraph &g) { DB_GEN_C - QCString fn = g.writeGraph(t,GOF_BITMAP,EOF_DocBook,Config_getString(DOCBOOK_OUTPUT), m_fileName,relPath,FALSE); + QCString fn = g.writeGraph(t,GOF_BITMAP,EOF_DocBook,dir(),fileName(),relPath,FALSE); } void DocbookGenerator::startDirDepGraph() { @@ -1140,7 +1138,7 @@ DB_GEN_C void DocbookGenerator::endDirDepGraph(DotDirDeps &g) { DB_GEN_C - QCString fn = g.writeGraph(t,GOF_BITMAP,EOF_DocBook,Config_getString(DOCBOOK_OUTPUT), m_fileName,relPath,FALSE); + QCString fn = g.writeGraph(t,GOF_BITMAP,EOF_DocBook,dir(),fileName(),relPath,FALSE); } void DocbookGenerator::startMemberDocList() { diff --git a/src/docbookgen.h b/src/docbookgen.h index bed2f5f..0fefe4b 100644 --- a/src/docbookgen.h +++ b/src/docbookgen.h @@ -1,6 +1,6 @@ /****************************************************************************** * -* +* * * Copyright (C) 1997-2015 by Dimitri van Heesch. * @@ -15,6 +15,7 @@ #ifndef DOCBOOKGEN_H #define DOCBOOKGEN_H +#include "config.h" #include "outputgen.h" class DocbookCodeGenerator : public CodeOutputInterface @@ -57,16 +58,16 @@ class DocbookCodeGenerator : public CodeOutputInterface private: FTextStream m_t; - bool m_streamSet = FALSE; + bool m_streamSet = false; QCString m_refId; QCString m_external; int m_lineNumber = -1; int m_col = 0; - bool m_insideCodeLine = FALSE; - bool m_insideSpecialHL = FALSE; + bool m_insideCodeLine = false; + bool m_insideSpecialHL = false; QCString m_relPath; QCString m_sourceFileName; - bool m_prettyCode = FALSE; + bool m_prettyCode = Config_getBool(DOCBOOK_PROGRAMLISTING); }; @@ -97,20 +98,14 @@ class DocbookGenerator : public OutputGenerator { public: DocbookGenerator(); - ~DocbookGenerator(); + DocbookGenerator(const DocbookGenerator &o); + DocbookGenerator &operator=(const DocbookGenerator &o); + virtual ~DocbookGenerator(); + virtual std::unique_ptr clone() const; + static void init(); - /////////////////////////////////////////////////////////////// - // generic generator methods - /////////////////////////////////////////////////////////////// - void enable() - { if (m_genStack->top()) m_active=*m_genStack->top(); else m_active=TRUE; } - void disable() { m_active=FALSE; } - void enableIf(OutputType o) { if (o==Docbook) enable(); } - void disableIf(OutputType o) { if (o==Docbook) disable(); } - void disableIfNot(OutputType o) { if (o!=Docbook) disable(); } - bool isEnabled(OutputType o) { return (o==Docbook && m_active); } - OutputGenerator *get(OutputType o) { return (o==Docbook) ? this : 0; } + OutputType type() const { return Docbook; } // --- CodeOutputInterface void codify(const char *text) @@ -343,21 +338,19 @@ class DocbookGenerator : public OutputGenerator void addWord(const char *,bool) {DB_GEN_EMPTY} private: - DocbookGenerator(const DocbookGenerator &o); - DocbookGenerator &operator=(const DocbookGenerator &o); - + QCString relPath; DocbookCodeGenerator m_codeGen; - bool m_prettyCode; - bool m_denseText; - bool m_inGroup; - bool m_inDetail; - int m_levelListItem; - bool m_inListItem[20]; - bool m_inSimpleSect[20]; - bool m_descTable; - int m_inLevel; - bool m_firstMember; + bool m_prettyCode = Config_getBool(DOCBOOK_PROGRAMLISTING); + bool m_denseText = false; + bool m_inGroup = false; + bool m_inDetail = false; + int m_levelListItem = 0; + bool m_inListItem[20] = { false, }; + bool m_inSimpleSect[20] = { false, }; + bool m_descTable = false; + int m_inLevel = -1; + bool m_firstMember = false; }; #endif diff --git a/src/doxygen.cpp b/src/doxygen.cpp index 4b5c267..757e783 100644 --- a/src/doxygen.cpp +++ b/src/doxygen.cpp @@ -7586,7 +7586,6 @@ static void generateFileSources() { msg("Generating code for file %s...\n",fd->docName().data()); fd->writeSource(*g_outputList,nullptr); - } else if (!fd->isReference() && Doxygen::parseSourcesNeeded) // we needed to parse the sources even if we do not show them @@ -11383,10 +11382,10 @@ void generateOutput() bool generateDocbook = Config_getBool(GENERATE_DOCBOOK); - g_outputList = new OutputList(TRUE); + g_outputList = new OutputList; if (generateHtml) { - g_outputList->add(new HtmlGenerator); + g_outputList->add(); HtmlGenerator::init(); // add HTML indexers that are enabled @@ -11405,22 +11404,22 @@ void generateOutput() } if (generateLatex) { - g_outputList->add(new LatexGenerator); + g_outputList->add(); LatexGenerator::init(); } if (generateDocbook) { - g_outputList->add(new DocbookGenerator); + g_outputList->add(); DocbookGenerator::init(); } if (generateMan) { - g_outputList->add(new ManGenerator); + g_outputList->add(); ManGenerator::init(); } if (generateRtf) { - g_outputList->add(new RTFGenerator); + g_outputList->add(); RTFGenerator::init(); } if (Config_getBool(USE_HTAGS)) @@ -11533,7 +11532,7 @@ void generateOutput() generateDirDocs(*g_outputList); g_s.end(); - if (g_outputList->count()>0) + if (g_outputList->size()>0) { writeIndexHierarchy(*g_outputList); } diff --git a/src/filedef.cpp b/src/filedef.cpp index 15fd1e5..f07201d 100644 --- a/src/filedef.cpp +++ b/src/filedef.cpp @@ -1151,11 +1151,11 @@ void FileDefImpl::writeQuickMemberLinks(OutputList &ol,const MemberDef *currentM /*! Write a source listing of this file to the output */ void FileDefImpl::writeSource(OutputList &ol,ClangTUParser *clangParser) { - static bool generateTreeView = Config_getBool(GENERATE_TREEVIEW); - static bool filterSourceFiles = Config_getBool(FILTER_SOURCE_FILES); - static bool latexSourceCode = Config_getBool(LATEX_SOURCE_CODE); - static bool docbookSourceCode = Config_getBool(DOCBOOK_PROGRAMLISTING); - static bool rtfSourceCode = Config_getBool(RTF_SOURCE_CODE); + bool generateTreeView = Config_getBool(GENERATE_TREEVIEW); + bool filterSourceFiles = Config_getBool(FILTER_SOURCE_FILES); + bool latexSourceCode = Config_getBool(LATEX_SOURCE_CODE); + bool docbookSourceCode = Config_getBool(DOCBOOK_PROGRAMLISTING); + bool rtfSourceCode = Config_getBool(RTF_SOURCE_CODE); DevNullCodeDocInterface devNullIntf; QCString title = m_docname; if (!m_fileVersion.isEmpty()) diff --git a/src/htmlgen.cpp b/src/htmlgen.cpp index 7b125af..e4684ef 100644 --- a/src/htmlgen.cpp +++ b/src/htmlgen.cpp @@ -87,7 +87,7 @@ static void writeClientSearchBox(FTextStream &t,const char *relPath) // part will be rendered inside menu.js static void writeServerSearchBox(FTextStream &t,const char *relPath,bool highlightSearch) { - static bool externalSearch = Config_getBool(EXTERNAL_SEARCH); + bool externalSearch = Config_getBool(EXTERNAL_SEARCH); t << "
\n"; t << "
\n"; t << "
HtmlGenerator::clone() const +{ + return std::make_unique(*this); } HtmlGenerator::~HtmlGenerator() @@ -922,9 +934,10 @@ HtmlGenerator::~HtmlGenerator() //printf("HtmlGenerator::~HtmlGenerator()\n"); } + void HtmlGenerator::init() { - QCString dname=Config_getString(HTML_OUTPUT); + QCString dname = Config_getString(HTML_OUTPUT); QDir d(dname); if (!d.exists() && !d.mkdir(dname)) { @@ -1032,32 +1045,32 @@ void HtmlGenerator::writeTabData() mgr.copyResource("nav_g.png",dname); } -void HtmlGenerator::writeSearchData(const char *dir) +void HtmlGenerator::writeSearchData(const char *dname) { - static bool serverBasedSearch = Config_getBool(SERVER_BASED_SEARCH); - //writeImgData(dir,serverBasedSearch ? search_server_data : search_client_data); + bool serverBasedSearch = Config_getBool(SERVER_BASED_SEARCH); + //writeImgData(dname,serverBasedSearch ? search_server_data : search_client_data); ResourceMgr &mgr = ResourceMgr::instance(); - mgr.copyResource("search_l.png",dir); + mgr.copyResource("search_l.png",dname); Doxygen::indexList->addImageFile("search/search_l.png"); - mgr.copyResource("search_m.png",dir); + mgr.copyResource("search_m.png",dname); Doxygen::indexList->addImageFile("search/search_m.png"); - mgr.copyResource("search_r.png",dir); + mgr.copyResource("search_r.png",dname); Doxygen::indexList->addImageFile("search/search_r.png"); if (serverBasedSearch) { - mgr.copyResource("mag.svg",dir); + mgr.copyResource("mag.svg",dname); Doxygen::indexList->addImageFile("search/mag.svg"); } else { - mgr.copyResource("close.svg",dir); + mgr.copyResource("close.svg",dname); Doxygen::indexList->addImageFile("search/close.svg"); - mgr.copyResource("mag_sel.svg",dir); + mgr.copyResource("mag_sel.svg",dname); Doxygen::indexList->addImageFile("search/mag_sel.svg"); } - QCString searchDirName = Config_getString(HTML_OUTPUT)+"/search"; + QCString searchDirName = QCString(dname)+"/search"; QFile f(searchDirName+"/search.css"); if (f.open(IO_WriteOnly)) { @@ -1119,8 +1132,8 @@ void HtmlGenerator::startFile(const char *name,const char *, t << "" << endl; - //static bool generateTreeView = Config_getBool(GENERATE_TREEVIEW); - static bool searchEngine = Config_getBool(SEARCHENGINE); + //bool generateTreeView = Config_getBool(GENERATE_TREEVIEW); + bool searchEngine = Config_getBool(SEARCHENGINE); if (searchEngine /*&& !generateTreeView*/) { t << "