Doxygen
Loading...
Searching...
No Matches
dirdef.cpp File Reference
#include <algorithm>
#include "dirdef.h"
#include "md5.h"
#include "filename.h"
#include "doxygen.h"
#include "util.h"
#include "outputlist.h"
#include "language.h"
#include "message.h"
#include "dot.h"
#include "dotdirdeps.h"
#include "layout.h"
#include "config.h"
#include "docparser.h"
#include "definitionimpl.h"
#include "filedef.h"
#include "trace.h"
Include dependency graph for dirdef.cpp:

Go to the source code of this file.

Classes

class  DirDefImpl

Functions

DirDefcreateDirDef (const QCString &path)
static QCString encodeDirName (const QCString &anchor)
static void writePartialDirPath (OutputList &ol, const DirDef *root, const DirDef *target)
static void writePartialFilePath (OutputList &ol, const DirDef *root, const FileDef *fd)
static void computeCommonDirPrefix ()
 In order to create stable, but unique directory names, we compute the common part of the path shared by all directories.
void buildDirectories ()
void computeDirDependencies ()
void generateDirDocs (OutputList &ol)
bool compareDirDefs (const DirDef *item1, const DirDef *item2)
DirDeftoDirDef (Definition *d)
const DirDeftoDirDef (const Definition *d)

Function Documentation

◆ buildDirectories()

void buildDirectories ( )

Definition at line 1070 of file dirdef.cpp.

1071{
1072 AUTO_TRACE();
1073 // for each input file
1074 for (const auto &fn : *Doxygen::inputNameLinkedMap)
1075 {
1076 for (const auto &fd : *fn)
1077 {
1078 if (fd->getReference().isEmpty())
1079 {
1080 DirDef *dir=Doxygen::dirLinkedMap->find(fd->getPath());
1081 if (dir==nullptr) // new directory
1082 {
1083 dir = DirDefImpl::mergeDirectoryInTree(fd->getPath());
1084 }
1085 if (dir && !fd->isDocumentationFile()) dir->addFile(fd.get());
1086 }
1087 else
1088 {
1089 // do something for file imported via tag files.
1090 }
1091 }
1092 }
1093
1094 // compute relations between directories => introduce container dirs.
1095 for (const auto &dir : *Doxygen::dirLinkedMap)
1096 {
1097 QCString name = dir->name();
1098 int i=name.findRev('/',static_cast<int>(name.length())-2);
1099 if (i>0)
1100 {
1101 DirDef *parent = Doxygen::dirLinkedMap->find(name.left(i+1));
1102 //if (parent==0) parent=root;
1103 if (parent)
1104 {
1105 parent->addSubDir(dir.get());
1106 AUTO_TRACE_ADD("DirDefImpl::addSubdir(): Adding subdir {} to {}",
1107 dir->displayName(), parent->displayName());
1108 }
1109 }
1110 }
1111
1112 // sort the directory contents
1113 for (const auto &dir : *Doxygen::dirLinkedMap)
1114 {
1115 dir->sort();
1116 }
1117
1118 // short the directories themselves
1119 std::stable_sort(Doxygen::dirLinkedMap->begin(),
1121 [](const auto &d1,const auto &d2)
1122 {
1123 QCString s1 = d1->shortName(), s2 = d2->shortName();
1124 int i = qstricmp_sort(s1,s2);
1125 if (i==0) // if sort name are equal, sort on full path
1126 {
1127 QCString n1 = d1->name(), n2 = d2->name();
1128 int n = qstricmp_sort(n1,n2);
1129 return n < 0;
1130 }
1131 return i < 0;
1132 });
1133
1134 // set the directory index identifier
1135 int dirIndex=0;
1136 for (const auto &dir : *Doxygen::dirLinkedMap)
1137 {
1138 dir->setDirIndex(dirIndex++);
1139 }
1140
1142}
virtual QCString displayName(bool includeScope=TRUE) const =0
virtual const QCString & name() const =0
A model of a directory symbol.
Definition dirdef.h:110
virtual void sort()=0
virtual void addFile(FileDef *fd)=0
virtual void setDirIndex(int index)=0
static DirDef * mergeDirectoryInTree(const QCString &path)
Definition dirdef.cpp:869
static FileNameLinkedMap * inputNameLinkedMap
Definition doxygen.h:105
static DirLinkedMap * dirLinkedMap
Definition doxygen.h:129
This is an alternative implementation of QCString.
Definition qcstring.h:101
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:153
int findRev(char c, int index=-1, bool cs=TRUE) const
Definition qcstring.cpp:91
QCString left(size_t len) const
Definition qcstring.h:214
DirIterator begin(DirIterator it) noexcept
Definition dir.cpp:170
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:175
static void computeCommonDirPrefix()
In order to create stable, but unique directory names, we compute the common part of the path shared ...
Definition dirdef.cpp:993
#define AUTO_TRACE_ADD(...)
Definition docnode.cpp:47
#define AUTO_TRACE(...)
Definition docnode.cpp:46
constexpr DocNodeVariant * parent(DocNodeVariant *n)
returns the parent node of a given node n or nullptr if the node has no parent.
Definition docnode.h:1324
int qstricmp_sort(const char *str1, const char *str2)
Definition qcstring.h:86

References DirDef::addFile(), AUTO_TRACE, AUTO_TRACE_ADD, begin(), computeCommonDirPrefix(), Doxygen::dirLinkedMap, end(), QCString::findRev(), Doxygen::inputNameLinkedMap, QCString::left(), QCString::length(), DirDefImpl::mergeDirectoryInTree(), parent(), and qstricmp_sort().

Referenced by parseInput().

◆ compareDirDefs()

bool compareDirDefs ( const DirDef * item1,
const DirDef * item2 )

Definition at line 1183 of file dirdef.cpp.

1184{
1185 return qstricmp_sort(item1->shortName(),item2->shortName()) < 0;
1186}
virtual const QCString shortName() const =0

References qstricmp_sort(), and DirDef::shortName().

Referenced by DirDefImpl::sort(), and GroupDefImpl::sortMemberLists().

◆ computeCommonDirPrefix()

void computeCommonDirPrefix ( )
static

In order to create stable, but unique directory names, we compute the common part of the path shared by all directories.

Definition at line 993 of file dirdef.cpp.

994{
995 AUTO_TRACE();
996 QCString path;
997 auto it = Doxygen::dirLinkedMap->begin();
998 if (!Doxygen::dirLinkedMap->empty()) // we have at least one dir
999 {
1000 // start will full path of first dir
1001 path=removeLongPathMarker((*it)->name());
1002 int i=path.findRev('/',static_cast<int>(path.length())-2);
1003 path=path.left(i+1);
1004 bool done=FALSE;
1005 if (i==-1)
1006 {
1007 path="";
1008 }
1009 else
1010 {
1011 while (!done)
1012 {
1013 int l = static_cast<int>(path.length());
1014 size_t count=0;
1015 for (const auto &dir : *Doxygen::dirLinkedMap)
1016 {
1017 QCString dirName = removeLongPathMarker(dir->name());
1018 //printf("dirName='%s' (l=%d) path='%s' (l=%d)\n",qPrint(dirName),dirName.length(),qPrint(path),path.length());
1019 if (dirName.length()>path.length())
1020 {
1021 if (dirName.left(l)!=path) // dirName does not start with path
1022 {
1023 i = l>=2 ? path.findRev('/',l-2) : -1;
1024 if (i==-1) // no unique prefix -> stop
1025 {
1026 path="";
1027 done=TRUE;
1028 }
1029 else // restart with shorter path
1030 {
1031 path=path.left(i+1);
1032 break;
1033 }
1034 }
1035 }
1036 else // dir is shorter than path -> take path of dir as new start
1037 {
1038 path=dir->name();
1039 l=static_cast<int>(path.length());
1040 i=path.findRev('/',l-2);
1041 if (i==-1) // no unique prefix -> stop
1042 {
1043 path="";
1044 done=TRUE;
1045 }
1046 else // restart with shorter path
1047 {
1048 path=path.left(i+1);
1049 }
1050 break;
1051 }
1052 count++;
1053 }
1054 if (count==Doxygen::dirLinkedMap->size())
1055 // path matches for all directories -> found the common prefix
1056 {
1057 done=TRUE;
1058 }
1059 }
1060 }
1061 }
1062 for (const auto &dir : *Doxygen::dirLinkedMap)
1063 {
1064 QCString diskName = dir->name().right(dir->name().length()-path.length());
1065 dir->setDiskName(diskName);
1066 AUTO_TRACE_ADD("set disk name: {} -> {}",dir->name(),diskName);
1067 }
1068}
QCString right(size_t len) const
Definition qcstring.h:219
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34
QCString removeLongPathMarker(QCString path)
Definition util.cpp:298

References AUTO_TRACE, AUTO_TRACE_ADD, Doxygen::dirLinkedMap, FALSE, QCString::findRev(), QCString::left(), QCString::length(), removeLongPathMarker(), QCString::right(), and TRUE.

Referenced by buildDirectories().

◆ computeDirDependencies()

void computeDirDependencies ( )

Definition at line 1144 of file dirdef.cpp.

1145{
1146 AUTO_TRACE();
1147 // compute nesting level for each directory
1148 for (const auto &dir : *Doxygen::dirLinkedMap)
1149 {
1150 dir->setLevel();
1151 }
1152
1153 // compute uses dependencies between directories
1154 for (const auto &dir : *Doxygen::dirLinkedMap)
1155 {
1156 AUTO_TRACE_ADD("computeDependencies for {}: #dirs={}",dir->name(),Doxygen::dirLinkedMap->size());
1157 dir->computeDependencies();
1158 }
1159}

References AUTO_TRACE, AUTO_TRACE_ADD, and Doxygen::dirLinkedMap.

Referenced by parseInput().

◆ createDirDef()

DirDef * createDirDef ( const QCString & path)

Definition at line 107 of file dirdef.cpp.

108{
109 return new DirDefImpl(path);
110}

Referenced by DirDefImpl::createNewDir().

◆ encodeDirName()

QCString encodeDirName ( const QCString & anchor)
static

Definition at line 188 of file dirdef.cpp.

189{
190 AUTO_TRACE();
191 // convert to md5 hash
192 uint8_t md5_sig[16];
193 char sigStr[33];
194 MD5Buffer(anchor.data(),static_cast<unsigned int>(anchor.length()),md5_sig);
195 MD5SigToString(md5_sig,sigStr);
196 AUTO_TRACE_EXIT("result={}",sigStr);
197 return sigStr;
198
199 // old algorithm
200// QCString result;
201
202// int l = anchor.length(),i;
203// for (i=0;i<l;i++)
204// {
205// char c = anchor.at(i);
206// if ((c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9'))
207// {
208// result+=c;
209// }
210// else
211// {
212// static char hexStr[]="0123456789ABCDEF";
213// char escChar[]={ '_', 0, 0, 0 };
214// escChar[1]=hexStr[c>>4];
215// escChar[2]=hexStr[c&0xf];
216// result+=escChar;
217// }
218// }
219// return result;
220}
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition qcstring.h:159
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:48

References AUTO_TRACE, AUTO_TRACE_EXIT, QCString::data(), and QCString::length().

Referenced by DirDefImpl::getOutputFileBase().

◆ generateDirDocs()

void generateDirDocs ( OutputList & ol)

Definition at line 1161 of file dirdef.cpp.

1162{
1163 AUTO_TRACE();
1164 for (const auto &dir : *Doxygen::dirLinkedMap)
1165 {
1166 ol.pushGeneratorState();
1167 if (!dir->hasDocumentation())
1168 {
1170 }
1171 dir->writeDocumentation(ol);
1172 ol.popGeneratorState();
1173 }
1174 //if (Config_getBool(DIRECTORY_GRAPH))
1175 {
1176 for (const auto &dr : Doxygen::dirRelations)
1177 {
1178 dr->writeDocumentation(ol);
1179 }
1180 }
1181}
static DirRelationLinkedMap dirRelations
Definition doxygen.h:130
void pushGeneratorState()
void disableAllBut(OutputType o)
void popGeneratorState()

References AUTO_TRACE, Doxygen::dirLinkedMap, Doxygen::dirRelations, OutputList::disableAllBut(), Html, OutputList::popGeneratorState(), and OutputList::pushGeneratorState().

Referenced by generateOutput().

◆ toDirDef() [1/2]

const DirDef * toDirDef ( const Definition * d)

Definition at line 1203 of file dirdef.cpp.

1204{
1205 if (d==nullptr) return nullptr;
1206 if (d && typeid(*d)==typeid(DirDefImpl))
1207 {
1208 return static_cast<const DirDef*>(d);
1209 }
1210 else
1211 {
1212 return nullptr;
1213 }
1214}

◆ toDirDef() [2/2]

DirDef * toDirDef ( Definition * d)

Definition at line 1190 of file dirdef.cpp.

1191{
1192 if (d==nullptr) return nullptr;
1193 if (d && typeid(*d)==typeid(DirDefImpl))
1194 {
1195 return static_cast<DirDef*>(d);
1196 }
1197 else
1198 {
1199 return nullptr;
1200 }
1201}

◆ writePartialDirPath()

void writePartialDirPath ( OutputList & ol,
const DirDef * root,
const DirDef * target )
static

Definition at line 905 of file dirdef.cpp.

906{
907 if (target->parent()!=root)
908 {
909 writePartialDirPath(ol,root,target->parent());
910 ol.writeString("&#160;/&#160;");
911 }
912 ol.writeObjectLink(target->getReference(),target->getOutputFileBase(),QCString(),target->shortName());
913}
virtual QCString getReference() const =0
virtual QCString getOutputFileBase() const =0
virtual DirDef * parent() const =0
void writeString(const QCString &text)
Definition outputlist.h:412
void writeObjectLink(const QCString &ref, const QCString &file, const QCString &anchor, const QCString &name)
Definition outputlist.h:440
static void writePartialDirPath(OutputList &ol, const DirDef *root, const DirDef *target)
Definition dirdef.cpp:905

References Definition::getOutputFileBase(), Definition::getReference(), DirDef::parent(), DirDef::shortName(), OutputList::writeObjectLink(), writePartialDirPath(), and OutputList::writeString().

Referenced by writePartialDirPath(), and writePartialFilePath().

◆ writePartialFilePath()

void writePartialFilePath ( OutputList & ol,
const DirDef * root,
const FileDef * fd )
static

Definition at line 915 of file dirdef.cpp.

916{
917 if (fd->getDirDef() && fd->getDirDef()!=root)
918 {
919 writePartialDirPath(ol,root,fd->getDirDef());
920 ol.writeString("&#160;/&#160;");
921 }
922 if (fd->isLinkable())
923 {
925 }
926 else
927 {
928 ol.startBold();
929 ol.docify(fd->name());
930 ol.endBold();
931 }
932}
virtual bool isLinkable() const =0
virtual DirDef * getDirDef() const =0
void docify(const QCString &s)
Definition outputlist.h:438
void startBold()
Definition outputlist.h:562
void endBold()
Definition outputlist.h:564

References OutputList::docify(), OutputList::endBold(), FileDef::getDirDef(), Definition::getOutputFileBase(), Definition::getReference(), Definition::isLinkable(), Definition::name(), OutputList::startBold(), OutputList::writeObjectLink(), writePartialDirPath(), and OutputList::writeString().

Referenced by DirRelation::writeDocumentation().