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

1081{
1082 AUTO_TRACE();
1083 // for each input file
1084 for (const auto &fn : *Doxygen::inputNameLinkedMap)
1085 {
1086 for (const auto &fd : *fn)
1087 {
1088 if (fd->getReference().isEmpty())
1089 {
1090 DirDef *dir=Doxygen::dirLinkedMap->find(fd->getPath());
1091 if (dir==nullptr) // new directory
1092 {
1093 dir = DirDefImpl::mergeDirectoryInTree(fd->getPath());
1094 }
1095 if (dir && !fd->isDocumentationFile()) dir->addFile(fd.get());
1096 }
1097 else
1098 {
1099 // do something for file imported via tag files.
1100 }
1101 }
1102 }
1103
1104 // compute relations between directories => introduce container dirs.
1105 for (const auto &dir : *Doxygen::dirLinkedMap)
1106 {
1107 QCString name = dir->name();
1108 int i=name.findRev('/',static_cast<int>(name.length())-2);
1109 if (i>0)
1110 {
1111 DirDef *parent = Doxygen::dirLinkedMap->find(name.left(i+1));
1112 //if (parent==0) parent=root;
1113 if (parent)
1114 {
1115 parent->addSubDir(dir.get());
1116 AUTO_TRACE_ADD("DirDefImpl::addSubdir(): Adding subdir {} to {}",
1117 dir->displayName(), parent->displayName());
1118 }
1119 }
1120 }
1121
1122 // sort the directory contents
1123 for (const auto &dir : *Doxygen::dirLinkedMap)
1124 {
1125 dir->sort();
1126 }
1127
1128 // short the directories themselves
1129 std::stable_sort(Doxygen::dirLinkedMap->begin(),
1131 [](const auto &d1,const auto &d2)
1132 {
1133 QCString s1 = d1->shortName(), s2 = d2->shortName();
1134 int i = qstricmp_sort(s1,s2);
1135 if (i==0) // if sort name are equal, sort on full path
1136 {
1137 QCString n1 = d1->name(), n2 = d2->name();
1138 int n = qstricmp_sort(n1,n2);
1139 return n < 0;
1140 }
1141 return i < 0;
1142 });
1143
1144 // set the directory index identifier
1145 int dirIndex=0;
1146 for (const auto &dir : *Doxygen::dirLinkedMap)
1147 {
1148 dir->setDirIndex(dirIndex++);
1149 }
1150
1152}
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:879
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:1003
#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:1325
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 1193 of file dirdef.cpp.

1194{
1195 return qstricmp_sort(item1->shortName(),item2->shortName()) < 0;
1196}
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 1003 of file dirdef.cpp.

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

1155{
1156 AUTO_TRACE();
1157 // compute nesting level for each directory
1158 for (const auto &dir : *Doxygen::dirLinkedMap)
1159 {
1160 dir->setLevel();
1161 }
1162
1163 // compute uses dependencies between directories
1164 for (const auto &dir : *Doxygen::dirLinkedMap)
1165 {
1166 AUTO_TRACE_ADD("computeDependencies for {}: #dirs={}",dir->name(),Doxygen::dirLinkedMap->size());
1167 dir->computeDependencies();
1168 }
1169}

References AUTO_TRACE, AUTO_TRACE_ADD, and Doxygen::dirLinkedMap.

Referenced by parseInput().

◆ createDirDef()

DirDef * createDirDef ( const QCString & path)

Definition at line 108 of file dirdef.cpp.

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

Referenced by DirDefImpl::createNewDir().

◆ encodeDirName()

QCString encodeDirName ( const QCString & anchor)
static

Definition at line 189 of file dirdef.cpp.

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

1172{
1173 AUTO_TRACE();
1174 for (const auto &dir : *Doxygen::dirLinkedMap)
1175 {
1176 ol.pushGeneratorState();
1177 if (!dir->hasDocumentation())
1178 {
1180 }
1181 dir->writeDocumentation(ol);
1182 ol.popGeneratorState();
1183 }
1184 //if (Config_getBool(DIRECTORY_GRAPH))
1185 {
1186 for (const auto &dr : Doxygen::dirRelations)
1187 {
1188 dr->writeDocumentation(ol);
1189 }
1190 }
1191}
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 1213 of file dirdef.cpp.

1214{
1215 if (d==nullptr) return nullptr;
1216 if (d && typeid(*d)==typeid(DirDefImpl))
1217 {
1218 return static_cast<const DirDef*>(d);
1219 }
1220 else
1221 {
1222 return nullptr;
1223 }
1224}

◆ toDirDef() [2/2]

DirDef * toDirDef ( Definition * d)

Definition at line 1200 of file dirdef.cpp.

1201{
1202 if (d==nullptr) return nullptr;
1203 if (d && typeid(*d)==typeid(DirDefImpl))
1204 {
1205 return static_cast<DirDef*>(d);
1206 }
1207 else
1208 {
1209 return nullptr;
1210 }
1211}

◆ writePartialDirPath()

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

Definition at line 915 of file dirdef.cpp.

916{
917 if (target->parent()!=root)
918 {
919 writePartialDirPath(ol,root,target->parent());
920 ol.writeString("&#160;/&#160;");
921 }
922 ol.writeObjectLink(target->getReference(),target->getOutputFileBase(),QCString(),target->shortName());
923}
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:915

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

926{
927 if (fd->getDirDef() && fd->getDirDef()!=root)
928 {
929 writePartialDirPath(ol,root,fd->getDirDef());
930 ol.writeString("&#160;/&#160;");
931 }
932 if (fd->isLinkable())
933 {
935 }
936 else
937 {
938 ol.startBold();
939 ol.docify(fd->name());
940 ol.endBold();
941 }
942}
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().