From 9282aab5ed2a0cca3858df6e62132f959e99edb5 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Sun, 27 Jul 2014 10:28:51 +0200 Subject: [PATCH] Template context support for CREATE_SUBDIRS --- src/context.cpp | 114 +++++++++++++++++++++++++++++++++++++++------ src/context.h | 4 +- src/definition.cpp | 2 +- src/memberdef.cpp | 2 +- src/template.cpp | 21 +++++++++ 5 files changed, 124 insertions(+), 19 deletions(-) diff --git a/src/context.cpp b/src/context.cpp index f03f6f8a5ea..b35fffa5181 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -13,6 +13,8 @@ * */ +#include + #include "context.h" #include "config.h" #include "index.h" @@ -286,7 +288,7 @@ class ConfigContext::Private { public: Private() { m_cachedLists.setAutoDelete(TRUE); } - ~Private() { } + virtual ~Private() { } TemplateVariant fetchList(const QCString &name,const QStrList *list) { TemplateVariant *v = m_cachedLists.find(name); @@ -663,6 +665,19 @@ class TranslateContext::Private : public PropertyMapper static bool extractAll = Config_getBool("EXTRACT_ALL"); return theTranslator->trNamespaceMemberDescription(extractAll); } + TemplateVariant classMembersDescription() const + { + static bool extractAll = Config_getBool("EXTRACT_ALL"); + static bool fortranOpt = Config_getBool("OPTIMIZE_FOR_FORTRAN"); + if (fortranOpt) + { + return theTranslator->trCompoundMembersDescriptionFortran(extractAll); + } + else + { + return theTranslator->trCompoundMembersDescription(extractAll); + } + } TemplateVariant relatedPagesDesc() const { return theTranslator->trRelatedPagesDescription(); @@ -805,6 +820,11 @@ class TranslateContext::Private : public PropertyMapper bool extractAll = Config_getBool("EXTRACT_ALL"); return theTranslator->trModulesListDescription(extractAll); } + TemplateVariant namespaceListDescription() const + { + bool extractAll = Config_getBool("EXTRACT_ALL"); + return theTranslator->trNamespaceListDescription(extractAll); + } TemplateVariant directories() const { return theTranslator->trDirectories(); @@ -871,6 +891,8 @@ class TranslateContext::Private : public PropertyMapper addProperty("classHierarchy", this,&Private::classHierarchy); //%% string classMembers addProperty("classMembers", this,&Private::classMembers); + //%% string classMembersDescription + addProperty("classMembersDescription",this,&Private::classMembersDescription); //%% string modules addProperty("modules", this,&Private::modules); //%% string namespaces @@ -961,6 +983,8 @@ class TranslateContext::Private : public PropertyMapper addProperty("detailLevel", this,&Private::detailLevel); //%% string fileListDescription addProperty("fileListDescription",this,&Private::fileListDescription); + //%% string namespaceListDescription + addProperty("namespaceListDescription",this,&Private::namespaceListDescription); //%% string directories addProperty("directories", this,&Private::directories); //%% string moduleDescript @@ -1177,7 +1201,7 @@ class DefinitionContext : public PropertyMapper static bool createSubdirs = Config_getBool("CREATE_SUBDIRS"); return createSubdirs ? QCString("../../") : QCString(""); } - TemplateVariant relPath() const + virtual TemplateVariant relPath() const { return relPathAsString(); } @@ -1499,6 +1523,7 @@ class ClassContext::Private : public DefinitionContext addProperty("memberGroups", this,&Private::memberGroups); addProperty("additionalInheritedMembers",this,&Private::additionalInheritedMembers); } + virtual ~Private() {} TemplateVariant title() const { return TemplateVariant(m_classDef->title()); @@ -2175,6 +2200,7 @@ class NamespaceContext::Private : public DefinitionContexttitle()); @@ -2433,6 +2459,7 @@ class FileContext::Private : public DefinitionContext addProperty("inlineClasses", this,&Private::inlineClasses); addProperty("compoundType", this,&Private::compoundType); } + virtual ~Private() {} TemplateVariant title() const { return m_fileDef->title(); @@ -2789,6 +2816,7 @@ class DirContext::Private : public DefinitionContext addProperty("hasDetails", this,&Private::hasDetails); addProperty("compoundType", this,&Private::compoundType); } + virtual ~Private() {} TemplateVariant title() const { return TemplateVariant(m_dirDef->shortTitle()); @@ -2849,6 +2877,10 @@ class DirContext::Private : public DefinitionContext { return theTranslator->trDir(FALSE,TRUE); } + TemplateVariant relPath() const + { + return ""; + } private: DirDef *m_dirDef; @@ -2891,6 +2923,7 @@ class PageContext::Private : public DefinitionContext addProperty("highlight",this,&Private::highlight); addProperty("subhighlight",this,&Private::subHighlight); } + virtual ~Private() {} TemplateVariant title() const { if (m_isMainPage) @@ -2909,9 +2942,27 @@ class PageContext::Private : public DefinitionContext return m_pageDef->title(); } } + TemplateVariant relPath() const + { + if (m_pageDef==Doxygen::mainPage) + { + return ""; + } + else + { + return DefinitionContext::relPath(); + } + } TemplateVariant highlight() const { - return "pages"; + if (m_pageDef==Doxygen::mainPage) + { + return "main"; + } + else + { + return "pages"; + } } TemplateVariant subHighlight() const { @@ -3186,6 +3237,7 @@ class MemberContext::Private : public DefinitionContext if (md->isRaisable()) m_cache.eventAttrs->append("raise"); } } + virtual ~Private() {} TemplateVariant fieldType() const { return createLinkedText(m_memberDef,relPathAsString(),m_memberDef->fieldType()); @@ -4161,6 +4213,7 @@ class ModuleContext::Private : public DefinitionContext addProperty("inlineClasses", this,&Private::inlineClasses); addProperty("compoundType", this,&Private::compoundType); } + virtual ~Private() {} TemplateVariant title() const { return TemplateVariant(m_groupDef->groupTitle()); @@ -5784,6 +5837,23 @@ TemplateListIntf::ConstIterator *NamespaceListContext::createIterator() const class NamespaceTreeContext::Private : public PropertyMapper { public: + Private() + { + m_namespaceTree.reset(NestingContext::alloc(0,0)); + if (Doxygen::namespaceSDict) + { + m_namespaceTree->addNamespaces(*Doxygen::namespaceSDict,TRUE,FALSE); + } + //%% Nesting tree + addProperty("tree",this,&Private::tree); + addProperty("fileName",this,&Private::fileName); + addProperty("relPath",this,&Private::relPath); + addProperty("highlight",this,&Private::highlight); + addProperty("subhighlight",this,&Private::subhighlight); + addProperty("title",this,&Private::title); + addProperty("preferredDepth",this,&Private::preferredDepth); + addProperty("maxDepth",this,&Private::maxDepth); + } TemplateVariant tree() const { return m_namespaceTree.get(); @@ -5822,23 +5892,35 @@ class NamespaceTreeContext::Private : public PropertyMapper return theTranslator->trNamespaceList(); } } - Private() + TemplateVariant maxDepth() const { - m_namespaceTree.reset(NestingContext::alloc(0,0)); - if (Doxygen::namespaceSDict) + if (!m_cache.maxDepthComputed) { - m_namespaceTree->addNamespaces(*Doxygen::namespaceSDict,TRUE,FALSE); + m_cache.maxDepth = computeMaxDepth(m_namespaceTree.get()); + m_cache.maxDepthComputed=TRUE; } - //%% Nesting tree - addProperty("tree",this,&Private::tree); - addProperty("fileName",this,&Private::fileName); - addProperty("relPath",this,&Private::relPath); - addProperty("highlight",this,&Private::highlight); - addProperty("subhighlight",this,&Private::subhighlight); - addProperty("title",this,&Private::title); + return m_cache.maxDepth; + } + TemplateVariant preferredDepth() const + { + if (!m_cache.preferredDepthComputed) + { + m_cache.preferredDepth = computePreferredDepth(m_namespaceTree.get(),maxDepth().toInt()); + m_cache.preferredDepthComputed=TRUE; + } + return m_cache.preferredDepth; } private: SharedPtr m_namespaceTree; + struct Cachable + { + Cachable() : maxDepthComputed(FALSE), preferredDepthComputed(FALSE) {} + int maxDepth; + bool maxDepthComputed; + int preferredDepth; + bool preferredDepthComputed; + }; + mutable Cachable m_cache; }; //%% } @@ -7581,7 +7663,7 @@ class InheritedMemberInfoContext::Private : public PropertyMapper addProperty("id", this,&Private::id); addProperty("inheritedFrom", this,&Private::inheritedFrom); } - ~Private() + virtual ~Private() { delete m_memberList; } @@ -8120,6 +8202,8 @@ void generateOutputViaTemplate() g_globals.outputFormat = ContextGlobals::Html; g_globals.dynSectionId = 0; g_globals.outputDir = Config_getString("HTML_OUTPUT"); + QDir dir(g_globals.outputDir); + createSubDirs(dir); HtmlEscaper htmlEsc; ctx->setEscapeIntf(Config_getString("HTML_FILE_EXTENSION"),&htmlEsc); HtmlSpaceless spl; diff --git a/src/context.h b/src/context.h index 22c92374e16..b39ab407dbd 100644 --- a/src/context.h +++ b/src/context.h @@ -66,7 +66,7 @@ class RefCountedContext m_className=className; m_insideRelease = FALSE; } - virtual ~RefCountedContext() + ~RefCountedContext() { if (!m_insideRelease) abort(); } @@ -152,7 +152,7 @@ class DoxygenContext : public RefCountedContext, public TemplateStructIntf private: DoxygenContext(); - ~DoxygenContext(); + ~DoxygenContext(); class Private; Private *p; }; diff --git a/src/definition.cpp b/src/definition.cpp index 86035360b49..2fb753f13e2 100644 --- a/src/definition.cpp +++ b/src/definition.cpp @@ -1360,7 +1360,7 @@ QCString Definition::qualifiedName() const //printf("end %s::qualifiedName()=%s\n",name().data(),m_impl->qualifiedName.data()); //count--; return m_impl->qualifiedName; -}; +} void Definition::setOuterScope(Definition *d) { diff --git a/src/memberdef.cpp b/src/memberdef.cpp index a5be3782a68..9b181edf5f5 100644 --- a/src/memberdef.cpp +++ b/src/memberdef.cpp @@ -5102,6 +5102,6 @@ bool MemberDef::isFunctionOrSignalSlot() const bool MemberDef::isRelatedOrFriend() const { - return isRelated() || isForeign() || isFriend() && !isFriendToHide(); + return isRelated() || isForeign() || (isFriend() && !isFriendToHide()); } diff --git a/src/template.cpp b/src/template.cpp index 2f9f69cb3a3..ec8554be3bb 100644 --- a/src/template.cpp +++ b/src/template.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "sortdict.h" #include "ftextstream.h" @@ -3465,6 +3466,25 @@ class TemplateNodeCreate : public TemplateNodeCreator delete m_templateExpr; delete m_fileExpr; } + void mkpath(TemplateContextImpl *ci,const QCString &fileName) + { + int i=fileName.find('/'); + QCString outputDir = ci->outputDirectory(); + QDir d(outputDir); + int j=0; + while (i!=-1) // fileName contains path part + { + if (d.exists()) + { + bool ok = d.mkdir(fileName.mid(j,i-j)); + if (!ok) break; + QCString dirName = outputDir+'/'+fileName.left(i); + d = QDir(dirName); + j = i+1; + } + i=fileName.find('/',i+1); + } + } void render(FTextStream &, TemplateContext *c) { TemplateContextImpl* ci = dynamic_cast(c); @@ -3490,6 +3510,7 @@ class TemplateNodeCreate : public TemplateNodeCreator TemplateImpl *createTemplate = ct ? dynamic_cast(ct) : 0; if (createTemplate) { + //mkpath(ci,outputFile); QCString extension=outputFile; int i=extension.findRev('.'); if (i!=-1)