diff options
Diffstat (limited to 'src/dirdef.cpp')
-rw-r--r-- | src/dirdef.cpp | 302 |
1 files changed, 170 insertions, 132 deletions
diff --git a/src/dirdef.cpp b/src/dirdef.cpp index ba792e1..6f23251 100644 --- a/src/dirdef.cpp +++ b/src/dirdef.cpp @@ -1,6 +1,22 @@ -#include "md5.h" +/****************************************************************************** + * + * Copyright (C) 1997-2020 by Dimitri van Heesch. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation under the terms of the GNU General Public License is hereby + * granted. No representations are made about the suitability of this software + * for any purpose. It is provided "as is" without express or implied warranty. + * See the GNU General Public License for more details. + * + * Documents produced by Doxygen are derivative works derived from the + * input used in their production; they are not affected by this license. + * + */ + +#include <algorithm> #include "dirdef.h" +#include "md5.h" #include "filename.h" #include "doxygen.h" #include "util.h" @@ -14,10 +30,12 @@ #include "config.h" #include "docparser.h" #include "definitionimpl.h" +#include "filedef.h" + //---------------------------------------------------------------------- -class DirDefImpl : public DefinitionImpl, public DirDef +class DirDefImpl : public DefinitionMixin<DirDef> { public: DirDefImpl(const char *path); @@ -34,11 +52,11 @@ class DirDefImpl : public DefinitionImpl, public DirDef virtual FileList * getFiles() const { return m_fileList; } virtual void addFile(FileDef *fd); virtual const DirList &subDirs() const { return m_subdirs; } - virtual bool isCluster() const { return m_subdirs.count()>0; } + virtual bool isCluster() const { return m_subdirs.size()>0; } virtual int level() const { return m_level; } virtual DirDef *parent() const { return m_parent; } virtual int dirCount() const { return m_dirCount; } - virtual const QDict<UsedDir> *usedDirs() const { return m_usedDirs; } + virtual const UsedDirLinkedMap &usedDirs() const { return m_usedDirs; } virtual bool isParentOf(const DirDef *dir) const; virtual bool depGraphIsTrivial() const; virtual QCString shortTitle() const; @@ -67,7 +85,7 @@ class DirDefImpl : public DefinitionImpl, public DirDef void endMemberDeclarations(OutputList &ol); static DirDef *createNewDir(const char *path); - static bool matchPath(const QCString &path,QStrList &l); + static bool matchPath(const QCString &path,const StringVector &l); DirList m_subdirs; QCString m_dispName; @@ -77,7 +95,7 @@ class DirDefImpl : public DefinitionImpl, public DirDef int m_dirCount; int m_level; DirDef *m_parent; - QDict<UsedDir> *m_usedDirs; + UsedDirLinkedMap m_usedDirs; }; DirDef *createDirDef(const char *path) @@ -91,7 +109,7 @@ DirDef *createDirDef(const char *path) static int g_dirCount=0; -DirDefImpl::DirDefImpl(const char *path) : DefinitionImpl(path,1,1,path) +DirDefImpl::DirDefImpl(const char *path) : DefinitionMixin(path,1,1,path) { bool fullPathNames = Config_getBool(FULL_PATH_NAMES); // get display name (stripping the paths mentioned in STRIP_FROM_PATH) @@ -103,7 +121,7 @@ DirDefImpl::DirDefImpl(const char *path) : DefinitionImpl(path,1,1,path) m_shortName = m_shortName.left(m_shortName.length()-1); } int pi=m_shortName.findRev('/'); - if (pi!=-1) + if (pi!=-1) { // remove everything till the last / m_shortName = m_shortName.mid(pi+1); } @@ -113,10 +131,8 @@ DirDefImpl::DirDefImpl(const char *path) : DefinitionImpl(path,1,1,path) { // strip trailing / m_dispName = m_dispName.left(m_dispName.length()-1); } - + m_fileList = new FileList; - m_usedDirs = new QDict<UsedDir>(257); - m_usedDirs->setAutoDelete(TRUE); m_dirCount = g_dirCount++; m_level=-1; m_parent=0; @@ -125,22 +141,21 @@ DirDefImpl::DirDefImpl(const char *path) : DefinitionImpl(path,1,1,path) DirDefImpl::~DirDefImpl() { delete m_fileList; - delete m_usedDirs; } -bool DirDefImpl::isLinkableInProject() const -{ - return !isReference(); +bool DirDefImpl::isLinkableInProject() const +{ + return !isReference(); } -bool DirDefImpl::isLinkable() const -{ - return isReference() || isLinkableInProject(); +bool DirDefImpl::isLinkable() const +{ + return isReference() || isLinkableInProject(); } void DirDefImpl::addSubDir(DirDef *subdir) { - m_subdirs.append(subdir); + m_subdirs.push_back(subdir); subdir->setOuterScope(this); subdir->setParent(this); } @@ -158,7 +173,7 @@ void DirDefImpl::addFile(FileDef *fd) void DirDefImpl::sort() { - m_subdirs.sort(); + std::sort(m_subdirs.begin(), m_subdirs.end(), compareDirDefs); m_fileList->sort(); } @@ -203,7 +218,7 @@ QCString DirDefImpl::getOutputFileBase() const void DirDefImpl::writeDetailedDescription(OutputList &ol,const QCString &title) { - if ((!briefDescription().isEmpty() && Config_getBool(REPEAT_BRIEF)) || + if ((!briefDescription().isEmpty() && Config_getBool(REPEAT_BRIEF)) || !documentation().isEmpty()) { ol.pushGeneratorState(); @@ -221,10 +236,11 @@ void DirDefImpl::writeDetailedDescription(OutputList &ol,const QCString &title) // repeat brief description if (!briefDescription().isEmpty() && Config_getBool(REPEAT_BRIEF)) { - ol.generateDoc(briefFile(),briefLine(),this,0,briefDescription(),FALSE,FALSE); + ol.generateDoc(briefFile(),briefLine(),this,0,briefDescription(),FALSE,FALSE, + 0,FALSE,FALSE,Config_getBool(MARKDOWN_SUPPORT)); } // separator between brief and details - if (!briefDescription().isEmpty() && Config_getBool(REPEAT_BRIEF) && + if (!briefDescription().isEmpty() && Config_getBool(REPEAT_BRIEF) && !documentation().isEmpty()) { ol.pushGeneratorState(); @@ -241,7 +257,8 @@ void DirDefImpl::writeDetailedDescription(OutputList &ol,const QCString &title) // write documentation if (!documentation().isEmpty()) { - ol.generateDoc(docFile(),docLine(),this,0,documentation()+"\n",TRUE,FALSE); + ol.generateDoc(docFile(),docLine(),this,0,documentation()+"\n",TRUE,FALSE, + 0,FALSE,FALSE,Config_getBool(MARKDOWN_SUPPORT)); } } } @@ -251,7 +268,8 @@ void DirDefImpl::writeBriefDescription(OutputList &ol) if (hasBriefDescription()) { DocRoot *rootNode = validatingParseDoc( - briefFile(),briefLine(),this,0,briefDescription(),TRUE,FALSE); + briefFile(),briefLine(),this,0,briefDescription(),TRUE,FALSE, + 0,FALSE,FALSE,Config_getBool(MARKDOWN_SUPPORT)); if (rootNode && !rootNode->isEmpty()) { ol.startParagraph(); @@ -306,9 +324,7 @@ void DirDefImpl::writeDirectoryGraph(OutputList &ol) void DirDefImpl::writeSubDirList(OutputList &ol) { int numSubdirs = 0; - QListIterator<DirDef> it(m_subdirs); - DirDef *dd; - for (it.toFirst();(dd=it.current());++it) + for(const auto dd : m_subdirs) { if (dd->hasDocumentation() || dd->getFiles()->count()>0) { @@ -323,7 +339,7 @@ void DirDefImpl::writeSubDirList(OutputList &ol) ol.parseText(theTranslator->trDir(TRUE,FALSE)); ol.endMemberHeader(); ol.startMemberList(); - for (it.toFirst();(dd=it.current());++it) + for(const auto dd : m_subdirs) { if (dd->hasDocumentation() || dd->getFiles()->count()==0) { @@ -341,7 +357,8 @@ void DirDefImpl::writeSubDirList(OutputList &ol) FALSE, // isExample 0, // exampleName TRUE, // single line - TRUE // link from index + TRUE, // link from index + Config_getBool(MARKDOWN_SUPPORT) ); ol.endMemberDescription(); } @@ -373,9 +390,7 @@ void DirDefImpl::writeFileList(OutputList &ol) ol.parseText(theTranslator->trFile(TRUE,FALSE)); ol.endMemberHeader(); ol.startMemberList(); - QListIterator<FileDef> it(*m_fileList); - FileDef *fd; - for (;(fd=it.current());++it) + for (it.toFirst();(fd=it.current());++it) { if (fd->hasDocumentation()) { @@ -414,7 +429,8 @@ void DirDefImpl::writeFileList(OutputList &ol) FALSE, // isExample 0, // exampleName TRUE, // single line - TRUE // link from index + TRUE, // link from index + Config_getBool(MARKDOWN_SUPPORT) ); ol.endMemberDescription(); } @@ -461,11 +477,9 @@ void DirDefImpl::writeTagFile(FTextStream &tagFile) { case LayoutDocEntry::DirSubDirs: { - if (m_subdirs.count()>0) + if (m_subdirs.size()>0) { - DirDef *dd; - QListIterator<DirDef> it(m_subdirs); - for (;(dd=it.current());++it) + for(const auto dd : m_subdirs) { tagFile << " <dir>" << convertToXML(dd->displayName()) << "</dir>" << endl; } @@ -497,7 +511,7 @@ void DirDefImpl::writeDocumentation(OutputList &ol) { static bool generateTreeView = Config_getBool(GENERATE_TREEVIEW); ol.pushGeneratorState(); - + QCString title=theTranslator->trDirReference(m_dispName); startFile(ol,getOutputFileBase(),name(),title,HLI_Files,!generateTreeView); @@ -529,25 +543,25 @@ void DirDefImpl::writeDocumentation(OutputList &ol) { switch (lde->kind()) { - case LayoutDocEntry::BriefDesc: + case LayoutDocEntry::BriefDesc: writeBriefDescription(ol); - break; - case LayoutDocEntry::DirGraph: + break; + case LayoutDocEntry::DirGraph: writeDirectoryGraph(ol); - break; - case LayoutDocEntry::MemberDeclStart: + break; + case LayoutDocEntry::MemberDeclStart: startMemberDeclarations(ol); - break; - case LayoutDocEntry::DirSubDirs: + break; + case LayoutDocEntry::DirSubDirs: writeSubDirList(ol); - break; - case LayoutDocEntry::DirFiles: + break; + case LayoutDocEntry::DirFiles: writeFileList(ol); - break; - case LayoutDocEntry::MemberDeclEnd: + break; + case LayoutDocEntry::MemberDeclEnd: endMemberDeclarations(ol); break; - case LayoutDocEntry::DetailedDesc: + case LayoutDocEntry::DetailedDesc: { LayoutDocEntrySection *ls = (LayoutDocEntrySection*)lde; writeDetailedDescription(ol,ls->title(lang)); @@ -575,16 +589,16 @@ void DirDefImpl::writeDocumentation(OutputList &ol) case LayoutDocEntry::FileConstantGroups: case LayoutDocEntry::FileIncludes: case LayoutDocEntry::FileIncludeGraph: - case LayoutDocEntry::FileIncludedByGraph: + case LayoutDocEntry::FileIncludedByGraph: case LayoutDocEntry::FileSourceLink: case LayoutDocEntry::FileInlineClasses: - case LayoutDocEntry::GroupClasses: - case LayoutDocEntry::GroupInlineClasses: + case LayoutDocEntry::GroupClasses: + case LayoutDocEntry::GroupInlineClasses: case LayoutDocEntry::GroupNamespaces: - case LayoutDocEntry::GroupDirs: - case LayoutDocEntry::GroupNestedGroups: + case LayoutDocEntry::GroupDirs: + case LayoutDocEntry::GroupNestedGroups: case LayoutDocEntry::GroupFiles: - case LayoutDocEntry::GroupGraph: + case LayoutDocEntry::GroupGraph: case LayoutDocEntry::GroupPageDocs: case LayoutDocEntry::AuthorSection: case LayoutDocEntry::MemberGroups: @@ -626,7 +640,7 @@ void DirDefImpl::setLevel() /** Add as "uses" dependency between \a this dir and \a dir, * that was caused by a dependency on file \a fd. - */ + */ void DirDefImpl::addUsesDependency(DirDef *dir,FileDef *srcFd, FileDef *dstFd,bool inherited) { @@ -640,15 +654,15 @@ void DirDefImpl::addUsesDependency(DirDef *dir,FileDef *srcFd, // levels match => add direct dependency bool added=FALSE; - UsedDir *usedDir = m_usedDirs->find(dir->getOutputFileBase()); + UsedDir *usedDir = m_usedDirs.find(dir->getOutputFileBase()); if (usedDir) // dir dependency already present { - FilePair *usedPair = usedDir->findFilePair( + const FilePair *usedPair = usedDir->findFilePair( srcFd->getOutputFileBase()+dstFd->getOutputFileBase()); if (usedPair==0) // new file dependency { //printf(" => new file\n"); - usedDir->addFileDep(srcFd,dstFd); + usedDir->addFileDep(srcFd,dstFd); added=TRUE; } else @@ -659,9 +673,9 @@ void DirDefImpl::addUsesDependency(DirDef *dir,FileDef *srcFd, else // new directory dependency { //printf(" => new file\n"); - usedDir = new UsedDir(dir,inherited); - usedDir->addFileDep(srcFd,dstFd); - m_usedDirs->insert(dir->getOutputFileBase(),usedDir); + auto newUsedDir = std::make_unique<UsedDir>(dir,inherited); + newUsedDir->addFileDep(srcFd,dstFd); + usedDir = m_usedDirs.add(dir->getOutputFileBase(),std::move(newUsedDir)); added=TRUE; } if (added) @@ -684,7 +698,7 @@ void DirDefImpl::addUsesDependency(DirDef *dir,FileDef *srcFd, void DirDefImpl::computeDependencies() { FileList *fl = m_fileList; - if (fl) + if (fl) { QListIterator<FileDef> fli(*fl); FileDef *fd; @@ -695,7 +709,7 @@ void DirDefImpl::computeDependencies() QList<IncludeInfo> *ifl = fd->includeFileList(); if (ifl) { - QListIterator<IncludeInfo> ifli(*ifl); + QListIterator<IncludeInfo> ifli(*ifl); IncludeInfo *ii; for (ifli.toFirst();(ii=ifli.current());++ifli) // foreach include file { @@ -716,30 +730,30 @@ void DirDefImpl::computeDependencies() } } } - if (m_usedDirs) + + std::sort(m_usedDirs.begin(),m_usedDirs.end(), + [](const auto &u1,const auto &u2) + { return qstricmp(u1->dir()->getOutputFileBase(),u2->dir()->getOutputFileBase())<0; }); + + for (const auto& usedDirectory : m_usedDirs) { - QDictIterator<UsedDir> udi(*m_usedDirs); - UsedDir *udir; - for (udi.toFirst();(udir=udi.current());++udi) - { - udir->sort(); - } + usedDirectory->sort(); } } bool DirDefImpl::isParentOf(const DirDef *dir) const { - if (dir->parent()==this) // this is a parent of dir + if (dir->parent()==this) // this is a parent of dir return TRUE; else if (dir->parent()) // repeat for the parent of dir - return isParentOf(dir->parent()); + return isParentOf(dir->parent()); else return FALSE; } bool DirDefImpl::depGraphIsTrivial() const { - return m_usedDirs->count()==0; + return m_usedDirs.empty(); } //---------------------------------------------------------------------- @@ -754,7 +768,7 @@ int FilePairDict::compareValues(const FilePair *left,const FilePair *right) cons //---------------------------------------------------------------------- -UsedDir::UsedDir(DirDef *dir,bool inherited) : +UsedDir::UsedDir(const DirDef *dir,bool inherited) : m_dir(dir), m_filePairs(7), m_inherited(inherited) { m_filePairs.setAutoDelete(TRUE); @@ -785,28 +799,27 @@ FilePair *UsedDir::findFilePair(const char *name) DirDef *DirDefImpl::createNewDir(const char *path) { ASSERT(path!=0); - DirDef *dir = Doxygen::directories->find(path); + DirDef *dir = Doxygen::dirLinkedMap->find(path); if (dir==0) // new dir { + dir = Doxygen::dirLinkedMap->add(path, + std::unique_ptr<DirDef>( + createDirDef(path))); //printf("Adding new dir %s\n",path); - dir = createDirDef(path); //printf("createNewDir %s short=%s\n",path,dir->shortName().data()); - Doxygen::directories->append(path,dir); } return dir; } -bool DirDefImpl::matchPath(const QCString &path,QStrList &l) +bool DirDefImpl::matchPath(const QCString &path,const StringVector &l) { - const char *s=l.first(); - while (s) + for (const auto &s : l) { - QCString prefix = s; - if (qstricmp(prefix.left(path.length()),path)==0) // case insensitive compare + std::string prefix = s.substr(0,path.length()); + if (qstricmp(prefix.c_str(),path)==0) // case insensitive compare { return TRUE; } - s = l.next(); } return FALSE; } @@ -824,7 +837,7 @@ DirDef *DirDefImpl::mergeDirectoryInTree(const QCString &path) QCString part=path.left(i+1); if (!matchPath(part,Config_getList(STRIP_FROM_PATH)) && (part!="/" && part!="//")) { - dir=createNewDir(part); + dir=createNewDir(part); } p=i+1; } @@ -835,7 +848,7 @@ DirDef *DirDefImpl::mergeDirectoryInTree(const QCString &path) static void writePartialDirPath(OutputList &ol,const DirDef *root,const DirDef *target) { - if (target->parent()!=root) + if (target->parent()!=root) { writePartialDirPath(ol,root,target->parent()); ol.writeString(" / "); @@ -912,7 +925,7 @@ void DirRelation::writeDocumentation(OutputList &ol) ol.writeString("</table>"); ol.endContents(); - + endFileWithNavPath(m_src,ol); ol.popGeneratorState(); @@ -927,18 +940,15 @@ void DirRelation::writeDocumentation(OutputList &ol) static void computeCommonDirPrefix() { QCString path; - DirDef *dir; - DirSDict::Iterator sdi(*Doxygen::directories); - if (Doxygen::directories->count()>0) // we have at least one dir + auto it = Doxygen::dirLinkedMap->begin(); + if (!Doxygen::dirLinkedMap->empty()) // we have at least one dir { // start will full path of first dir - sdi.toFirst(); - dir=sdi.current(); - path=dir->name(); - int i=path.findRev('/',path.length()-2); + path=(*it)->name(); + int i=path.findRev('/',(int)path.length()-2); path=path.left(i+1); bool done=FALSE; - if (i==-1) + if (i==-1) { path=""; } @@ -946,16 +956,16 @@ static void computeCommonDirPrefix() { while (!done) { - int l = path.length(); - int count=0; - for (sdi.toFirst();(dir=sdi.current());++sdi) + uint l = path.length(); + size_t count=0; + for (const auto &dir : *Doxygen::dirLinkedMap) { QCString dirName = dir->name(); if (dirName.length()>path.length()) { if (qstrncmp(dirName,path,l)!=0) // dirName does not start with path { - int i=path.findRev('/',l-2); + i=path.findRev('/',(int)l-2); if (i==-1) // no unique prefix -> stop { path=""; @@ -972,7 +982,7 @@ static void computeCommonDirPrefix() { path=dir->name(); l=path.length(); - int i=path.findRev('/',l-2); + i=path.findRev('/',(int)l-2); if (i==-1) // no unique prefix -> stop { path=""; @@ -986,7 +996,7 @@ static void computeCommonDirPrefix() } count++; } - if (count==Doxygen::directories->count()) + if (count==Doxygen::dirLinkedMap->size()) // path matches for all directories -> found the common prefix { done=TRUE; @@ -994,7 +1004,7 @@ static void computeCommonDirPrefix() } } } - for (sdi.toFirst();(dir=sdi.current());++sdi) + for (const auto &dir : *Doxygen::dirLinkedMap) { QCString diskName = dir->name().right(dir->name().length()-path.length()); dir->setDiskName(diskName); @@ -1005,23 +1015,19 @@ static void computeCommonDirPrefix() void buildDirectories() { // for each input file - FileNameListIterator fnli(*Doxygen::inputNameList); - FileName *fn; - for (fnli.toFirst();(fn=fnli.current());++fnli) + for (const auto &fn : *Doxygen::inputNameLinkedMap) { - FileNameIterator fni(*fn); - FileDef *fd; - for (;(fd=fni.current());++fni) + for (const auto &fd : *fn) { //printf("buildDirectories %s\n",fd->name().data()); if (fd->getReference().isEmpty()) { DirDef *dir; - if ((dir=Doxygen::directories->find(fd->getPath()))==0) // new directory + if ((dir=Doxygen::dirLinkedMap->find(fd->getPath()))==0) // new directory { dir = DirDefImpl::mergeDirectoryInTree(fd->getPath()); } - if (dir && !fd->isDocumentationFile()) dir->addFile(fd); + if (dir && !fd->isDocumentationFile()) dir->addFile(fd.get()); } else { @@ -1030,45 +1036,48 @@ void buildDirectories() } } - //DirDef *root = new DirDef("root:"); // compute relations between directories => introduce container dirs. - DirDef *dir; - DirSDict::Iterator sdi(*Doxygen::directories); - for (sdi.toFirst();(dir=sdi.current());++sdi) + for (const auto &dir : *Doxygen::dirLinkedMap) { QCString name = dir->name(); - int i=name.findRev('/',name.length()-2); + int i=name.findRev('/',(int)name.length()-2); if (i>0) { - DirDef *parent = Doxygen::directories->find(name.left(i+1)); + DirDef *parent = Doxygen::dirLinkedMap->find(name.left(i+1)); //if (parent==0) parent=root; - if (parent) + if (parent) { - parent->addSubDir(dir); + parent->addSubDir(dir.get()); //printf("DirDefImpl::addSubdir(): Adding subdir\n%s to\n%s\n", // dir->displayName().data(), parent->displayName().data()); } } } - for (sdi.toFirst();(dir=sdi.current());++sdi) + + // sort the directory contents + for (const auto &dir : *Doxygen::dirLinkedMap) { dir->sort(); } - Doxygen::directories->sort(); + + // short the directories themselves + std::sort(Doxygen::dirLinkedMap->begin(), + Doxygen::dirLinkedMap->end(), + [](const auto &d1,const auto &d2) + { return qstricmp(d1->shortName(),d2->shortName()) < 0; }); + computeCommonDirPrefix(); } void computeDirDependencies() { - DirDef *dir; - DirSDict::Iterator sdi(*Doxygen::directories); // compute nesting level for each directory - for (sdi.toFirst();(dir=sdi.current());++sdi) + for (const auto &dir : *Doxygen::dirLinkedMap) { dir->setLevel(); } // compute uses dependencies between directories - for (sdi.toFirst();(dir=sdi.current());++sdi) + for (const auto &dir : *Doxygen::dirLinkedMap) { //printf("computeDependencies for %s: #dirs=%d\n",dir->name().data(),Doxygen::directories.count()); dir->computeDependencies(); @@ -1078,9 +1087,7 @@ void computeDirDependencies() void generateDirDocs(OutputList &ol) { - DirDef *dir; - DirSDict::Iterator sdi(*Doxygen::directories); - for (sdi.toFirst();(dir=sdi.current());++sdi) + for (const auto &dir : *Doxygen::dirLinkedMap) { ol.pushGeneratorState(); if (!dir->hasDocumentation()) @@ -1092,12 +1099,43 @@ void generateDirDocs(OutputList &ol) } if (Config_getBool(DIRECTORY_GRAPH)) { - SDict<DirRelation>::Iterator rdi(Doxygen::dirRelations); - DirRelation *dr; - for (rdi.toFirst();(dr=rdi.current());++rdi) + for (const auto &dr : Doxygen::dirRelations) { dr->writeDocumentation(ol); } } } +bool compareDirDefs(const DirDef *item1, const DirDef *item2) +{ + return qstricmp(item1->shortName(),item2->shortName()) < 0; +} + +// --- Cast functions + +DirDef *toDirDef(Definition *d) +{ + if (d==0) return 0; + if (d && typeid(*d)==typeid(DirDefImpl)) + { + return static_cast<DirDef*>(d); + } + else + { + return 0; + } +} + +const DirDef *toDirDef(const Definition *d) +{ + if (d==0) return 0; + if (d && typeid(*d)==typeid(DirDefImpl)) + { + return static_cast<const DirDef*>(d); + } + else + { + return 0; + } +} + |