diff options
author | Dimitri van Heesch <doxygen@gmail.com> | 2021-01-06 10:55:56 (GMT) |
---|---|---|
committer | Dimitri van Heesch <doxygen@gmail.com> | 2021-01-22 20:45:18 (GMT) |
commit | 62e58020a6fcbce9c1170b69dfee5d8769f14778 (patch) | |
tree | 3d8aa32c74615ed6d5778fa8dc76922ecc66b842 /src | |
parent | 0aa907761f5f29032b01ea2d8373bbc6c53f5e7c (diff) | |
download | Doxygen-62e58020a6fcbce9c1170b69dfee5d8769f14778.zip Doxygen-62e58020a6fcbce9c1170b69dfee5d8769f14778.tar.gz Doxygen-62e58020a6fcbce9c1170b69dfee5d8769f14778.tar.bz2 |
Refactoring: modernize ClassDef::getTemplateInstances()
Diffstat (limited to 'src')
-rw-r--r-- | src/classdef.cpp | 46 | ||||
-rw-r--r-- | src/classdef.h | 13 | ||||
-rw-r--r-- | src/dotclassgraph.cpp | 22 | ||||
-rw-r--r-- | src/doxygen.cpp | 26 |
4 files changed, 44 insertions, 63 deletions
diff --git a/src/classdef.cpp b/src/classdef.cpp index a04fe0a..8d7b019 100644 --- a/src/classdef.cpp +++ b/src/classdef.cpp @@ -196,7 +196,7 @@ class ClassDefImpl : public DefinitionMixin<ClassDefMutable> virtual bool isBaseClass(const ClassDef *bcd,bool followInstances,int level=0) const; virtual bool isSubClass(ClassDef *bcd,int level=0) const; virtual bool isAccessibleMember(const MemberDef *md) const; - virtual QDict<ClassDef> *getTemplateInstances() const; + virtual const TemplateInstanceList &getTemplateInstances() const; virtual const ClassDef *templateMaster() const; virtual bool isTemplate() const; virtual IncludeInfo *includeInfo() const; @@ -441,7 +441,7 @@ class ClassDefAliasImpl : public DefinitionAliasMixin<ClassDef> { return getCdAlias()->isSubClass(bcd,level); } virtual bool isAccessibleMember(const MemberDef *md) const { return getCdAlias()->isAccessibleMember(md); } - virtual QDict<ClassDef> *getTemplateInstances() const + virtual const TemplateInstanceList &getTemplateInstances() const { return getCdAlias()->getTemplateInstances(); } virtual const ClassDef *templateMaster() const { return getCdAlias()->templateMaster(); } @@ -652,7 +652,7 @@ class ClassDefImpl::IMPL /*! Template instances that exists of this class, the key in the * dictionary is the template argument list. */ - mutable QDict<ClassDef> *templateInstances = 0; + TemplateInstanceList templateInstances; /*! Template instances that exists of this class, as defined by variables. * We do NOT want to document these individually. The key in the @@ -740,7 +740,6 @@ void ClassDefImpl::IMPL::init(const char *defFileName, const char *name, usesIntfClassDict=0; constraintClassDict=0; subGrouping=Config_getBool(SUBGROUPING); - templateInstances = 0; variableInstances = 0; templateMaster =0; templBaseClassNames = 0; @@ -782,7 +781,6 @@ ClassDefImpl::IMPL::~IMPL() delete usesIntfClassDict; delete constraintClassDict; delete incInfo; - delete templateInstances; delete variableInstances; delete templBaseClassNames; } @@ -1209,17 +1207,12 @@ void ClassDefImpl::insertUsedFile(FileDef *fd) { if (fd==0) return; if (m_impl->files.find(fd)==-1) m_impl->files.append(fd); - if (m_impl->templateInstances) + for (const auto &ti : m_impl->templateInstances) { - QDictIterator<ClassDef> qdi(*m_impl->templateInstances); - ClassDef *cd; - for (qdi.toFirst();(cd=qdi.current());++qdi) + ClassDefMutable *cdm = toClassDefMutable(ti.classDef); + if (cdm) { - ClassDefMutable *cdm = toClassDefMutable(cd); - if (cdm) - { - cdm->insertUsedFile(fd); - } + cdm->insertUsedFile(fd); } } } @@ -3215,15 +3208,11 @@ bool ClassDefImpl::hasNonReferenceSuperClass() const if (!found) { // look for template instances that might have non-reference super classes - QDict<ClassDef> *cil = bcd->getTemplateInstances(); - if (cil) + for (const auto &cil : bcd->getTemplateInstances()) { - QDictIterator<ClassDef> tidi(*cil); - for ( ; tidi.current() && !found ; ++tidi) // for each template instance - { - // recurse into the template instance branch - found = found || tidi.current()->hasNonReferenceSuperClass(); - } + // recurse into the template instance branch + found = cil.classDef->hasNonReferenceSuperClass(); + if (found) break; } } else @@ -3939,11 +3928,14 @@ ClassDef *ClassDefImpl::insertTemplateInstance(const QCString &fileName, int startLine, int startColumn, const QCString &templSpec,bool &freshInstance) const { freshInstance = FALSE; - if (m_impl->templateInstances==0) + auto it = std::find_if(m_impl->templateInstances.begin(), + m_impl->templateInstances.end(), + [&templSpec](const auto &ti) { return templSpec==ti.templSpec; }); + ClassDefMutable *templateClass=0; + if (it!=m_impl->templateInstances.end()) { - m_impl->templateInstances = new QDict<ClassDef>(17); + templateClass = toClassDefMutable((*it).classDef); } - ClassDefMutable *templateClass=toClassDefMutable(m_impl->templateInstances->find(templSpec)); if (templateClass==0) { QCString tcname = removeRedundantWhiteSpace(localName()+templSpec); @@ -3965,7 +3957,7 @@ ClassDef *ClassDefImpl::insertTemplateInstance(const QCString &fileName, templateClass->setOuterScope(getOuterScope()); templateClass->setHidden(isHidden()); templateClass->setArtificial(isArtificial()); - m_impl->templateInstances->insert(templSpec,templateClass); + m_impl->templateInstances.push_back(TemplateInstanceDef(templSpec,templateClass)); // also add nested classes for (const auto &innerCd : m_impl->innerClasses) @@ -4638,7 +4630,7 @@ FileDef *ClassDefImpl::getFileDef() const return m_impl->fileDef; } -QDict<ClassDef> *ClassDefImpl::getTemplateInstances() const +const TemplateInstanceList &ClassDefImpl::getTemplateInstances() const { return m_impl->templateInstances; } diff --git a/src/classdef.h b/src/classdef.h index 46e1f7d..e8fe500 100644 --- a/src/classdef.h +++ b/src/classdef.h @@ -86,6 +86,17 @@ struct BaseClassDef using BaseClassList = std::vector<BaseClassDef>; +/** Class that contains information about a template instance relation */ +struct TemplateInstanceDef +{ + TemplateInstanceDef(const QCString &ts,const ClassDef *cd) : templSpec(ts), classDef(cd) {} + QCString templSpec; + const ClassDef *classDef; +}; + +using TemplateInstanceList = std::vector<TemplateInstanceDef>; + + /** A abstract class representing of a compound symbol. * * A compound can be a class, struct, union, interface, service, singleton, @@ -233,7 +244,7 @@ class ClassDef : public Definition /** Returns a sorted dictionary with all template instances found for * this template class. Returns 0 if not a template or no instances. */ - virtual QDict<ClassDef> *getTemplateInstances() const = 0; + virtual const TemplateInstanceList &getTemplateInstances() const = 0; /** Returns the template master of which this class is an instance. * Returns 0 if not applicable. diff --git a/src/dotclassgraph.cpp b/src/dotclassgraph.cpp index 98a82d4..5f9aa3f 100644 --- a/src/dotclassgraph.cpp +++ b/src/dotclassgraph.cpp @@ -300,30 +300,18 @@ void DotClassGraph::buildGraph(const ClassDef *cd,DotNode *n,bool base,int dista const ClassDef *templMaster=cd->templateMaster(); if (templMaster) { - QDictIterator<ClassDef> cli(*templMaster->getTemplateInstances()); - const ClassDef *templInstance; - for (;(templInstance=cli.current());++cli) + for (const auto &ti : templMaster->getTemplateInstances()) + if (ti.classDef==cd) { - if (templInstance==cd) - { - addClass(templMaster,n,EdgeInfo::Orange,cli.currentKey(),0, - 0,TRUE,distance); - } + addClass(templMaster,n,EdgeInfo::Orange,ti.templSpec,0,0,TRUE,distance); } } } else // template relations for super classes { - const QDict<ClassDef> *templInstances = cd->getTemplateInstances(); - if (templInstances) + for (const auto &ti : cd->getTemplateInstances()) { - QDictIterator<ClassDef> cli(*templInstances); - const ClassDef *templInstance; - for (;(templInstance=cli.current());++cli) - { - addClass(templInstance,n,EdgeInfo::Orange,cli.currentKey(),0, - 0,FALSE,distance); - } + addClass(ti.classDef,n,EdgeInfo::Orange,ti.templSpec,0,0,FALSE,distance); } } } diff --git a/src/doxygen.cpp b/src/doxygen.cpp index 27da315..4e3d552 100644 --- a/src/doxygen.cpp +++ b/src/doxygen.cpp @@ -4840,19 +4840,16 @@ static void computeTemplateClassRelations() bName=stripTemplateSpecifiersFromScope(bName); ClassDefMutable *cd=getClassMutable(bName); // strip any anonymous scopes first - QDict<ClassDef> *templInstances = 0; - if (cd && (templInstances=cd->getTemplateInstances())) + if (cd && !cd->getTemplateInstances().empty()) { Debug::print(Debug::Classes,0," Template class %s : \n",qPrint(cd->name())); - QDictIterator<ClassDef> tdi(*templInstances); - ClassDef *itcd; - for (tdi.toFirst();(itcd=tdi.current());++tdi) // for each template instance + for (const auto &ti : cd->getTemplateInstances()) // for each template instance { - ClassDefMutable *tcd=toClassDefMutable(itcd); + ClassDefMutable *tcd=toClassDefMutable(ti.classDef); if (tcd) { Debug::print(Debug::Classes,0," Template instance %s : \n",qPrint(tcd->name())); - QCString templSpec = tdi.currentKey(); + QCString templSpec = ti.templSpec; std::unique_ptr<ArgumentList> templArgs = stringToArgumentList(tcd->getLanguage(),templSpec); for (const BaseInfo &bi : root->extends) { @@ -7631,19 +7628,12 @@ static void createTemplateInstanceMembers() for (const auto &cd : *Doxygen::classLinkedMap) { // that is a template - QDict<ClassDef> *templInstances = cd->getTemplateInstances(); - if (templInstances) + for (const auto &ti : cd->getTemplateInstances()) { - QDictIterator<ClassDef> qdi(*templInstances); - ClassDef *tcd=0; - // for each instance of the template - for (qdi.toFirst();(tcd=qdi.current());++qdi) + ClassDefMutable *tcdm = toClassDefMutable(ti.classDef); + if (tcdm) { - ClassDefMutable *tcdm = toClassDefMutable(tcd); - if (tcdm) - { - tcdm->addMembersToTemplateInstance(cd.get(),cd->templateArguments(),qdi.currentKey()); - } + tcdm->addMembersToTemplateInstance(cd.get(),cd->templateArguments(),ti.templSpec); } } } |