From 1a56a39b4a97452a5c7c2d8e9d39ab28ca33dff0 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Sun, 16 Feb 2020 22:34:46 +0100 Subject: Restructure section handling --- src/commentscan.l | 53 +++++++------ src/definition.cpp | 148 ++++++++++++++++--------------------- src/definition.h | 4 +- src/definitionimpl.h | 6 +- src/docbookgen.cpp | 4 +- src/docbookgen.h | 4 +- src/docparser.cpp | 89 ++++++++-------------- src/doctokenizer.l | 22 +++--- src/doxygen.cpp | 50 ++++++------- src/doxygen.h | 1 - src/groupdef.cpp | 10 +-- src/htmlgen.cpp | 24 +++--- src/htmlgen.h | 4 +- src/index.cpp | 10 +-- src/latexgen.cpp | 24 +++--- src/latexgen.h | 4 +- src/mangen.cpp | 24 +++--- src/mangen.h | 4 +- src/markdown.cpp | 18 ++--- src/outputgen.h | 4 +- src/outputlist.h | 4 +- src/pagedef.cpp | 26 +++---- src/perlmodgen.cpp | 4 +- src/rtfgen.cpp | 14 ++-- src/rtfgen.h | 4 +- src/section.h | 204 ++++++++++++++++++++++++++++++++++++++++++++------- src/tagreader.cpp | 8 +- src/util.cpp | 25 +++---- src/xmlgen.cpp | 28 ++++--- 29 files changed, 456 insertions(+), 368 deletions(-) diff --git a/src/commentscan.l b/src/commentscan.l index e1b2f13..9c38e18 100644 --- a/src/commentscan.l +++ b/src/commentscan.l @@ -398,7 +398,7 @@ struct commentscanYY_state static QCString stripQuotes(const char *s); static bool getDocSectionName(int s); -static SectionInfo::SectionType sectionLevelToType(int level); +static SectionType sectionLevelToType(int level); static void stripTrailingWhiteSpace(QCString &s); static void initParser(yyscan_t yyscanner); @@ -2832,24 +2832,24 @@ static void addXRefItem(yyscan_t yyscanner, { yyextra->current->doc += cmdString; } - SectionInfo *si = Doxygen::sectionDict->find(anchorLabel); + SectionManager &sm = SectionManager::instance(); + const SectionInfo *si = sm.find(anchorLabel); if (si) { - if (si->lineNr != -1) + if (si->lineNr() != -1) { - warn(listName,yyextra->lineNr,"multiple use of section label '%s', (first occurrence: %s, line %d)",anchorLabel,si->fileName.data(),si->lineNr); + warn(listName,yyextra->lineNr,"multiple use of section label '%s', (first occurrence: %s, line %d)",anchorLabel,si->fileName().data(),si->lineNr()); } else { - warn(listName,yyextra->lineNr,"multiple use of section label '%s', (first occurrence: %s)",anchorLabel,si->fileName.data()); + warn(listName,yyextra->lineNr,"multiple use of section label '%s', (first occurrence: %s)",anchorLabel,si->fileName().data()); } } else { - si=new SectionInfo(listName,yyextra->lineNr,anchorLabel, - yyextra->sectionTitle,SectionInfo::Anchor, - yyextra->sectionLevel); - Doxygen::sectionDict->append(anchorLabel,si); + si = sm.add(listName,yyextra->lineNr,anchorLabel, + yyextra->sectionTitle,SectionType::Anchor, + yyextra->sectionLevel); yyextra->current->anchors.push_back(si); } } @@ -2875,25 +2875,26 @@ static QCString addFormula(yyscan_t yyscanner) //----------------------------------------------------------------------------- -static SectionInfo::SectionType sectionLevelToType(int level) +static SectionType sectionLevelToType(int level) { - if (level>=0 && level<5) return (SectionInfo::SectionType)level; - return SectionInfo::Anchor; + if (level>=0 && level<5) return (SectionType)level; + return SectionType::Anchor; } static void addSection(yyscan_t yyscanner) { struct yyguts_t *yyg = (struct yyguts_t*)yyscanner; - SectionInfo *si = Doxygen::sectionDict->find(yyextra->sectionLabel); + SectionManager &sm = SectionManager::instance(); + const SectionInfo *si = sm.find(yyextra->sectionLabel); if (si) { - if (si->lineNr != -1) + if (si->lineNr() != -1) { - warn(yyextra->fileName,yyextra->lineNr,"multiple use of section label '%s' while adding section, (first occurrence: %s, line %d)",yyextra->sectionLabel.data(),si->fileName.data(),si->lineNr); + warn(yyextra->fileName,yyextra->lineNr,"multiple use of section label '%s' while adding section, (first occurrence: %s, line %d)",yyextra->sectionLabel.data(),si->fileName().data(),si->lineNr()); } else { - warn(yyextra->fileName,yyextra->lineNr,"multiple use of section label '%s' while adding section, (first occurrence: %s)",yyextra->sectionLabel.data(),si->fileName.data()); + warn(yyextra->fileName,yyextra->lineNr,"multiple use of section label '%s' while adding section, (first occurrence: %s)",yyextra->sectionLabel.data(),si->fileName().data()); } } else @@ -2901,14 +2902,12 @@ static void addSection(yyscan_t yyscanner) // create a new section element yyextra->sectionTitle+=yytext; yyextra->sectionTitle=yyextra->sectionTitle.stripWhiteSpace(); - si = new SectionInfo(yyextra->fileName,yyextra->lineNr,yyextra->sectionLabel, - yyextra->sectionTitle,sectionLevelToType(yyextra->sectionLevel),yyextra->sectionLevel); + si = sm.add(yyextra->fileName,yyextra->lineNr,yyextra->sectionLabel, + yyextra->sectionTitle,sectionLevelToType(yyextra->sectionLevel), + yyextra->sectionLevel); // add section to this entry yyextra->current->anchors.push_back(si); - - // add section to the global dictionary - Doxygen::sectionDict->append(yyextra->sectionLabel,si); } } @@ -3068,22 +3067,22 @@ static inline void setOutput(yyscan_t yyscanner,OutputContext ctx) static void addAnchor(yyscan_t yyscanner,const char *anchor) { struct yyguts_t *yyg = (struct yyguts_t*)yyscanner; - SectionInfo *si = Doxygen::sectionDict->find(anchor); + SectionManager &sm = SectionManager::instance(); + const SectionInfo *si = sm.find(anchor); if (si) { - if (si->lineNr != -1) + if (si->lineNr() != -1) { - warn(yyextra->fileName,yyextra->lineNr,"multiple use of section label '%s' while adding anchor, (first occurrence: %s, line %d)",anchor,si->fileName.data(),si->lineNr); + warn(yyextra->fileName,yyextra->lineNr,"multiple use of section label '%s' while adding anchor, (first occurrence: %s, line %d)",anchor,si->fileName().data(),si->lineNr()); } else { - warn(yyextra->fileName,yyextra->lineNr,"multiple use of section label '%s' while adding anchor, (first occurrence: %s)",anchor,si->fileName.data()); + warn(yyextra->fileName,yyextra->lineNr,"multiple use of section label '%s' while adding anchor, (first occurrence: %s)",anchor,si->fileName().data()); } } else { - si = new SectionInfo(yyextra->fileName,yyextra->lineNr,anchor,0,SectionInfo::Anchor,0); - Doxygen::sectionDict->append(anchor,si); + si = sm.add(yyextra->fileName,yyextra->lineNr,anchor,0,SectionType::Anchor,0); yyextra->current->anchors.push_back(si); } } diff --git a/src/definition.cpp b/src/definition.cpp index 7540eff..c67030e 100644 --- a/src/definition.cpp +++ b/src/definition.cpp @@ -55,7 +55,7 @@ class DefinitionImpl::IMPL void init(const char *df, const char *n); void setDefFileName(const QCString &df); - SectionDict *sectionDict = 0; // dictionary of all sections, not accessible + SectionRefs sectionRefs; MemberSDict *sourceRefByDict = 0; MemberSDict *sourceRefsDict = 0; @@ -99,7 +99,6 @@ class DefinitionImpl::IMPL DefinitionImpl::IMPL::~IMPL() { - delete sectionDict; delete sourceRefByDict; delete sourceRefsDict; delete partOfGroups; @@ -140,7 +139,6 @@ void DefinitionImpl::IMPL::init(const char *df, const char *n) inbodyDocs = 0; sourceRefByDict = 0; sourceRefsDict = 0; - sectionDict = 0, outerScope = Doxygen::globalScope; partOfGroups = 0; hidden = FALSE; @@ -315,7 +313,6 @@ DefinitionImpl::DefinitionImpl(const DefinitionImpl &d) { m_impl = new DefinitionImpl::IMPL; *m_impl = *d.m_impl; - m_impl->sectionDict = 0; m_impl->sourceRefByDict = 0; m_impl->sourceRefsDict = 0; m_impl->partOfGroups = 0; @@ -323,16 +320,6 @@ DefinitionImpl::DefinitionImpl(const DefinitionImpl &d) m_impl->details = 0; m_impl->body = 0; m_impl->inbodyDocs = 0; - if (d.m_impl->sectionDict) - { - m_impl->sectionDict = new SectionDict(17); - SDict::Iterator it(*d.m_impl->sectionDict); - SectionInfo *si; - for (it.toFirst();(si=it.current());++it) - { - m_impl->sectionDict->append(si->label,si); - } - } if (d.m_impl->sourceRefByDict) { m_impl->sourceRefByDict = new MemberSDict; @@ -426,22 +413,18 @@ void DefinitionImpl::addSectionsToDefinition(const std::vectorlabel.data(),name().data()); - SectionInfo *gsi=Doxygen::sectionDict->find(si->label); + // si->label().data(),name().data()); + SectionManager &sm = SectionManager::instance(); + SectionInfo *gsi=sm.find(si->label()); //printf("===== label=%s gsi=%p\n",si->label.data(),gsi); if (gsi==0) { - gsi = new SectionInfo(*si); - Doxygen::sectionDict->append(si->label,gsi); + gsi = sm.add(*si); } - if (m_impl->sectionDict==0) + if (m_impl->sectionRefs.find(gsi->label())==0) { - m_impl->sectionDict = new SectionDict(17); - } - if (m_impl->sectionDict->find(gsi->label)==0) - { - m_impl->sectionDict->append(gsi->label,gsi); - gsi->definition = this; + m_impl->sectionRefs.add(gsi); + gsi->setDefinition(this); } } } @@ -450,15 +433,10 @@ bool DefinitionImpl::hasSections() const { //printf("DefinitionImpl::hasSections(%s) #sections=%d\n",name().data(), // m_impl->sectionDict ? m_impl->sectionDict->count() : 0); - if (m_impl->sectionDict==0) return FALSE; - SDict::Iterator li(*m_impl->sectionDict); - SectionInfo *si; - for (li.toFirst();(si=li.current());++li) - { - if (si->type==SectionInfo::Section || - si->type==SectionInfo::Subsection || - si->type==SectionInfo::Subsubsection || - si->type==SectionInfo::Paragraph) + if (m_impl->sectionRefs.empty()) return FALSE; + for (const SectionInfo *si : m_impl->sectionRefs) + { + if (isSection(si->type())) { return TRUE; } @@ -468,20 +446,17 @@ bool DefinitionImpl::hasSections() const void DefinitionImpl::addSectionsToIndex() { - if (m_impl->sectionDict==0) return; + if (m_impl->sectionRefs.empty()) return; //printf("DefinitionImpl::addSectionsToIndex()\n"); - SDict::Iterator li(*m_impl->sectionDict); - SectionInfo *si; int level=1; - for (li.toFirst();(si=li.current());++li) + for (auto it = m_impl->sectionRefs.begin(); it!=m_impl->sectionRefs.end(); ++it) { - if (si->type==SectionInfo::Section || - si->type==SectionInfo::Subsection || - si->type==SectionInfo::Subsubsection || - si->type==SectionInfo::Paragraph) + const SectionInfo *si = *it; + SectionType type = si->type(); + if (isSection(type)) { //printf(" level=%d title=%s\n",level,si->title.data()); - int nextLevel = (int)si->type; + int nextLevel = (int)type; int i; if (nextLevel>level) { @@ -497,16 +472,16 @@ void DefinitionImpl::addSectionsToIndex() Doxygen::indexList->decContentsDepth(); } } - QCString title = si->title; - if (title.isEmpty()) title = si->label; + QCString title = si->title(); + if (title.isEmpty()) title = si->label(); // determine if there is a next level inside this item - ++li; - bool isDir = ((li.current()) ? (int)(li.current()->type > nextLevel):FALSE); - --li; + auto it_next = std::next(it); + bool isDir = (it_next!=m_impl->sectionRefs.end()) ? + ((int)((*it_next)->type()) > nextLevel) : FALSE; Doxygen::indexList->addContentsItem(isDir,title, getReference(), getOutputFileBase(), - si->label, + si->label(), FALSE, TRUE); level = nextLevel; @@ -521,23 +496,21 @@ void DefinitionImpl::addSectionsToIndex() void DefinitionImpl::writeDocAnchorsToTagFile(FTextStream &tagFile) const { - if (m_impl->sectionDict) + if (!m_impl->sectionRefs.empty()) { - //printf("%s: writeDocAnchorsToTagFile(%d)\n",name().data(),m_impl->sectionDict->count()); - SDict::Iterator sdi(*m_impl->sectionDict); - SectionInfo *si; - for (;(si=sdi.current());++sdi) + //printf("%s: writeDocAnchorsToTagFile(%d)\n",name().data(),m_impl->sectionRef.size()); + for (const SectionInfo *si : m_impl->sectionRefs) { - if (!si->generated && si->ref.isEmpty() && !si->label.startsWith("autotoc_md")) + if (!si->generated() && si->ref().isEmpty() && !si->label().startsWith("autotoc_md")) { //printf("write an entry!\n"); if (definitionType()==TypeMember) tagFile << " "; - tagFile << " fileName) << "\""; - if (!si->title.isEmpty()) + tagFile << " fileName()) << "\""; + if (!si->title().isEmpty()) { - tagFile << " title=\"" << convertToXML(si->title) << "\""; + tagFile << " title=\"" << convertToXML(si->title()) << "\""; } - tagFile << ">" << si->label << "" << endl; + tagFile << ">" << si->label() << "" << endl; } } } @@ -1756,8 +1729,7 @@ void DefinitionImpl::writeNavigationPath(OutputList &ol) const // TODO: move to htmlgen void DefinitionImpl::writeToc(OutputList &ol, const LocalToc &localToc) const { - SectionDict *sectionDict = m_impl->sectionDict; - if (sectionDict==0) return; + if (m_impl->sectionRefs.empty()) return; if (localToc.isHtmlEnabled()) { int maxLevel = localToc.htmlLevel(); @@ -1768,21 +1740,17 @@ void DefinitionImpl::writeToc(OutputList &ol, const LocalToc &localToc) const ol.writeString(theTranslator->trRTFTableOfContents()); ol.writeString("\n"); ol.writeString("
    "); - SDict::Iterator li(*sectionDict); - SectionInfo *si; int level=1,l; char cs[2]; cs[1]='\0'; bool inLi[5]={ FALSE, FALSE, FALSE, FALSE, FALSE }; - for (li.toFirst();(si=li.current());++li) + for (const SectionInfo *si : m_impl->sectionRefs) { - if (si->type==SectionInfo::Section || - si->type==SectionInfo::Subsection || - si->type==SectionInfo::Subsubsection || - si->type==SectionInfo::Paragraph) + SectionType type = si->type(); + if (isSection(type)) { //printf(" level=%d title=%s\n",level,si->title.data()); - int nextLevel = (int)si->type; + int nextLevel = (int)type; if (nextLevel>level) { for (l=level;l\n"); - QCString titleDoc = convertToHtml(si->title); - if (nextLevel <= maxLevel) ol.writeString("
  • label+"\">"+(si->title.isEmpty()?si->label:titleDoc)+""); + if (nextLevel <= maxLevel && inLi[nextLevel]) + { + ol.writeString("
  • \n"); + } + QCString titleDoc = convertToHtml(si->title()); + if (nextLevel <= maxLevel) + { + ol.writeString("
  • " + "label()+"\">"+ + (si->title().isEmpty()?si->label():titleDoc)+""); + } inLi[nextLevel]=TRUE; level = nextLevel; } @@ -1810,7 +1786,10 @@ void DefinitionImpl::writeToc(OutputList &ol, const LocalToc &localToc) const if (level > maxLevel) level = maxLevel; while (level>1 && level <= maxLevel) { - if (inLi[level]) ol.writeString("
  • \n"); + if (inLi[level]) + { + ol.writeString("\n"); + } inLi[level]=FALSE; ol.writeString("
\n"); level--; @@ -1828,21 +1807,16 @@ void DefinitionImpl::writeToc(OutputList &ol, const LocalToc &localToc) const ol.disableAllBut(OutputGenerator::Docbook); ol.writeString(" \n"); ol.writeString(" " + theTranslator->trRTFTableOfContents() + "\n"); - SectionDict *sectionDict = getSectionDict(); - SDict::Iterator li(*sectionDict); - SectionInfo *si; int level=1,l; bool inLi[5]={ FALSE, FALSE, FALSE, FALSE, FALSE }; int maxLevel = localToc.docbookLevel(); - for (li.toFirst();(si=li.current());++li) + for (const SectionInfo *si : m_impl->sectionRefs) { - if (si->type==SectionInfo::Section || - si->type==SectionInfo::Subsection || - si->type==SectionInfo::Subsubsection || - si->type==SectionInfo::Paragraph) + SectionType type = si->type(); + if (isSection(type)) { //printf(" level=%d title=%s\n",level,si->title.data()); - int nextLevel = (int)si->type; + int nextLevel = (int)type; if (nextLevel>level) { for (l=level;ltitle); - ol.writeString(" " + (si->title.isEmpty()?si->label:titleDoc) + "\n"); + QCString titleDoc = convertToDocBook(si->title()); + ol.writeString(" " + + (si->title().isEmpty()?si->label():titleDoc) + + "\n"); } inLi[nextLevel]=TRUE; level = nextLevel; @@ -1894,9 +1870,9 @@ void DefinitionImpl::writeToc(OutputList &ol, const LocalToc &localToc) const //---------------------------------------------------------------------------------------- -SectionDict * DefinitionImpl::getSectionDict() const +const SectionRefs &DefinitionImpl::getSectionRefs() const { - return m_impl->sectionDict; + return m_impl->sectionRefs; } QCString DefinitionImpl::symbolName() const diff --git a/src/definition.h b/src/definition.h index b3ece2c..db64094 100644 --- a/src/definition.h +++ b/src/definition.h @@ -32,7 +32,7 @@ class FileDef; class OutputList; -class SectionDict; +class SectionRefs; class MemberSDict; class MemberDef; class GroupDef; @@ -280,7 +280,7 @@ class Definition : public DefinitionIntf virtual QCString id() const = 0; /** returns the section dictionary, only of importance for pagedef */ - virtual SectionDict * getSectionDict() const = 0; + virtual const SectionRefs &getSectionRefs() const = 0; virtual QCString navigationPathAsString() const = 0; virtual QCString pathFragment() const = 0; diff --git a/src/definitionimpl.h b/src/definitionimpl.h index 2d8886d..1b2ce5b 100644 --- a/src/definitionimpl.h +++ b/src/definitionimpl.h @@ -76,7 +76,7 @@ class DefinitionImpl : virtual public Definition virtual bool hasSources() const; virtual bool hasBriefDescription() const; virtual QCString id() const; - virtual SectionDict * getSectionDict() const; + virtual const SectionRefs &getSectionRefs() const; virtual void setName(const char *name); virtual void setId(const char *name); virtual void setDefFile(const QCString& df,int defLine,int defColumn); @@ -231,8 +231,8 @@ class DefinitionAliasImpl : virtual public Definition { return m_def->hasBriefDescription(); } virtual QCString id() const { return m_def->id(); } - virtual SectionDict * getSectionDict() const - { return m_def->getSectionDict(); } + virtual const SectionRefs &getSectionRefs() const + { return m_def->getSectionRefs(); } virtual QCString navigationPathAsString() const { return m_def->navigationPathAsString(); } virtual QCString pathFragment() const diff --git a/src/docbookgen.cpp b/src/docbookgen.cpp index fff9728..1799ed9 100644 --- a/src/docbookgen.cpp +++ b/src/docbookgen.cpp @@ -1025,13 +1025,13 @@ DB_GEN_C t << ""; t << ""; } -void DocbookGenerator::startSection(const char *lab,const char *,SectionInfo::SectionType type) +void DocbookGenerator::startSection(const char *lab,const char *,SectionType type) { DB_GEN_C t << "
"; t << ""; } -void DocbookGenerator::endSection(const char *lab,SectionInfo::SectionType) +void DocbookGenerator::endSection(const char *lab,SectionType) { DB_GEN_C t << ""; diff --git a/src/docbookgen.h b/src/docbookgen.h index 64e9e67..d993312 100644 --- a/src/docbookgen.h +++ b/src/docbookgen.h @@ -204,8 +204,8 @@ class DocbookGenerator : public OutputGenerator void startTitle(void){DB_GEN_NEW}; void endTitle(void){DB_GEN_NEW}; void writeAnchor(const char *,const char *){DB_GEN_EMPTY}; - void startSection(const char *,const char *,SectionInfo::SectionType); - void endSection(const char *,SectionInfo::SectionType); + void startSection(const char *,const char *,SectionType); + void endSection(const char *,SectionType); void lineBreak(const char *); void addIndexItem(const char *,const char *); void writeNonBreakableSpace(int); diff --git a/src/docparser.cpp b/src/docparser.cpp index c5eb9e9..4f11698 100644 --- a/src/docparser.cpp +++ b/src/docparser.cpp @@ -106,7 +106,6 @@ static QDict g_paramsFound; static const MemberDef * g_memberDef; static bool g_isExample; static QCString g_exampleName; -static SectionDict * g_sectionDict; static QCString g_searchUrl; static QCString g_includeFileName; @@ -141,7 +140,6 @@ struct DocParserContext QDict paramsFound; bool isExample; QCString exampleName; - SectionDict *sectionDict; QCString searchUrl; QCString includeFileText; @@ -191,7 +189,6 @@ static void docParserPushContext(bool saveParamInfo=TRUE) ctx->memberDef = g_memberDef; ctx->isExample = g_isExample; ctx->exampleName = g_exampleName; - ctx->sectionDict = g_sectionDict; ctx->searchUrl = g_searchUrl; ctx->includeFileText = g_includeFileText; @@ -232,7 +229,6 @@ static void docParserPopContext(bool keepParamInfo=FALSE) g_memberDef = ctx->memberDef; g_isExample = ctx->isExample; g_exampleName = ctx->exampleName; - g_sectionDict = ctx->sectionDict; g_searchUrl = ctx->searchUrl; g_includeFileText = ctx->includeFileText; @@ -1942,17 +1938,12 @@ DocAnchor::DocAnchor(DocNode *parent,const QCString &id,bool newAnchor) } else // found \anchor label { - SectionInfo *sec = Doxygen::sectionDict->find(id); + const SectionInfo *sec = SectionManager::instance().find(id); if (sec) { //printf("Found anchor %s\n",id.data()); - m_file = sec->fileName; - m_anchor = sec->label; - if (g_sectionDict && g_sectionDict->find(id)==0) - { - //printf("Inserting in dictionary!\n"); - g_sectionDict->append(id,sec); - } + m_file = sec->fileName(); + m_anchor = sec->label(); } else { @@ -2286,30 +2277,26 @@ void DocSecRefItem::parse() doctokenizerYYsetStatePara(); handlePendingStyleCommands(this,m_children); - SectionInfo *sec=0; + const SectionInfo *sec=0; if (!m_target.isEmpty()) { - sec=Doxygen::sectionDict->find(m_target); + const SectionInfo *sec = SectionManager::instance().find(m_target); if (sec) { - m_file = sec->fileName; - m_anchor = sec->label; - if (g_sectionDict && g_sectionDict->find(m_target)==0) - { - g_sectionDict->append(m_target,sec); - } + m_file = sec->fileName(); + m_anchor = sec->label(); } else { warn_doc_error(g_fileName,doctokenizerYYlineno,"reference to unknown section %s", qPrint(m_target)); } - } + } else { warn_doc_error(g_fileName,doctokenizerYYlineno,"reference to empty target"); } - + DBG(("DocSecRefItem::parse() end\n")); DocNode *n = g_nodeStack.pop(); ASSERT(n==this); @@ -2431,28 +2418,28 @@ DocRef::DocRef(DocNode *parent,const QCString &target,const QCString &context) : ASSERT(!target.isEmpty()); SrcLangExt lang = getLanguageFromFileName(target); m_relPath = g_relPath; - SectionInfo *sec = Doxygen::sectionDict->find(target); + const SectionInfo *sec = SectionManager::instance().find(target); if (sec==0 && lang==SrcLangExt_Markdown) // lookup as markdown file { - sec = Doxygen::sectionDict->find(markdownFileNameToId(target)); + sec = SectionManager::instance().find(markdownFileNameToId(target)); } if (sec) // ref to section or anchor { PageDef *pd = 0; - if (sec->type==SectionInfo::Page) + if (sec->type()==SectionType::Page) { pd = Doxygen::pageSDict->find(target); } - m_text = sec->title; - if (m_text.isEmpty()) m_text = sec->label; + m_text = sec->title(); + if (m_text.isEmpty()) m_text = sec->label(); - m_ref = sec->ref; - m_file = stripKnownExtensions(sec->fileName); - if (sec->type==SectionInfo::Anchor) + m_ref = sec->ref(); + m_file = stripKnownExtensions(sec->fileName()); + if (sec->type()==SectionType::Anchor) { m_refType = Anchor; } - else if (sec->type==SectionInfo::Table) + else if (sec->type()==SectionType::Table) { m_refType = Table; } @@ -2461,7 +2448,7 @@ DocRef::DocRef(DocNode *parent,const QCString &target,const QCString &context) : m_refType = Section; } m_isSubPage = pd && pd->hasParentPage(); - if (sec->type!=SectionInfo::Page || m_isSubPage) m_anchor = sec->label; + if (sec->type()!=SectionType::Page || m_isSubPage) m_anchor = sec->label(); //printf("m_text=%s,m_ref=%s,m_file=%s,m_refToAnchor=%d type=%d\n", // m_text.data(),m_ref.data(),m_file.data(),m_refToAnchor,sec->type); return; @@ -3249,18 +3236,13 @@ DocHtmlCaption::DocHtmlCaption(DocNode *parent,const HtmlAttribList &attribs) { if (opt->name=="id" && !opt->value.isEmpty()) // interpret id attribute as an anchor { - SectionInfo *sec = Doxygen::sectionDict->find(opt->value); + const SectionInfo *sec = SectionManager::instance().find(opt->value); if (sec) { //printf("Found anchor %s\n",id.data()); - m_file = sec->fileName; - m_anchor = sec->label; + m_file = sec->fileName(); + m_anchor = sec->label(); m_hasCaptionId = TRUE; - if (g_sectionDict && g_sectionDict->find(opt->value)==0) - { - //printf("Inserting in dictionary!\n"); - g_sectionDict->append(opt->value,sec); - } } else { @@ -6868,20 +6850,15 @@ int DocSection::parse() int retval=RetVal_OK; g_nodeStack.push(this); - SectionInfo *sec; if (!m_id.isEmpty()) { - sec=Doxygen::sectionDict->find(m_id); + const SectionInfo *sec = SectionManager::instance().find(m_id); if (sec) { - m_file = sec->fileName; - m_anchor = sec->label; - m_title = sec->title; - if (m_title.isEmpty()) m_title = sec->label; - if (g_sectionDict && g_sectionDict->find(m_id)==0) - { - g_sectionDict->append(m_id,sec); - } + m_file = sec->fileName(); + m_anchor = sec->label(); + m_title = sec->title(); + if (m_title.isEmpty()) m_title = sec->label(); } } @@ -6935,7 +6912,6 @@ int DocSection::parse() // then parse any number of nested sections while (retval==RetVal_Subsection) // more sections follow { - //SectionInfo *sec=Doxygen::sectionDict[g_token->sectionId]; DocSection *s=new DocSection(this, QMIN(2+Doxygen::subpageNestingLevel,5),g_token->sectionId); m_children.append(s); @@ -6950,7 +6926,6 @@ int DocSection::parse() // then parse any number of nested sections while (retval==RetVal_Subsubsection) // more sections follow { - //SectionInfo *sec=Doxygen::sectionDict[g_token->sectionId]; DocSection *s=new DocSection(this, QMIN(3+Doxygen::subpageNestingLevel,5),g_token->sectionId); m_children.append(s); @@ -6965,7 +6940,6 @@ int DocSection::parse() // then parse any number of nested sections while (retval==RetVal_Paragraph) // more sections follow { - //SectionInfo *sec=Doxygen::sectionDict[g_token->sectionId]; DocSection *s=new DocSection(this, QMIN(4+Doxygen::subpageNestingLevel,5),g_token->sectionId); m_children.append(s); @@ -7140,7 +7114,7 @@ void DocRoot::parse() { if (!g_token->sectionId.isEmpty()) { - SectionInfo *sec=Doxygen::sectionDict->find(g_token->sectionId); + const SectionInfo *sec=SectionManager::instance().find(g_token->sectionId); if (sec) { DocSection *s=new DocSection(this, @@ -7169,7 +7143,7 @@ void DocRoot::parse() { if (!g_token->sectionId.isEmpty()) { - SectionInfo *sec=Doxygen::sectionDict->find(g_token->sectionId); + const SectionInfo *sec=SectionManager::instance().find(g_token->sectionId); if (sec) { DocSection *s=new DocSection(this, @@ -7200,7 +7174,7 @@ void DocRoot::parse() { if (!g_token->sectionId.isEmpty()) { - SectionInfo *sec=Doxygen::sectionDict->find(g_token->sectionId); + const SectionInfo *sec=SectionManager::instance().find(g_token->sectionId); if (sec) { DocSection *s=new DocSection(this, @@ -7240,7 +7214,7 @@ void DocRoot::parse() { if (!g_token->sectionId.isEmpty()) { - SectionInfo *sec=Doxygen::sectionDict->find(g_token->sectionId); + const SectionInfo *sec=SectionManager::instance().find(g_token->sectionId); if (sec) { DocSection *s=new DocSection(this, @@ -7750,7 +7724,6 @@ DocRoot *validatingParseDoc(const char *fileName,int startLine, g_retvalsFound.clear(); g_paramsFound.setAutoDelete(FALSE); g_paramsFound.clear(); - g_sectionDict = 0; //sections; //printf("Starting comment block at %s:%d\n",g_fileName.data(),startLine); doctokenizerYYlineno=startLine; diff --git a/src/doctokenizer.l b/src/doctokenizer.l index 4f03c9b..0f8cb1c 100644 --- a/src/doctokenizer.l +++ b/src/doctokenizer.l @@ -63,7 +63,7 @@ static int g_sharpCount=0; static const Definition *g_definition; static QCString g_secLabel; static QCString g_secTitle; -static SectionInfo::SectionType g_secType; +static SectionType g_secType; static QCString g_endMarker; static int g_autoListLevel; @@ -170,11 +170,11 @@ static void processSection() { warn(g_fileName,yylineno,"Found section/anchor %s without context\n",g_secLabel.data()); } - SectionInfo *si=0; - if ((si=Doxygen::sectionDict->find(g_secLabel))) + SectionInfo *si = SectionManager::instance().find(g_secLabel); + if (si) { - si->fileName = file; - si->type = g_secType; + si->setFileName(file); + si->setType(g_secType); } } @@ -1248,7 +1248,7 @@ REFWORD_NOCV {FILEMASK}|{LABELID}|{REFWORD2_NOCV}|{REFWORD3}|{REFWORD4_NOCV} int e=tag.find(c,s+4); if (e!=-1) // found matching end { - g_secType = SectionInfo::Table; + g_secType = SectionType::Table; g_secLabel=tag.mid(s+4,e-s-4); // extract id processSection(); } @@ -1256,23 +1256,23 @@ REFWORD_NOCV {FILEMASK}|{LABELID}|{REFWORD2_NOCV}|{REFWORD3}|{REFWORD4_NOCV} } } {CMD}"anchor"{BLANK}+ { - g_secType = SectionInfo::Anchor; + g_secType = SectionType::Anchor; BEGIN(St_SecLabel1); } {CMD}"section"{BLANK}+ { - g_secType = SectionInfo::Section; + g_secType = SectionType::Section; BEGIN(St_SecLabel2); } {CMD}"subsection"{BLANK}+ { - g_secType = SectionInfo::Subsection; + g_secType = SectionType::Subsection; BEGIN(St_SecLabel2); } {CMD}"subsubsection"{BLANK}+ { - g_secType = SectionInfo::Subsubsection; + g_secType = SectionType::Subsubsection; BEGIN(St_SecLabel2); } {CMD}"paragraph"{BLANK}+ { - g_secType = SectionInfo::Paragraph; + g_secType = SectionType::Paragraph; BEGIN(St_SecLabel2); } {CMD}"verbatim"/[^a-z_A-Z0-9] { diff --git a/src/doxygen.cpp b/src/doxygen.cpp index cb667cb..f102273 100644 --- a/src/doxygen.cpp +++ b/src/doxygen.cpp @@ -128,7 +128,6 @@ FileNameDict *Doxygen::inputNameDict = 0; GroupSDict *Doxygen::groupSDict = 0; PageSDict *Doxygen::pageSDict = 0; PageSDict *Doxygen::exampleSDict = 0; -SectionDict *Doxygen::sectionDict = 0; // all page sections StringDict Doxygen::aliasDict(257); // aliases QDict Doxygen::inputPaths(1009); FileNameDict *Doxygen::includeNameDict = 0; // include names @@ -192,7 +191,6 @@ void clearAll() Doxygen::pageSDict->clear(); Doxygen::exampleSDict->clear(); Doxygen::inputNameList->clear(); - Doxygen::sectionDict->clear(); Doxygen::inputNameDict->clear(); Doxygen::includeNameDict->clear(); Doxygen::exampleNameDict->clear(); @@ -201,6 +199,7 @@ void clearAll() Doxygen::mscFileNameDict->clear(); Doxygen::diaFileNameDict->clear(); Doxygen::tagDestinationDict.clear(); + SectionManager::instance().clear(); CitationManager::instance().clear(); delete Doxygen::mainPage; Doxygen::mainPage=0; FormulaManager::instance().clear(); @@ -8509,30 +8508,31 @@ static void findMainPage(Entry *root) Doxygen::mainPage->setLocalToc(root->localToc); addPageToContext(Doxygen::mainPage,root); - SectionInfo *si = Doxygen::sectionDict->find(Doxygen::mainPage->name()); + const SectionInfo *si = SectionManager::instance().find(Doxygen::mainPage->name()); if (si) { - if (si->lineNr != -1) + if (si->lineNr() != -1) { - warn(root->fileName,root->startLine,"multiple use of section label '%s' for main page, (first occurrence: %s, line %d)",Doxygen::mainPage->name().data(),si->fileName.data(),si->lineNr); + warn(root->fileName,root->startLine,"multiple use of section label '%s' for main page, (first occurrence: %s, line %d)", + Doxygen::mainPage->name().data(),si->fileName().data(),si->lineNr()); } else { - warn(root->fileName,root->startLine,"multiple use of section label '%s' for main page, (first occurrence: %s)",Doxygen::mainPage->name().data(),si->fileName.data()); + warn(root->fileName,root->startLine,"multiple use of section label '%s' for main page, (first occurrence: %s)", + Doxygen::mainPage->name().data(),si->fileName().data()); } } else { // a page name is a label as well! but should no be double either - si=new SectionInfo( + SectionManager::instance().add( indexName, root->startLine, Doxygen::mainPage->name(), Doxygen::mainPage->title(), - SectionInfo::Page, + SectionType::Page, 0); // level 0 - Doxygen::sectionDict->append(indexName,si); - Doxygen::mainPage->addSectionsToDefinition(root->anchors); } + Doxygen::mainPage->addSectionsToDefinition(root->anchors); } else if (root->tagInfo()==0) { @@ -8615,9 +8615,7 @@ static void checkPageRelations() static void resolveUserReferences() { - SDict::Iterator sdi(*Doxygen::sectionDict); - SectionInfo *si; - for (;(si=sdi.current());++sdi) + for (auto &si : SectionManager::instance()) { //printf("si->label='%s' si->definition=%s si->fileName='%s'\n", // si->label.data(),si->definition?si->definition->name().data():"", @@ -8634,39 +8632,39 @@ static void resolveUserReferences() for (rli.toFirst();(rl=rli.current());++rli) { QCString label="_"+rl->listName(); // "_todo", "_test", ... - if (si->label.left(label.length())==label) + if (si->label().left(label.length())==label) { - si->fileName=rl->listName(); - si->generated=TRUE; + si->setFileName(rl->listName()); + si->setGenerated(TRUE); break; } } //printf("start: si->label=%s si->fileName=%s\n",si->label.data(),si->fileName.data()); - if (!si->generated) + if (!si->generated()) { // if this section is in a page and the page is in a group, then we // have to adjust the link file name to point to the group. - if (!si->fileName.isEmpty() && - (pd=Doxygen::pageSDict->find(si->fileName)) && + if (!si->fileName().isEmpty() && + (pd=Doxygen::pageSDict->find(si->fileName())) && pd->getGroupDef()) { - si->fileName=pd->getGroupDef()->getOutputFileBase().copy(); + si->setFileName(pd->getGroupDef()->getOutputFileBase()); } - if (si->definition) + if (si->definition()) { // TODO: there should be one function in Definition that returns // the file to link to, so we can avoid the following tests. const GroupDef *gd=0; - if (si->definition->definitionType()==Definition::TypeMember) + if (si->definition()->definitionType()==Definition::TypeMember) { - gd = (dynamic_cast(si->definition))->getGroupDef(); + gd = (dynamic_cast(si->definition()))->getGroupDef(); } if (gd) { - si->fileName=gd->getOutputFileBase().copy(); + si->setFileName(gd->getOutputFileBase()); } else { @@ -9863,8 +9861,6 @@ void initDoxygen() Doxygen::dirRelations.setAutoDelete(TRUE); Doxygen::genericsDict = new GenericsSDict; Doxygen::indexList = new IndexList; - Doxygen::sectionDict = new SectionDict(257); - Doxygen::sectionDict->setAutoDelete(TRUE); // initialisation of these globals depends on // configuration switches so we need to postpone these @@ -9893,8 +9889,8 @@ void initDoxygen() void cleanUpDoxygen() { FormulaManager::instance().clear(); + SectionManager::instance().clear(); - delete Doxygen::sectionDict; delete Doxygen::indexList; delete Doxygen::genericsDict; delete Doxygen::inputNameDict; diff --git a/src/doxygen.h b/src/doxygen.h index 2833611..e1f0a90 100644 --- a/src/doxygen.h +++ b/src/doxygen.h @@ -112,7 +112,6 @@ class Doxygen static QStrList tagfileList; static MemberNameSDict *memberNameSDict; static MemberNameSDict *functionNameSDict; - static SectionDict *sectionDict; static StringDict namespaceAliasDict; static GroupSDict *groupSDict; static NamespaceSDict *namespaceSDict; diff --git a/src/groupdef.cpp b/src/groupdef.cpp index 0d6d43f..7b954e5 100644 --- a/src/groupdef.cpp +++ b/src/groupdef.cpp @@ -1101,13 +1101,13 @@ void GroupDefImpl::writePageDocumentation(OutputList &ol) { if (!pd->isReference()) { - SectionInfo *si=0; + const SectionInfo *si=0; if (pd->hasTitle() && !pd->name().isEmpty() && - (si=Doxygen::sectionDict->find(pd->name()))!=0) + (si=SectionManager::instance().find(pd->name()))!=0) { - ol.startSection(si->label,si->title,SectionInfo::Subsection); - ol.docify(si->title); - ol.endSection(si->label,SectionInfo::Subsection); + ol.startSection(si->label(),si->title(),SectionType::Subsection); + ol.docify(si->title()); + ol.endSection(si->label(),SectionType::Subsection); } ol.startTextBlock(); ol.generateDoc(pd->docFile(),pd->docLine(),pd,0,pd->documentation()+pd->inbodyDocumentation(),TRUE,FALSE,0,TRUE,FALSE); diff --git a/src/htmlgen.cpp b/src/htmlgen.cpp index bf52eed..f9775fd 100644 --- a/src/htmlgen.cpp +++ b/src/htmlgen.cpp @@ -1435,29 +1435,29 @@ void HtmlGenerator::endGroupHeader(int extraIndentLevel) } } -void HtmlGenerator::startSection(const char *lab,const char *,SectionInfo::SectionType type) +void HtmlGenerator::startSection(const char *lab,const char *,SectionType type) { switch(type) { - case SectionInfo::Page: t << "\n\n

"; break; - case SectionInfo::Section: t << "\n\n

"; break; - case SectionInfo::Subsection: t << "\n\n

"; break; - case SectionInfo::Subsubsection: t << "\n\n

"; break; - case SectionInfo::Paragraph: t << "\n\n

"; break; + case SectionType::Page: t << "\n\n

"; break; + case SectionType::Section: t << "\n\n

"; break; + case SectionType::Subsection: t << "\n\n

"; break; + case SectionType::Subsubsection: t << "\n\n

"; break; + case SectionType::Paragraph: t << "\n\n

"; break; default: ASSERT(0); break; } t << ""; } -void HtmlGenerator::endSection(const char *,SectionInfo::SectionType type) +void HtmlGenerator::endSection(const char *,SectionType type) { switch(type) { - case SectionInfo::Page: t << "
"; break; - case SectionInfo::Section: t << ""; break; - case SectionInfo::Subsection: t << ""; break; - case SectionInfo::Subsubsection: t << ""; break; - case SectionInfo::Paragraph: t << ""; break; + case SectionType::Page: t << ""; break; + case SectionType::Section: t << ""; break; + case SectionType::Subsection: t << ""; break; + case SectionType::Subsubsection: t << ""; break; + case SectionType::Paragraph: t << ""; break; default: ASSERT(0); break; } } diff --git a/src/htmlgen.h b/src/htmlgen.h index fe84061..a8268da 100644 --- a/src/htmlgen.h +++ b/src/htmlgen.h @@ -250,8 +250,8 @@ class HtmlGenerator : public OutputGenerator void endExamples(); void startParamList(ParamListTypes,const char *); void endParamList(); - void startSection(const char *,const char *,SectionInfo::SectionType); - void endSection(const char *,SectionInfo::SectionType); + void startSection(const char *,const char *,SectionType); + void endSection(const char *,SectionType); void addIndexItem(const char *,const char *); void startIndent(); void endIndent(); diff --git a/src/index.cpp b/src/index.cpp index edc302b..2234377 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -2847,9 +2847,9 @@ static void writeMemberList(OutputList &ol,bool useSections,int page, QCString cl = letterToString(ml->letter()); QCString anchor=(QCString)"index_"+convertToId(cs); QCString title=(QCString)"- "+cl+" -"; - ol.startSection(anchor,title,SectionInfo::Subsection); + ol.startSection(anchor,title,SectionType::Subsection); ol.docify(title); - ol.endSection(anchor,SectionInfo::Subsection); + ol.endSection(anchor,SectionType::Subsection); ol.startItemList(); firstSection=FALSE; firstItem=TRUE; @@ -4160,8 +4160,8 @@ static void writeGroupTreeNode(OutputList &ol, GroupDef *gd, int level, FTVHelp* PageDef *pd; for (;(pd=it.current());++it) { - SectionInfo *si=0; - if (!pd->name().isEmpty()) si=Doxygen::sectionDict->find(pd->name()); + const SectionInfo *si=0; + if (!pd->name().isEmpty()) si=SectionManager::instance().find(pd->name()); bool hasSubPages = pd->hasSubPages(); bool hasSections = pd->hasSections(); Doxygen::indexList->addContentsItem( @@ -4169,7 +4169,7 @@ static void writeGroupTreeNode(OutputList &ol, GroupDef *gd, int level, FTVHelp* convertToHtml(pd->title(),TRUE), gd->getReference(), gd->getOutputFileBase(), - si ? si->label.data() : 0, + si ? si->label().data() : 0, hasSubPages || hasSections, TRUE); // addToNavIndex if (hasSections || hasSubPages) diff --git a/src/latexgen.cpp b/src/latexgen.cpp index 79ba44f..af3084e 100644 --- a/src/latexgen.cpp +++ b/src/latexgen.cpp @@ -1779,7 +1779,7 @@ void LatexGenerator::addIndexItem(const char *s1,const char *s2) } -void LatexGenerator::startSection(const char *lab,const char *,SectionInfo::SectionType type) +void LatexGenerator::startSection(const char *lab,const char *,SectionType type) { static bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS); static bool usePDFLatex = Config_getBool(USE_PDFLATEX); @@ -1792,11 +1792,11 @@ void LatexGenerator::startSection(const char *lab,const char *,SectionInfo::Sect { switch(type) { - case SectionInfo::Page: t << "doxysubsection"; break; - case SectionInfo::Section: t << "doxysubsubsection"; break; - case SectionInfo::Subsection: t << "doxyparagraph"; break; - case SectionInfo::Subsubsection: t << "doxysubparagraph"; break; - case SectionInfo::Paragraph: t << "doxysubparagraph"; break; + case SectionType::Page: t << "doxysubsection"; break; + case SectionType::Section: t << "doxysubsubsection"; break; + case SectionType::Subsection: t << "doxyparagraph"; break; + case SectionType::Subsubsection: t << "doxysubparagraph"; break; + case SectionType::Paragraph: t << "doxysubparagraph"; break; default: ASSERT(0); break; } t << "{"; @@ -1805,18 +1805,18 @@ void LatexGenerator::startSection(const char *lab,const char *,SectionInfo::Sect { switch(type) { - case SectionInfo::Page: t << "doxysection"; break; - case SectionInfo::Section: t << "doxysubsection"; break; - case SectionInfo::Subsection: t << "doxysubsubsection"; break; - case SectionInfo::Subsubsection: t << "doxyparagraph"; break; - case SectionInfo::Paragraph: t << "doxysubparagraph"; break; + case SectionType::Page: t << "doxysection"; break; + case SectionType::Section: t << "doxysubsection"; break; + case SectionType::Subsection: t << "doxysubsubsection"; break; + case SectionType::Subsubsection: t << "doxyparagraph"; break; + case SectionType::Paragraph: t << "doxysubparagraph"; break; default: ASSERT(0); break; } t << "{"; } } -void LatexGenerator::endSection(const char *lab,SectionInfo::SectionType) +void LatexGenerator::endSection(const char *lab,SectionType) { t << "}\\label{" << lab << "}" << endl; } diff --git a/src/latexgen.h b/src/latexgen.h index 7d4cae8..6bd1e17 100644 --- a/src/latexgen.h +++ b/src/latexgen.h @@ -241,8 +241,8 @@ class LatexGenerator : public OutputGenerator void endParamList(); void startDescForItem() { t << "\\par" << endl; } void endDescForItem() {} - void startSection(const char *,const char *,SectionInfo::SectionType); - void endSection(const char *,SectionInfo::SectionType); + void startSection(const char *,const char *,SectionType); + void endSection(const char *,SectionType); void addIndexItem(const char *,const char *); void startIndent() {} void endIndent() {} diff --git a/src/mangen.cpp b/src/mangen.cpp index 5f07932..6709748 100644 --- a/src/mangen.cpp +++ b/src/mangen.cpp @@ -593,33 +593,33 @@ void ManGenerator::endMemberGroup(bool) m_firstCol=FALSE; } -void ManGenerator::startSection(const char *,const char *,SectionInfo::SectionType type) +void ManGenerator::startSection(const char *,const char *,SectionType type) { if( !m_inHeader ) { switch(type) { - case SectionInfo::Page: startGroupHeader(FALSE); break; - case SectionInfo::Section: startGroupHeader(FALSE); break; - case SectionInfo::Subsection: startMemberHeader(0, -1); break; - case SectionInfo::Subsubsection: startMemberHeader(0, -1); break; - case SectionInfo::Paragraph: startMemberHeader(0, -1); break; + case SectionType::Page: startGroupHeader(FALSE); break; + case SectionType::Section: startGroupHeader(FALSE); break; + case SectionType::Subsection: startMemberHeader(0, -1); break; + case SectionType::Subsubsection: startMemberHeader(0, -1); break; + case SectionType::Paragraph: startMemberHeader(0, -1); break; default: ASSERT(0); break; } } } -void ManGenerator::endSection(const char *,SectionInfo::SectionType type) +void ManGenerator::endSection(const char *,SectionType type) { if( !m_inHeader ) { switch(type) { - case SectionInfo::Page: endGroupHeader(0); break; - case SectionInfo::Section: endGroupHeader(0); break; - case SectionInfo::Subsection: endMemberHeader(); break; - case SectionInfo::Subsubsection: endMemberHeader(); break; - case SectionInfo::Paragraph: endMemberHeader(); break; + case SectionType::Page: endGroupHeader(0); break; + case SectionType::Section: endGroupHeader(0); break; + case SectionType::Subsection: endMemberHeader(); break; + case SectionType::Subsubsection: endMemberHeader(); break; + case SectionType::Paragraph: endMemberHeader(); break; default: ASSERT(0); break; } } diff --git a/src/mangen.h b/src/mangen.h index eba6c8d..a3a2a33 100644 --- a/src/mangen.h +++ b/src/mangen.h @@ -176,8 +176,8 @@ class ManGenerator : public OutputGenerator //void writeDescItem(); void startDescForItem(); void endDescForItem(); - void startSection(const char *,const char *,SectionInfo::SectionType); - void endSection(const char *,SectionInfo::SectionType); + void startSection(const char *,const char *,SectionType); + void endSection(const char *,SectionType); void addIndexItem(const char *,const char *) {} void startIndent() {} void endIndent() {} diff --git a/src/markdown.cpp b/src/markdown.cpp index d0262b3..b9b92c3 100644 --- a/src/markdown.cpp +++ b/src/markdown.cpp @@ -1957,20 +1957,20 @@ void writeOneLineHeaderOrRuler(GrowBuf &out,const char *data,int size) QCString hTag; if (level<5 && !id.isEmpty()) { - SectionInfo::SectionType type = SectionInfo::Anchor; + SectionType type = SectionType::Anchor; switch(level) { - case 1: out.addStr("@section "); - type=SectionInfo::Section; + case 1: out.addStr("@section "); + type=SectionType::Section; break; - case 2: out.addStr("@subsection "); - type=SectionInfo::Subsection; + case 2: out.addStr("@subsection "); + type=SectionType::Subsection; break; - case 3: out.addStr("@subsubsection "); - type=SectionInfo::Subsubsection; + case 3: out.addStr("@subsubsection "); + type=SectionType::Subsubsection; break; - default: out.addStr("@paragraph "); - type=SectionInfo::Paragraph; + default: out.addStr("@paragraph "); + type=SectionType::Paragraph; break; } out.addStr(id); diff --git a/src/outputgen.h b/src/outputgen.h index 576e950..2b4da98 100644 --- a/src/outputgen.h +++ b/src/outputgen.h @@ -290,8 +290,8 @@ class BaseOutputDocInterface : public CodeOutputInterface virtual void endTitle() = 0; virtual void writeAnchor(const char *fileName,const char *name) = 0; - virtual void startSection(const char *,const char *,SectionInfo::SectionType) = 0; - virtual void endSection(const char *,SectionInfo::SectionType) = 0; + virtual void startSection(const char *,const char *,SectionType) = 0; + virtual void endSection(const char *,SectionType) = 0; virtual void lineBreak(const char *style) = 0; virtual void addIndexItem(const char *s1,const char *s2) = 0; diff --git a/src/outputlist.h b/src/outputlist.h index cfd3773..06c9185 100644 --- a/src/outputlist.h +++ b/src/outputlist.h @@ -329,9 +329,9 @@ class OutputList : public OutputDocInterface { forall(&OutputGenerator::startIndent); } void endIndent() { forall(&OutputGenerator::endIndent); } - void startSection(const char *lab,const char *title,SectionInfo::SectionType t) + void startSection(const char *lab,const char *title,SectionType t) { forall(&OutputGenerator::startSection,lab,title,t); } - void endSection(const char *lab,SectionInfo::SectionType t) + void endSection(const char *lab,SectionType t) { forall(&OutputGenerator::endSection,lab,t); } void addIndexItem(const char *s1,const char *s2) { forall(&OutputGenerator::addIndexItem,s1,s2); } diff --git a/src/pagedef.cpp b/src/pagedef.cpp index 8b6228f..0a6e014 100644 --- a/src/pagedef.cpp +++ b/src/pagedef.cpp @@ -213,7 +213,7 @@ void PageDefImpl::writeDocumentation(OutputList &ol) } ol.endQuickIndices(); } - SectionInfo *si=Doxygen::sectionDict->find(name()); + const SectionInfo *si=SectionManager::instance().find(name()); // save old generator state and write title only to Man generator ol.pushGeneratorState(); @@ -228,10 +228,10 @@ void PageDefImpl::writeDocumentation(OutputList &ol) ol.writeString(" - "); ol.popGeneratorState(); - if (si->title != manPageName) + if (si->title() != manPageName) { - ol.generateDoc(docFile(),docLine(),this,0,si->title,TRUE,FALSE,0,TRUE,FALSE); - ol.endSection(si->label,si->type); + ol.generateDoc(docFile(),docLine(),this,0,si->title(),TRUE,FALSE,0,TRUE,FALSE); + ol.endSection(si->label(),si->type()); } } ol.popGeneratorState(); @@ -246,10 +246,10 @@ void PageDefImpl::writeDocumentation(OutputList &ol) ol.disable(OutputGenerator::Man); if (hasTitle() && !name().isEmpty() && si!=0) { - ol.startPageDoc(si->title); + ol.startPageDoc(si->title()); //ol.startSection(si->label,si->title,si->type); startTitle(ol,getOutputFileBase(),this); - ol.generateDoc(docFile(),docLine(),this,0,si->title,TRUE,FALSE,0,TRUE,FALSE); + ol.generateDoc(docFile(),docLine(),this,0,si->title(),TRUE,FALSE,0,TRUE,FALSE); //stringToSearchIndex(getOutputFileBase(), // theTranslator->trPage(TRUE,TRUE)+" "+si->title, // si->title); @@ -297,7 +297,7 @@ void PageDefImpl::writePageDocumentation(OutputList &ol) ol.startTextBlock(); QCString docStr = documentation()+inbodyDocumentation(); - if (hasBriefDescription() && !Doxygen::sectionDict->find(name())) + if (hasBriefDescription() && !SectionManager::instance().find(name())) { ol.pushGeneratorState(); ol.disableAllBut(OutputGenerator::Man); @@ -331,14 +331,14 @@ void PageDefImpl::writePageDocumentation(OutputList &ol) PageDef *subPage=pdi.toFirst(); for (pdi.toFirst();(subPage=pdi.current());++pdi) { - SectionInfo::SectionType sectionType = SectionInfo::Paragraph; + SectionType sectionType = SectionType::Paragraph; switch (m_nestingLevel) { - case 0: sectionType = SectionInfo::Page; break; - case 1: sectionType = SectionInfo::Section; break; - case 2: sectionType = SectionInfo::Subsection; break; - case 3: sectionType = SectionInfo::Subsubsection; break; - default: sectionType = SectionInfo::Paragraph; break; + case 0: sectionType = SectionType::Page; break; + case 1: sectionType = SectionType::Section; break; + case 2: sectionType = SectionType::Subsection; break; + case 3: sectionType = SectionType::Subsubsection; break; + default: sectionType = SectionType::Paragraph; break; } QCString title = subPage->title(); if (title.isEmpty()) title = subPage->name(); diff --git a/src/perlmodgen.cpp b/src/perlmodgen.cpp index 7bbc4a7..dd0e4cc 100644 --- a/src/perlmodgen.cpp +++ b/src/perlmodgen.cpp @@ -2179,9 +2179,9 @@ void PerlModGenerator::generatePerlModForPage(PageDef *pd) m_output.openHash() .addFieldQuotedString("name", pd->name()); - SectionInfo *si = Doxygen::sectionDict->find(pd->name()); + const SectionInfo *si = SectionManager::instance().find(pd->name()); if (si) - m_output.addFieldQuotedString("title4", filterTitle(si->title)); + m_output.addFieldQuotedString("title4", filterTitle(si->title())); addPerlModDocBlock(m_output,"detailed",pd->docFile(),pd->docLine(),0,0,pd->documentation()); m_output.closeHash(); diff --git a/src/rtfgen.cpp b/src/rtfgen.cpp index 79411c6..39741dc 100644 --- a/src/rtfgen.cpp +++ b/src/rtfgen.cpp @@ -1686,7 +1686,7 @@ void RTFGenerator::endDescForItem() //} -void RTFGenerator::startSection(const char *,const char *title,SectionInfo::SectionType type) +void RTFGenerator::startSection(const char *,const char *title,SectionType type) { DBG_RTF(t << "{\\comment (startSection)}" << endl) t << "{"; @@ -1694,11 +1694,11 @@ void RTFGenerator::startSection(const char *,const char *title,SectionInfo::Sect int num=4; switch(type) { - case SectionInfo::Page: num=2; break; - case SectionInfo::Section: num=3; break; - case SectionInfo::Subsection: num=4; break; - case SectionInfo::Subsubsection: num=4; break; - case SectionInfo::Paragraph: num=4; break; + case SectionType::Page: num=2; break; + case SectionType::Section: num=3; break; + case SectionType::Subsection: num=4; break; + case SectionType::Subsubsection: num=4; break; + case SectionType::Paragraph: num=4; break; default: ASSERT(0); break; } QCString heading; @@ -1711,7 +1711,7 @@ void RTFGenerator::startSection(const char *,const char *title,SectionInfo::Sect t << "}" << endl; } -void RTFGenerator::endSection(const char *lab,SectionInfo::SectionType) +void RTFGenerator::endSection(const char *lab,SectionType) { DBG_RTF(t << "{\\comment (endSection)}" << endl) // make bookmark diff --git a/src/rtfgen.h b/src/rtfgen.h index c6cb76b..1750a7b 100644 --- a/src/rtfgen.h +++ b/src/rtfgen.h @@ -171,8 +171,8 @@ class RTFGenerator : public OutputGenerator //void writeDescItem(); void startDescForItem(); void endDescForItem(); - void startSection(const char *,const char *,SectionInfo::SectionType); - void endSection(const char *,SectionInfo::SectionType); + void startSection(const char *,const char *,SectionType); + void endSection(const char *,SectionType); void addIndexItem(const char *,const char *); void startIndent(); void endIndent(); diff --git a/src/section.h b/src/section.h index 9e6c695..fd11ebd 100644 --- a/src/section.h +++ b/src/section.h @@ -19,42 +19,190 @@ #ifndef SECTION_H #define SECTION_H -#include "sortdict.h" +#include +#include +#include +#include + +#include class Definition; -/** Class representing a section in a page */ -struct SectionInfo +enum class SectionType { - enum SectionType { Page = 0, - Section = 1, - Subsection = 2, - Subsubsection = 3, - Paragraph = 4, - Anchor = 5, - Table = 6 - }; - SectionInfo(const char *f,const int lin,const char *l,const char *t, - SectionType st,int lev,const char *r=0) : - label(l), title(t), type(st), ref(r), definition(0), - fileName(f), lineNr(lin), generated(FALSE), level(lev) {} - QCString label; - QCString title; - SectionType type; - QCString ref; - Definition *definition; - QCString fileName; - int lineNr; - bool generated; - int level; + Page = 0, + Section = 1, + Subsection = 2, + Subsubsection = 3, + Paragraph = 4, + Anchor = 5, + Table = 6 }; -/** Unsorted dictionary of SectionInfo objects. */ -class SectionDict : public SDict +inline constexpr bool isSection(SectionType type) +{ + return (type==SectionType::Section || + type==SectionType::Subsection || + type==SectionType::Subsubsection || + type==SectionType::Paragraph); +} + + +class SectionInfo { public: - SectionDict(int size) : SDict(size) {} - ~SectionDict() {} + SectionInfo(const char *fileName, int lineNr, const char *label, + const char *title, SectionType type, int level, const char *ref): + m_label(label), m_title(title), m_type(type), m_ref(ref), + m_lineNr(lineNr), m_fileName(fileName), m_level(level) + { + //printf("SectionInfo(%p)\n",this); + } + ~SectionInfo() + { + //printf("~SectionInfo(%p)\n",this); + } + + + QCString label() const { return m_label; } + QCString title() const { return m_title; } + SectionType type() const { return m_type; } + QCString ref() const { return m_ref; } + int lineNr() const { return m_lineNr; } + QCString fileName() const { return m_fileName; } + bool generated() const { return m_generated; } + int level() const { return m_level; } + Definition *definition() const { return m_definition; } + + // setters + void setFileName(const char *fn) { m_fileName = fn; } + void setType(SectionType t) { m_type = t; } + void setGenerated(bool b) { m_generated = b; } + void setDefinition(Definition *d) { m_definition = d; } + + private: + QCString m_label; + QCString m_title; + SectionType m_type; + QCString m_ref; + int m_lineNr; + QCString m_fileName; + bool m_generated = false; + int m_level; + Definition *m_definition = 0; }; +class SectionRefs +{ + using SectionInfoVec = std::vector; + public: + using iterator = SectionInfoVec::const_iterator; + + const SectionInfo *find(const char *label) const + { + auto it = m_lookup.find(label); + return it!=m_lookup.end() ? it->second : nullptr; + } + + void add(const SectionInfo *si) + { + m_lookup.insert({std::string(si->label()),si}); + m_entries.push_back(si); + } + + iterator begin() const + { + return m_entries.cbegin(); + } + + iterator end() const + { + return m_entries.cend(); + } + + bool empty() const + { + return m_lookup.empty(); + } + + private: + SectionInfoVec m_entries; + std::map< std::string, const SectionInfo* > m_lookup; +}; + +class SectionManager +{ + using SectionInfoPtr = std::unique_ptr; + using SectionInfoVec = std::vector; + + public: + using iterator = SectionInfoVec::iterator; + + SectionInfo *find(const char *label) + { + auto it = m_lookup.find(label); + return it!=m_lookup.end() ? it->second : nullptr; + } + + const SectionInfo *find(const char *label) const + { + auto it = m_lookup.find(label); + return it!=m_lookup.end() ? it->second : nullptr; + } + + SectionInfo *add(const char *fileName, + int lineNr, + const char *label, + const char *title, + SectionType type, + int level, + const char *ref=0) + { + SectionInfoPtr si = std::make_unique( + fileName,lineNr,label,title,type,level,ref); + SectionInfo *result = si.get(); + m_lookup.insert({std::string(label),result}); + m_entries.push_back(std::move(si)); + return result; + } + + SectionInfo *add(const SectionInfo &si) + { + add(si.fileName(),si.lineNr(),si.label(),si.title(),si.type(),si.level(),si.ref()); + return find(si.label()); + } + iterator begin() + { + return m_entries.begin(); + } + iterator end() + { + return m_entries.end(); + } + bool empty() const + { + return m_entries.empty(); + } + void clear() + { + m_entries.clear(); + m_lookup.clear(); + } + + static SectionManager &instance() + { + static SectionManager sm; + return sm; + } + + private: + SectionManager() {} + SectionManager(const SectionManager &other) = delete; + SectionManager &operator=(const SectionManager &other) = delete; + + SectionInfoVec m_entries; + std::map< std::string, SectionInfo* > m_lookup; +}; + + #endif diff --git a/src/tagreader.cpp b/src/tagreader.cpp index 3f9a7a1..60b2e53 100644 --- a/src/tagreader.cpp +++ b/src/tagreader.cpp @@ -1162,13 +1162,13 @@ void TagFileParser::addDocAnchors(const std::shared_ptr &e,const TagAncho TagAnchorInfo *ta; for (tli.toFirst();(ta=tli.current());++tli) { - if (Doxygen::sectionDict->find(ta->label)==0) + if (SectionManager::instance().find(ta->label)==0) { //printf("New sectionInfo file=%s anchor=%s\n", // ta->fileName.data(),ta->label.data()); - SectionInfo *si=new SectionInfo(ta->fileName,-1,ta->label,ta->title, - SectionInfo::Anchor,0,m_tagName); - Doxygen::sectionDict->append(ta->label,si); + SectionInfo *si=SectionManager::instance().add( + ta->fileName,-1,ta->label,ta->title, + SectionType::Anchor,0,m_tagName); e->anchors.push_back(si); } else diff --git a/src/util.cpp b/src/util.cpp index 38d7cdf..25ca13e 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -4752,7 +4752,7 @@ bool resolveLink(/* in */ const char *scName, const ClassDef *cd; const DirDef *dir; const NamespaceDef *nd; - SectionInfo *si=0; + const SectionInfo *si=0; bool ambig; if (linkRef.isEmpty()) // no reference name! { @@ -4763,9 +4763,9 @@ bool resolveLink(/* in */ const char *scName, const GroupDef *gd = pd->getGroupDef(); if (gd) { - if (!pd->name().isEmpty()) si=Doxygen::sectionDict->find(pd->name()); + if (!pd->name().isEmpty()) si=SectionManager::instance().find(pd->name()); *resContext=gd; - if (si) resAnchor = si->label; + if (si) resAnchor = si->label(); } else { @@ -4773,10 +4773,10 @@ bool resolveLink(/* in */ const char *scName, } return TRUE; } - else if ((si=Doxygen::sectionDict->find(linkRef))) + else if ((si=SectionManager::instance().find(linkRef))) { - *resContext=si->definition; - resAnchor = si->label; + *resContext=si->definition(); + resAnchor = si->label(); return TRUE; } else if ((pd=Doxygen::exampleSDict->find(linkRef))) // link to an example @@ -6653,28 +6653,27 @@ PageDef *addRelatedPage(const char *name,const QCString &ptitle, { file=pd->getOutputFileBase(); } - SectionInfo *si = Doxygen::sectionDict->find(pd->name()); + const SectionInfo *si = SectionManager::instance().find(pd->name()); if (si) { - if (si->lineNr != -1) + if (si->lineNr() != -1) { - warn(file,-1,"multiple use of section label '%s', (first occurrence: %s, line %d)",pd->name().data(),si->fileName.data(),si->lineNr); + warn(file,-1,"multiple use of section label '%s', (first occurrence: %s, line %d)",pd->name().data(),si->fileName().data(),si->lineNr()); } else { - warn(file,-1,"multiple use of section label '%s', (first occurrence: %s)",pd->name().data(),si->fileName.data()); + warn(file,-1,"multiple use of section label '%s', (first occurrence: %s)",pd->name().data(),si->fileName().data()); } } else { - si=new SectionInfo( - file,-1,pd->name(),pd->title(),SectionInfo::Page,0,pd->getReference()); + SectionManager::instance().add( + file,-1,pd->name(),pd->title(),SectionType::Page,0,pd->getReference()); //printf("si->label='%s' si->definition=%s si->fileName='%s'\n", // si->label.data(),si->definition?si->definition->name().data():"", // si->fileName.data()); //printf(" SectionInfo: sec=%p sec->fileName=%s\n",si,si->fileName.data()); //printf("Adding section key=%s si->fileName=%s\n",pageName.data(),si->fileName.data()); - Doxygen::sectionDict->append(pd->name(),si); } } } diff --git a/src/xmlgen.cpp b/src/xmlgen.cpp index bf5af84..7a72346 100644 --- a/src/xmlgen.cpp +++ b/src/xmlgen.cpp @@ -1823,32 +1823,30 @@ static void generateXMLForPage(PageDef *pd,FTextStream &ti,bool isExample) } else { - SectionInfo *si = Doxygen::sectionDict->find(pd->name()); + const SectionInfo *si = SectionManager::instance().find(pd->name()); if (si) { - t << " " << convertToXML(convertCharEntitiesToUTF8(filterTitle(si->title))) + t << " <title>" << convertToXML(convertCharEntitiesToUTF8(filterTitle(si->title()))) << "" << endl; } } writeInnerPages(pd->getSubPages(),t); - SectionDict *sectionDict = pd->getSectionDict(); - if (pd->localToc().isXmlEnabled() && sectionDict) + const SectionRefs §ionRefs = pd->getSectionRefs(); + if (pd->localToc().isXmlEnabled() && !sectionRefs.empty()) { t << " " << endl; - SDict::Iterator li(*sectionDict); - SectionInfo *si; + //SDict::Iterator li(*sectionDict); + //SectionInfo *si; int level=1,l; bool inLi[5]={ FALSE, FALSE, FALSE, FALSE, FALSE }; int maxLevel = pd->localToc().xmlLevel(); - for (li.toFirst();(si=li.current());++li) + //for (li.toFirst();(si=li.current());++li) + for (const SectionInfo *si : sectionRefs) { - if (si->type==SectionInfo::Section || - si->type==SectionInfo::Subsection || - si->type==SectionInfo::Subsubsection || - si->type==SectionInfo::Paragraph) + if (isSection(si->type())) { //printf(" level=%d title=%s\n",level,si->title.data()); - int nextLevel = (int)si->type; + int nextLevel = (int)si->type(); if (nextLevel>level) { for (l=level;l" << endl; - QCString titleDoc = convertToXML(si->title); + QCString titleDoc = convertToXML(si->title()); t << " " << endl; - t << " " << (si->title.isEmpty()?si->label:titleDoc) << "" << endl; - t << " " << convertToXML(pageName) << "_1" << convertToXML(si -> label) << "" << endl; + t << " " << (si->title().isEmpty()?si->label():titleDoc) << "" << endl; + t << " " << convertToXML(pageName) << "_1" << convertToXML(si->label()) << "" << endl; inLi[nextLevel]=TRUE; level = nextLevel; } -- cgit v0.12