From 185d6abdc832e7dd66183a2154a13a546414b96f Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Sun, 22 Jul 2018 17:19:56 +0200 Subject: Moved local toc data into a separate type for better encapsulation --- src/commentscan.l | 14 +++--- src/definition.cpp | 122 ++++++++++++++++++++++++++--------------------------- src/definition.h | 9 +--- src/doxygen.cpp | 4 +- src/entry.cpp | 9 ---- src/entry.h | 3 +- src/index.cpp | 4 +- src/marshal.cpp | 42 +++++++++++++----- src/pagedef.cpp | 17 ++------ src/pagedef.h | 9 ++-- src/types.h | 45 ++++++++++++++++++++ src/xmlgen.cpp | 4 +- 12 files changed, 158 insertions(+), 124 deletions(-) diff --git a/src/commentscan.l b/src/commentscan.l index f6cf099..c364312 100644 --- a/src/commentscan.l +++ b/src/commentscan.l @@ -2897,26 +2897,22 @@ static bool handleToc(const QCString &, const QCString &opt) { if (opt == "html") { - current->localToc |= (1 << Definition::Html); - current->localTocLevel[Definition::Html] = level; + current->localToc.enableHtml(level); } else if (opt == "latex") { - current->localToc |= (1 << Definition::Latex); - current->localTocLevel[Definition::Latex] = level; + current->localToc.enableLatex(level); } else if (opt == "xml") { - current->localToc |= (1 << Definition::Xml); - current->localTocLevel[Definition::Xml] = level; + current->localToc.enableXml(level); } else warn(yyFileName,yyLineNr,"Unknown option specified with \\tableofcontents: `%s'", (*it).stripWhiteSpace().data()); } } - if (current->localToc == Definition::None) + if (current->localToc.nothingEnabled()) { - current->localToc |= (1 << Definition::Html); - current->localTocLevel[Definition::Html] = 5; + current->localToc.enableHtml(5); // for backward compatibility } } return FALSE; diff --git a/src/definition.cpp b/src/definition.cpp index f44c403..cbfad94 100644 --- a/src/definition.cpp +++ b/src/definition.cpp @@ -1614,83 +1614,83 @@ void Definition::writeNavigationPath(OutputList &ol) const } // TODO: move to htmlgen -void Definition::writeToc(OutputList &ol, int localToc, int *localTocLevel) +void Definition::writeToc(OutputList &ol, const LocalToc &localToc) { SectionDict *sectionDict = m_impl->sectionDict; if (sectionDict==0) return; - if (PageDef::isLocalToc(localToc, Definition::Html)) - { - int maxLevel = localTocLevel[Definition::Html]; - ol.pushGeneratorState(); - ol.disableAllBut(OutputGenerator::Html); - ol.writeString("
"); - ol.writeString("

"); - ol.writeString(theTranslator->trRTFTableOfContents()); - ol.writeString("

\n"); - ol.writeString("\n"); + level--; + } + if (level <= maxLevel && inLi[level]) ol.writeString("\n"); inLi[level]=FALSE; ol.writeString("\n"); - level--; - } - if (level <= maxLevel && inLi[level]) ol.writeString("\n"); - inLi[level]=FALSE; - ol.writeString("\n"); - ol.writeString("
\n"); - ol.popGeneratorState(); + ol.writeString("\n"); + ol.popGeneratorState(); } - if (PageDef::isLocalToc(localToc, Definition::Latex)) + if (localToc.isLatexEnabled()) { - char tmp[100]; - ol.pushGeneratorState(); - ol.disableAllBut(OutputGenerator::Latex); - sprintf(tmp,"\\etocsetnexttocdepth{%d}\n",localTocLevel[Definition::Latex]); - ol.writeString(tmp); - - ol.writeString("\\localtableofcontents\n"); - ol.popGeneratorState(); + ol.pushGeneratorState(); + ol.disableAllBut(OutputGenerator::Latex); + int maxLevel = localToc.latexLevel(); + + ol.writeString("\\etocsetnexttocdepth{"+QCString().setNum(maxLevel)+"}\n"); + + ol.writeString("\\localtableofcontents\n"); + ol.popGeneratorState(); } } diff --git a/src/definition.h b/src/definition.h index ac9cc56..c0428a0 100644 --- a/src/definition.h +++ b/src/definition.h @@ -97,13 +97,6 @@ class Definition : public DefinitionIntf virtual ~Cookie() {} }; - enum outputLocalTocType { - None = 0, // absolute value - Html = 0, // index / also to be used as (1 << Definition::Html) - Latex = 1, // ... - Xml = 2, // ... - numOutputLocalTocType = 3 // number of outputLocalTocType - }; /*! Create a new definition */ Definition( const char *defFileName,int defLine,int defColumn, @@ -356,7 +349,7 @@ class Definition : public DefinitionIntf void setLocalName(const QCString name); void addSectionsToIndex(); - void writeToc(OutputList &ol, int localToc, int *localTocLevel); + void writeToc(OutputList &ol, const LocalToc <); void setCookie(Cookie *cookie) { delete m_cookie; m_cookie = cookie; } Cookie *cookie() const { return m_cookie; } diff --git a/src/doxygen.cpp b/src/doxygen.cpp index 8facb3f..7353516 100644 --- a/src/doxygen.cpp +++ b/src/doxygen.cpp @@ -609,7 +609,7 @@ static void addRelatedPage(EntryNav *rootNav) { pd->setBriefDescription(root->brief,root->briefFile,root->briefLine); pd->addSectionsToDefinition(root->anchors); - pd->setShowToc(root->localToc, root->localTocLevel); + pd->setLocalToc(root->localToc); addPageToContext(pd,rootNav); } } @@ -8716,7 +8716,7 @@ static void findMainPage(EntryNav *rootNav) //setFileNameForSections(root->anchors,"index",Doxygen::mainPage); Doxygen::mainPage->setBriefDescription(root->brief,root->briefFile,root->briefLine); Doxygen::mainPage->setFileName(indexName); - Doxygen::mainPage->setShowToc(root->localToc, root->localTocLevel); + Doxygen::mainPage->setLocalToc(root->localToc); addPageToContext(Doxygen::mainPage,rootNav); SectionInfo *si = Doxygen::sectionDict->find(Doxygen::mainPage->name()); diff --git a/src/entry.cpp b/src/entry.cpp index e4fb0a5..a0460da 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -74,10 +74,6 @@ Entry::Entry(const Entry &e) initLines = e.initLines; stat = e.stat; localToc = e.localToc; - for (int i = 0; i < sizeof(localTocLevel) / sizeof(*localTocLevel) ; i++) - { - localTocLevel[i] = e.localTocLevel[i]; - } explicitExternal = e.explicitExternal; proto = e.proto; subGrouping = e.subGrouping; @@ -258,11 +254,6 @@ void Entry::reset() mtype = Method; virt = Normal; stat = FALSE; - localToc = Definition::None; - for (int i = 0; i < sizeof(localTocLevel) / sizeof(*localTocLevel) ; i++) - { - localTocLevel[i] = 0; - } proto = FALSE; explicitExternal = FALSE; spec = 0; diff --git a/src/entry.h b/src/entry.h index 8513fb9..fac3831 100644 --- a/src/entry.h +++ b/src/entry.h @@ -288,8 +288,7 @@ class Entry bool artificial; //!< Artificially introduced item GroupDocType groupDocType; QCString id; //!< libclang id - int localToc; //!< types of local TOC, command \tableofcontents - int localTocLevel[3];//!< depth of local TOC, command \tableofcontents + LocalToc localToc; static int num; //!< counts the total number of entries diff --git a/src/index.cpp b/src/index.cpp index b403de3..3c231fc 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -3883,9 +3883,9 @@ static void writeIndex(OutputList &ol) if (Doxygen::mainPage) { Doxygen::insideMainPage=TRUE; - if (Doxygen::mainPage->showToc() && Doxygen::mainPage->hasSections()) + if (Doxygen::mainPage->localToc().isHtmlEnabled() && Doxygen::mainPage->hasSections()) { - Doxygen::mainPage->writeToc(ol,Doxygen::mainPage->showToc(),Doxygen::mainPage->showTocLevel()); + Doxygen::mainPage->writeToc(ol,Doxygen::mainPage->localToc()); } ol.startTextBlock(); diff --git a/src/marshal.cpp b/src/marshal.cpp index 43c5511..f13b6fd 100644 --- a/src/marshal.cpp +++ b/src/marshal.cpp @@ -344,6 +344,14 @@ void marshalMemberLists(StorageIntf *s,SDict *mls) } } +void marshalLocalToc(StorageIntf *s,const LocalToc <) +{ + marshalInt(s,lt.mask()); + marshalInt(s,lt.htmlLevel()); + marshalInt(s,lt.latexLevel()); + marshalInt(s,lt.xmlLevel()); +} + void marshalEntry(StorageIntf *s,Entry *e) { marshalUInt(s,HEADER); @@ -355,11 +363,7 @@ void marshalEntry(StorageIntf *s,Entry *e) marshalUInt64(s,e->spec); marshalInt(s,e->initLines); marshalBool(s,e->stat); - marshalInt(s,e->localToc); - for (int i = 0; i < sizeof(e->localTocLevel) / sizeof(*(e->localTocLevel)) ; i++) - { - marshalInt(s,e->localTocLevel[i]); - } + marshalLocalToc(s,e->localToc); marshalBool(s,e->explicitExternal); marshalBool(s,e->proto); marshalBool(s,e->subGrouping); @@ -729,6 +733,28 @@ SDict *unmarshalMemberLists(StorageIntf *s) return result; } +LocalToc unmarshalLocalToc(StorageIntf *s) +{ + LocalToc result; + int mask = unmarshalInt(s); + int htmlLevel = unmarshalInt(s); + int latexLevel = unmarshalInt(s); + int xmlLevel = unmarshalInt(s); + if ((mask & LocalToc::Html)!=0) + { + result.enableHtml(htmlLevel); + } + if ((mask & LocalToc::Latex)!=0) + { + result.enableLatex(latexLevel); + } + if ((mask & LocalToc::Xml)!=0) + { + result.enableXml(xmlLevel); + } + return result; +} + Entry * unmarshalEntry(StorageIntf *s) { Entry *e = new Entry; @@ -742,11 +768,7 @@ Entry * unmarshalEntry(StorageIntf *s) e->spec = unmarshalUInt64(s); e->initLines = unmarshalInt(s); e->stat = unmarshalBool(s); - e->localToc = unmarshalInt(s); - for (int i = 0; i < sizeof(e->localTocLevel) / sizeof(*(e->localTocLevel)) ; i++) - { - e->localTocLevel[i] = unmarshalInt(s); - } + e->localToc = unmarshalLocalToc(s); e->explicitExternal = unmarshalBool(s); e->proto = unmarshalBool(s); e->subGrouping = unmarshalBool(s); diff --git a/src/pagedef.cpp b/src/pagedef.cpp index df5cf0d..4721306 100644 --- a/src/pagedef.cpp +++ b/src/pagedef.cpp @@ -35,11 +35,6 @@ PageDef::PageDef(const char *f,int l,const char *n, m_pageScope = 0; m_nestingLevel = 0; m_fileName = ::convertNameToFile(n,FALSE,TRUE); - m_showToc = Definition::None; - for (int i = 0; i < sizeof(m_localTocLevel) / sizeof(*m_localTocLevel) ; i++) - { - m_localTocLevel[i] = 0; - } } PageDef::~PageDef() @@ -211,9 +206,9 @@ void PageDef::writeDocumentation(OutputList &ol) ol.popGeneratorState(); //2.} - if (m_showToc && hasSections()) + if ((m_localToc.isHtmlEnabled() || m_localToc.isLatexEnabled()) && hasSections()) { - writeToc(ol, m_showToc, m_localTocLevel); + writeToc(ol, m_localToc); } writePageDocumentation(ol); @@ -330,11 +325,7 @@ void PageDef::setNestingLevel(int l) m_nestingLevel = l; } -void PageDef::setShowToc(int localToc, int *localTocLevel) +void PageDef::setLocalToc(const LocalToc <) { - m_showToc |= localToc; - for (int i = 0; i < sizeof(m_localTocLevel) / sizeof(*m_localTocLevel) ; i++) - { - m_localTocLevel[i] += localTocLevel[i]; - } + m_localToc = lt; } diff --git a/src/pagedef.h b/src/pagedef.h index 7016049..27316cb 100644 --- a/src/pagedef.h +++ b/src/pagedef.h @@ -34,7 +34,7 @@ class PageDef : public Definition // setters void setFileName(const char *name); - void setShowToc(int localToc, int *localTocLevel); + void setLocalToc(const LocalToc &tl); // getters DefType definitionType() const { return TypePage; } @@ -59,9 +59,7 @@ class PageDef : public Definition bool documentedPage() const; bool hasSubPages() const; bool hasParentPage() const; - int showToc() const { return m_showToc; } - int *showTocLevel() { return m_localTocLevel; } - static bool isLocalToc(int localToc, int tocType) { return(localToc & (1 << tocType)); } + LocalToc localToc() const { return m_localToc; } void setPageScope(Definition *d){ m_pageScope = d; } Definition *getPageScope() const { return m_pageScope; } QCString displayName(bool=TRUE) const { return !m_title.isEmpty() ? m_title : Definition::name(); } @@ -77,8 +75,7 @@ class PageDef : public Definition PageSDict *m_subPageDict; // list of pages in the group Definition *m_pageScope; int m_nestingLevel; - int m_showToc; - int m_localTocLevel[numOutputLocalTocType]; + LocalToc m_localToc; }; class PageSDict : public SDict diff --git a/src/types.h b/src/types.h index 806e6fc..36f31fe 100644 --- a/src/types.h +++ b/src/types.h @@ -16,6 +16,7 @@ #ifndef TYPES_H #define TYPES_H +#include #include /** @file @@ -218,4 +219,48 @@ enum FortranFormat FortranFormat_Fixed }; +class LocalToc +{ + public: + enum Type { + None = 0, // initial value + Html = 0, // index / also to be used as (1 << Definition::Html) + Latex = 1, // ... + Xml = 2, // ... + numTocTypes = 3 // number of enum values + }; + LocalToc() : m_mask(None) { memset(m_level,0,sizeof(m_level)); } + + // setters + void enableHtml(int level) + { + m_mask|=(1<getSubPages(),t); - if (PageDef::isLocalToc(pd->showToc(), Definition::Xml)) + if (pd->localToc().isXmlEnabled()) { t << " " << endl; SectionDict *sectionDict = pd->getSectionDict(); @@ -1846,7 +1846,7 @@ static void generateXMLForPage(PageDef *pd,FTextStream &ti,bool isExample) SectionInfo *si; int level=1,l; bool inLi[5]={ FALSE, FALSE, FALSE, FALSE }; - int maxLevel = (pd -> showTocLevel())[Definition::Xml]; + int maxLevel = pd->localToc().xmlLevel(); for (li.toFirst();(si=li.current());++li) { if (si->type==SectionInfo::Section || -- cgit v0.12