From ecdbe198a15512d562d5636a60765ce92294f2a2 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Mon, 4 Jan 2021 20:45:22 +0100 Subject: Refactoring: modernize docsets --- src/docsets.cpp | 142 ++++++++++++++++++++++++++++---------------------------- src/docsets.h | 42 +++++------------ 2 files changed, 82 insertions(+), 102 deletions(-) diff --git a/src/docsets.cpp b/src/docsets.cpp index c59ca76..091d2c2 100644 --- a/src/docsets.cpp +++ b/src/docsets.cpp @@ -1,6 +1,6 @@ /****************************************************************************** * - * Copyright (C) 1997-2015 by Dimitri van Heesch. + * Copyright (C) 1997-2021 by Dimitri van Heesch. * * Permission to use, copy, modify, and distribute this software and its * documentation under the terms of the GNU General Public License is hereby @@ -13,6 +13,9 @@ * */ +#include +#include + #include #include "docsets.h" #include "config.h" @@ -24,20 +27,26 @@ #include "memberdef.h" #include "namespacedef.h" #include "util.h" +#include "ftextstream.h" + +struct DocSets::Private +{ + QCString indent(); + QFile nf; + QFile tf; + FTextStream nts; + FTextStream tts; + std::stack indentStack; + std::set scopes; +}; -DocSets::DocSets() : m_nodes(17), m_scopes(17) + +DocSets::DocSets() : p(std::make_unique()) { - m_nf = 0; - m_tf = 0; - m_dc = 0; - m_id = 0; - m_nodes.setAutoDelete(TRUE); } DocSets::~DocSets() { - delete m_nf; - delete m_tf; } void DocSets::initialize() @@ -144,85 +153,74 @@ void DocSets::initialize() // -- start Nodes.xml QCString notes = Config_getString(HTML_OUTPUT) + "/Nodes.xml"; - m_nf = new QFile(notes); - if (!m_nf->open(IO_WriteOnly)) + p->nf.setName(notes); + if (!p->nf.open(IO_WriteOnly)) { term("Could not open file %s for writing\n",notes.data()); } //QCString indexName=Config_getBool(GENERATE_TREEVIEW)?"main":"index"; QCString indexName="index"; - m_nts.setDevice(m_nf); - m_nts << "" << endl; - m_nts << "" << endl; - m_nts << " " << endl; - m_nts << " " << endl; - m_nts << " Root" << endl; - m_nts << " " << indexName << Doxygen::htmlFileExtension << "" << endl; - m_nts << " " << endl; - m_dc = 1; - m_firstNode.resize(m_dc); - m_firstNode.at(0)=TRUE; + p->nts.setDevice(&p->nf); + p->nts << "" << endl; + p->nts << "" << endl; + p->nts << " " << endl; + p->nts << " " << endl; + p->nts << " Root" << endl; + p->nts << " " << indexName << Doxygen::htmlFileExtension << "" << endl; + p->nts << " " << endl; + p->indentStack.push(true); QCString tokens = Config_getString(HTML_OUTPUT) + "/Tokens.xml"; - m_tf = new QFile(tokens); - if (!m_tf->open(IO_WriteOnly)) + p->tf.setName(tokens); + if (!p->tf.open(IO_WriteOnly)) { term("Could not open file %s for writing\n",tokens.data()); } - m_tts.setDevice(m_tf); - m_tts << "" << endl; - m_tts << "" << endl; + p->tts.setDevice(&p->tf); + p->tts << "" << endl; + p->tts << "" << endl; } void DocSets::finalize() { - if (!m_firstNode.at(m_dc-1)) + if (!p->indentStack.top()) { - m_nts << indent() << " " << endl; + p->nts << p->indent() << " " << endl; } - m_dc--; - m_nts << " " << endl; - m_nts << " " << endl; - m_nts << " " << endl; - m_nts << "" << endl; - m_nf->close(); - delete m_nf; - m_nf=0; + p->indentStack.pop(); + p->nts << " " << endl; + p->nts << " " << endl; + p->nts << " " << endl; + p->nts << "" << endl; + p->nf.close(); - m_tts << "" << endl; - m_tf->close(); - delete m_tf; - m_tf=0; + p->tts << "" << endl; + p->tf.close(); } -QCString DocSets::indent() +QCString DocSets::Private::indent() { QCString result; - result.fill(' ',(m_dc+2)*2); + result.fill(' ',(indentStack.size()+2)*2); return result; } void DocSets::incContentsDepth() { - //printf("DocSets::incContentsDepth() m_dc=%d\n",m_dc); - ++m_dc; - m_nts << indent() << "" << endl; - m_firstNode.resize(m_dc); - if (m_dc>0) - { - m_firstNode.at(m_dc-1)=TRUE; - } + //printf("DocSets::incContentsDepth() depth=%zu\n",p->indentStack.size()); + p->nts << p->indent() << "" << endl; + p->indentStack.push(true); } void DocSets::decContentsDepth() { - if (!m_firstNode.at(m_dc-1)) + if (!p->indentStack.top()) { - m_nts << indent() << " " << endl; + p->nts << p->indent() << " " << endl; } - m_nts << indent() << "" << endl; - --m_dc; - //printf("DocSets::decContentsDepth() m_dc=%d\n",m_dc); + p->nts << p->indent() << "" << endl; + p->indentStack.pop(); + //printf("DocSets::decContentsDepth() depth=%zu\n",p->indentStack.size()); } void DocSets::addContentsItem(bool isDir, @@ -235,36 +233,36 @@ void DocSets::addContentsItem(bool isDir, const Definition * /*def*/) { (void)isDir; - //printf("DocSets::addContentsItem(%s) m_dc=%d\n",name,m_dc); + //printf("DocSets::addContentsItem(%s) depth=%zu\n",name,p->indentStack.size()); if (ref==0) { - if (!m_firstNode.at(m_dc-1)) + if (!p->indentStack.top()) { - m_nts << indent() << " " << endl; + p->nts << p->indent() << " " << endl; } - m_firstNode.at(m_dc-1)=FALSE; - m_nts << indent() << " " << endl; - m_nts << indent() << " " << convertToXML(name) << "" << endl; + p->indentStack.top()=false; + p->nts << p->indent() << " " << endl; + p->nts << p->indent() << " " << convertToXML(name) << "" << endl; if (file && file[0]=='^') // URL marker { - m_nts << indent() << " " << convertToXML(&file[1]) + p->nts << p->indent() << " " << convertToXML(&file[1]) << "" << endl; } else // relative file { - m_nts << indent() << " "; + p->nts << p->indent() << " "; if (file && file[0]=='!') // user specified file { - m_nts << convertToXML(&file[1]); + p->nts << convertToXML(&file[1]); } else if (file) // doxygen generated file { - m_nts << file << Doxygen::htmlFileExtension; + p->nts << file << Doxygen::htmlFileExtension; } - m_nts << "" << endl; + p->nts << "" << endl; if (file && anchor) { - m_nts << indent() << " " << anchor << "" << endl; + p->nts << p->indent() << " " << anchor << "" << endl; } } } @@ -421,7 +419,7 @@ void DocSets::addIndexItem(const Definition *context,const MemberDef *md, decl = fd->name(); } } - writeToken(m_tts,md,type,lang,scope,md->anchor(),decl); + writeToken(p->tts,md,type,lang,scope,md->anchor(),decl); } else if (context && context->isLinkable()) { @@ -476,10 +474,10 @@ void DocSets::addIndexItem(const Definition *context,const MemberDef *md, scope = nd->name(); type = "ns"; } - if (m_scopes.find(context->getOutputFileBase())==0) + if (p->scopes.find(context->getOutputFileBase().str())==p->scopes.end()) { - writeToken(m_tts,context,type,lang,scope,0,decl); - m_scopes.append(context->getOutputFileBase(),(void*)0x8); + writeToken(p->tts,context,type,lang,scope,0,decl); + p->scopes.insert(context->getOutputFileBase().str()); } } } diff --git a/src/docsets.h b/src/docsets.h index 0d75bfd..6065cfe 100644 --- a/src/docsets.h +++ b/src/docsets.h @@ -1,10 +1,10 @@ /****************************************************************************** * - * Copyright (C) 1997-2015 by Dimitri van Heesch. + * Copyright (C) 1997-2021 by Dimitri van Heesch. * * Permission to use, copy, modify, and distribute this software and its - * documentation under the terms of the GNU General Public License is hereby - * granted. No representations are made about the suitability of this software + * documentation under the terms of the GNU General Public License is hereby + * granted. No representations are made about the suitability of this software * for any purpose. It is provided "as is" without express or implied warranty. * See the GNU General Public License for more details. * @@ -16,16 +16,17 @@ #ifndef DOCSETS_H #define DOCSETS_H -#include "sortdict.h" -#include "ftextstream.h" +#include + #include "index.h" class QFile; class Definition; +class FTextStream; /** A class that generates docset files. * - * These files can be used to create context help + * These files can be used to create context help * for use within Apple's Xcode 3.0 development environment */ class DocSets : public IndexIntf @@ -39,8 +40,8 @@ class DocSets : public IndexIntf void incContentsDepth(); void decContentsDepth(); void addContentsItem(bool isDir, - const char *name, - const char *ref, + const char *name, + const char *ref, const char *file, const char *anchor, bool separateIndex, @@ -58,28 +59,9 @@ class DocSets : public IndexIntf const QCString &type, const QCString &lang, const char *scope=0, const char *anchor=0, const char *decl=0); - struct NodeDef - { - NodeDef(bool d,const QCString &n,const QCString &r, - const QCString &f,const QCString &a,int i) : - isDir(d), name(n), ref(r), file(f), anchor(a),id(i) {} - bool isDir; - QCString name; - QCString ref; - QCString file; - QCString anchor; - int id; - }; - QCString indent(); - QFile *m_nf; - QFile *m_tf; - FTextStream m_nts; - FTextStream m_tts; - int m_dc; - int m_id; - QArray m_firstNode; - SDict m_nodes; - SDict m_scopes; + struct Private; + std::unique_ptr p; + }; #endif /* DOCSETS_H */ -- cgit v0.12