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 1119 of file dirdef.cpp.

1120{
1121 AUTO_TRACE();
1122 // for each input file
1123 for (const auto &fn : *Doxygen::inputNameLinkedMap)
1124 {
1125 for (const auto &fd : *fn)
1126 {
1127 if (fd->getReference().isEmpty())
1128 {
1129 DirDef *dir=Doxygen::dirLinkedMap->find(fd->getPath());
1130 if (dir==nullptr) // new directory
1131 {
1132 dir = DirDefImpl::mergeDirectoryInTree(fd->getPath());
1133 }
1134 if (dir && !fd->isDocumentationFile()) dir->addFile(fd.get());
1135 }
1136 else
1137 {
1138 // do something for file imported via tag files.
1139 }
1140 }
1141 }
1142
1143 // compute relations between directories => introduce container dirs.
1144 for (const auto &dir : *Doxygen::dirLinkedMap)
1145 {
1146 QCString name = dir->name();
1147 int i=name.findRev('/',static_cast<int>(name.length())-2);
1148 if (i>0)
1149 {
1150 DirDef *parent = Doxygen::dirLinkedMap->find(name.left(i+1));
1151 //if (parent==0) parent=root;
1152 if (parent)
1153 {
1154 parent->addSubDir(dir.get());
1155 AUTO_TRACE_ADD("DirDefImpl::addSubdir(): Adding subdir {} to {}",
1156 dir->displayName(), parent->displayName());
1157 }
1158 }
1159 }
1160
1161 // sort the directory contents
1162 for (const auto &dir : *Doxygen::dirLinkedMap)
1163 {
1164 dir->sort();
1165 }
1166
1167 // short the directories themselves
1168 std::stable_sort(Doxygen::dirLinkedMap->begin(),
1170 [](const auto &d1,const auto &d2)
1171 {
1172 QCString s1 = d1->shortName(), s2 = d2->shortName();
1173 int i = qstricmp_sort(s1,s2);
1174 if (i==0) // if sort name are equal, sort on full path
1175 {
1176 QCString n1 = d1->name(), n2 = d2->name();
1177 int n = qstricmp_sort(n1,n2);
1178 return n < 0;
1179 }
1180 return i < 0;
1181 });
1182
1183 // set the directory index identifier
1184 int dirIndex=0;
1185 for (const auto &dir : *Doxygen::dirLinkedMap)
1186 {
1187 dir->setDirIndex(dirIndex++);
1188 }
1189
1191}
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:918
static FileNameLinkedMap * inputNameLinkedMap
Definition doxygen.h:104
static DirLinkedMap * dirLinkedMap
Definition doxygen.h:128
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:166
int findRev(char c, int index=-1, bool cs=TRUE) const
Definition qcstring.cpp:96
QCString left(size_t len) const
Definition qcstring.h:229
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:1042
#define AUTO_TRACE_ADD(...)
Definition docnode.cpp:48
#define AUTO_TRACE(...)
Definition docnode.cpp:47
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:1328
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 1232 of file dirdef.cpp.

1233{
1234 return qstricmp_sort(item1->shortName(),item2->shortName()) < 0;
1235}
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 1042 of file dirdef.cpp.

1043{
1044 AUTO_TRACE();
1045 QCString path;
1046 auto it = Doxygen::dirLinkedMap->begin();
1047 if (!Doxygen::dirLinkedMap->empty()) // we have at least one dir
1048 {
1049 // start will full path of first dir
1050 path=removeLongPathMarker((*it)->name());
1051 int i=path.findRev('/',static_cast<int>(path.length())-2);
1052 path=path.left(i+1);
1053 bool done=FALSE;
1054 if (i==-1)
1055 {
1056 path="";
1057 }
1058 else
1059 {
1060 while (!done)
1061 {
1062 int l = static_cast<int>(path.length());
1063 size_t count=0;
1064 for (const auto &dir : *Doxygen::dirLinkedMap)
1065 {
1066 QCString dirName = removeLongPathMarker(dir->name());
1067 //printf("dirName='%s' (l=%d) path='%s' (l=%d)\n",qPrint(dirName),dirName.length(),qPrint(path),path.length());
1068 if (dirName.length()>path.length())
1069 {
1070 if (dirName.left(l)!=path) // dirName does not start with path
1071 {
1072 i = l>=2 ? path.findRev('/',l-2) : -1;
1073 if (i==-1) // no unique prefix -> stop
1074 {
1075 path="";
1076 done=TRUE;
1077 }
1078 else // restart with shorter path
1079 {
1080 path=path.left(i+1);
1081 break;
1082 }
1083 }
1084 }
1085 else // dir is shorter than path -> take path of dir as new start
1086 {
1087 path=dir->name();
1088 l=static_cast<int>(path.length());
1089 i=path.findRev('/',l-2);
1090 if (i==-1) // no unique prefix -> stop
1091 {
1092 path="";
1093 done=TRUE;
1094 }
1095 else // restart with shorter path
1096 {
1097 path=path.left(i+1);
1098 }
1099 break;
1100 }
1101 count++;
1102 }
1103 if (count==Doxygen::dirLinkedMap->size())
1104 // path matches for all directories -> found the common prefix
1105 {
1106 done=TRUE;
1107 }
1108 }
1109 }
1110 }
1111 for (const auto &dir : *Doxygen::dirLinkedMap)
1112 {
1113 QCString diskName = dir->name().right(dir->name().length()-path.length());
1114 dir->setDiskName(diskName);
1115 AUTO_TRACE_ADD("set disk name: {} -> {}",dir->name(),diskName);
1116 }
1117}
QCString right(size_t len) const
Definition qcstring.h:234
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34
QCString removeLongPathMarker(QCString path)
Definition util.cpp:288

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 1193 of file dirdef.cpp.

1194{
1195 AUTO_TRACE();
1196 // compute nesting level for each directory
1197 for (const auto &dir : *Doxygen::dirLinkedMap)
1198 {
1199 dir->setLevel();
1200 }
1201
1202 // compute uses dependencies between directories
1203 for (const auto &dir : *Doxygen::dirLinkedMap)
1204 {
1205 AUTO_TRACE_ADD("computeDependencies for {}: #dirs={}",dir->name(),Doxygen::dirLinkedMap->size());
1206 dir->computeDependencies();
1207 }
1208}

References AUTO_TRACE, AUTO_TRACE_ADD, and Doxygen::dirLinkedMap.

Referenced by parseInput().

◆ createDirDef()

DirDef * createDirDef ( const QCString & path)

Definition at line 111 of file dirdef.cpp.

112{
113 return new DirDefImpl(path);
114}

Referenced by DirDefImpl::createNewDir().

◆ encodeDirName()

QCString encodeDirName ( const QCString & anchor)
static

Definition at line 192 of file dirdef.cpp.

193{
194 AUTO_TRACE();
195 // convert to md5 hash
196 uint8_t md5_sig[16];
197 char sigStr[33];
198 MD5Buffer(anchor.data(),static_cast<unsigned int>(anchor.length()),md5_sig);
199 MD5SigToString(md5_sig,sigStr);
200 AUTO_TRACE_EXIT("result={}",sigStr);
201 return sigStr;
202
203 // old algorithm
204// QCString result;
205
206// int l = anchor.length(),i;
207// for (i=0;i<l;i++)
208// {
209// char c = anchor.at(i);
210// if ((c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9'))
211// {
212// result+=c;
213// }
214// else
215// {
216// static char hexStr[]="0123456789ABCDEF";
217// char escChar[]={ '_', 0, 0, 0 };
218// escChar[1]=hexStr[c>>4];
219// escChar[2]=hexStr[c&0xf];
220// result+=escChar;
221// }
222// }
223// return result;
224}
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:172
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:49

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

Referenced by DirDefImpl::getOutputFileBase().

◆ generateDirDocs()

void generateDirDocs ( OutputList & ol)

Definition at line 1210 of file dirdef.cpp.

1211{
1212 AUTO_TRACE();
1213 for (const auto &dir : *Doxygen::dirLinkedMap)
1214 {
1215 ol.pushGeneratorState();
1216 if (!dir->hasDocumentation())
1217 {
1219 }
1220 dir->writeDocumentation(ol);
1221 ol.popGeneratorState();
1222 }
1223 //if (Config_getBool(DIRECTORY_GRAPH))
1224 {
1225 for (const auto &dr : Doxygen::dirRelations)
1226 {
1227 dr->writeDocumentation(ol);
1228 }
1229 }
1230}
static DirRelationLinkedMap dirRelations
Definition doxygen.h:129
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 1252 of file dirdef.cpp.

1253{
1254 if (d==nullptr) return nullptr;
1255 if (d && typeid(*d)==typeid(DirDefImpl))
1256 {
1257 return static_cast<const DirDef*>(d);
1258 }
1259 else
1260 {
1261 return nullptr;
1262 }
1263}

◆ toDirDef() [2/2]

DirDef * toDirDef ( Definition * d)

Definition at line 1239 of file dirdef.cpp.

1240{
1241 if (d==nullptr) return nullptr;
1242 if (d && typeid(*d)==typeid(DirDefImpl))
1243 {
1244 return static_cast<DirDef*>(d);
1245 }
1246 else
1247 {
1248 return nullptr;
1249 }
1250}

◆ writePartialDirPath()

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

Definition at line 954 of file dirdef.cpp.

955{
956 if (target->parent()!=root)
957 {
958 writePartialDirPath(ol,root,target->parent());
959 ol.writeString("&#160;/&#160;");
960 }
961 ol.writeObjectLink(target->getReference(),target->getOutputFileBase(),QCString(),target->shortName());
962}
virtual QCString getReference() const =0
virtual QCString getOutputFileBase() const =0
virtual DirDef * parent() const =0
void writeString(const QCString &text)
Definition outputlist.h:411
void writeObjectLink(const QCString &ref, const QCString &file, const QCString &anchor, const QCString &name)
Definition outputlist.h:439
static void writePartialDirPath(OutputList &ol, const DirDef *root, const DirDef *target)
Definition dirdef.cpp:954

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 964 of file dirdef.cpp.

965{
966 if (fd->getDirDef() && fd->getDirDef()!=root)
967 {
968 writePartialDirPath(ol,root,fd->getDirDef());
969 ol.writeString("&#160;/&#160;");
970 }
971 if (fd->isLinkable())
972 {
974 }
975 else
976 {
977 ol.startBold();
978 ol.docify(fd->name());
979 ol.endBold();
980 }
981}
virtual bool isLinkable() const =0
virtual DirDef * getDirDef() const =0
void docify(const QCString &s)
Definition outputlist.h:437
void startBold()
Definition outputlist.h:561
void endBold()
Definition outputlist.h:563

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().