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

Go to the source code of this file.

Classes

class  DirDefImpl

Functions

DirDef * createDirDef (const DString &path)
static DString encodeDirName (const DString &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)
DirDef * toDirDef (Definition *d)
const DirDef * toDirDef (const Definition *d)

Function Documentation

◆ buildDirectories()

void buildDirectories ( )

Definition at line 1097 of file dirdef.cpp.

1098{
1099 AUTO_TRACE();
1100 // for each input file
1101 for (const auto &fn : *Doxygen::inputNameLinkedMap)
1102 {
1103 for (const auto &fd : *fn)
1104 {
1105 if (fd->getReference().empty())
1106 {
1107 DirDef *dir=Doxygen::dirLinkedMap->find(fd->getPath());
1108 if (dir==nullptr) // new directory
1109 {
1110 dir = DirDefImpl::mergeDirectoryInTree(fd->getPath());
1111 }
1112 if (dir && !fd->isDocumentationFile()) dir->addFile(fd.get());
1113 }
1114 else
1115 {
1116 // do something for file imported via tag files.
1117 }
1118 }
1119 }
1120
1121 // compute relations between directories => introduce container dirs.
1122 for (const auto &dir : *Doxygen::dirLinkedMap)
1123 {
1124 DString name = dir->name();
1125 size_t i = name.length()>=2 ? name.rfind('/',name.length()-2) : DString::npos;
1126 if (i!=DString::npos && i>0)
1127 {
1129 //if (parent==0) parent=root;
1130 if (parent)
1131 {
1132 parent->addSubDir(dir.get());
1133 AUTO_TRACE_ADD("DirDefImpl::addSubdir(): Adding subdir {} to {}",
1134 dir->displayName(), parent->displayName());
1135 }
1136 }
1137 }
1138
1139 // sort the directory contents
1140 for (const auto &dir : *Doxygen::dirLinkedMap)
1141 {
1142 dir->sort();
1143 }
1144
1145 // short the directories themselves
1146 std::stable_sort(Doxygen::dirLinkedMap->begin(),
1148 [](const auto &d1,const auto &d2)
1149 {
1150 DString s1 = d1->shortName(), s2 = d2->shortName();
1151 int i = dstricmp_sort(s1,s2);
1152 if (i==0) // if sort name are equal, sort on full path
1153 {
1154 DString n1 = d1->name(), n2 = d2->name();
1155 int n = dstricmp_sort(n1,n2);
1156 return n < 0;
1157 }
1158 return i < 0;
1159 });
1160
1161 // set the directory index identifier
1162 int dirIndex=0;
1163 for (const auto &dir : *Doxygen::dirLinkedMap)
1164 {
1165 dir->setDirIndex(dirIndex++);
1166 }
1167
1169}
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
size_t rfind(char c, size_t pos=npos) const
Definition dstring.h:244
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
Definition dstring.h:178
DString left(size_t len) const
Definition dstring.h:306
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:151
virtual const DString & name() const =0
virtual DString displayName(bool includeScope=true) const =0
A model of a directory symbol.
Definition dirdef.h:108
virtual void sort()=0
virtual void addFile(FileDef *fd)=0
virtual void setDirIndex(int index)=0
static DirDef * mergeDirectoryInTree(const DString &path)
Definition dirdef.cpp:896
static FileNameLinkedMap * inputNameLinkedMap
Definition doxygen.h:97
static DirLinkedMap * dirLinkedMap
Definition doxygen.h:120
const T * find(const std::string &key) const
Definition linkedmap.h:47
DirIterator begin(DirIterator it) noexcept
Definition dir.cpp:176
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:181
static void computeCommonDirPrefix()
In order to create stable, but unique directory names, we compute the common part of the path shared ...
Definition dirdef.cpp:1020
#define AUTO_TRACE_ADD(...)
Definition docnode.cpp:54
#define AUTO_TRACE(...)
Definition docnode.cpp:53
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:1335
int dstricmp_sort(const char *str1, const char *str2)
Definition dstring.h:67

References DirDef::addFile(), AUTO_TRACE, AUTO_TRACE_ADD, begin(), computeCommonDirPrefix(), Doxygen::dirLinkedMap, dstricmp_sort(), end(), LinkedMap< T, Hash, KeyEqual, Map >::find(), Doxygen::inputNameLinkedMap, DString::left(), DString::length(), DirDefImpl::mergeDirectoryInTree(), DString::npos, parent(), and DString::rfind().

Referenced by parseInput().

◆ compareDirDefs()

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

Definition at line 1210 of file dirdef.cpp.

1211{
1212 return dstricmp_sort(item1->shortName(),item2->shortName()) < 0;
1213}
virtual const DString shortName() const =0

References dstricmp_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 1020 of file dirdef.cpp.

1021{
1022 AUTO_TRACE();
1023 DString path;
1024 auto it = Doxygen::dirLinkedMap->begin();
1025 if (!Doxygen::dirLinkedMap->empty()) // we have at least one dir
1026 {
1027 // start will full path of first dir
1028 path=Portable::removeLongPathMarker((*it)->name());
1029 size_t i = path.length()>=2 ? path.rfind('/',path.length()-2) : DString::npos;
1030 bool done=false;
1031 if (i==DString::npos)
1032 {
1033 path="";
1034 }
1035 else
1036 {
1037 path=path.left(i+1);
1038 while (!done)
1039 {
1040 size_t l = path.length();
1041 size_t count=0;
1042 for (const auto &dir : *Doxygen::dirLinkedMap)
1043 {
1044 DString dirName = Portable::removeLongPathMarker(dir->name());
1045 //printf("dirName='%s' (l=%d) path='%s' (l=%d)\n",qPrint(dirName),dirName.length(),qPrint(path),path.length());
1046 if (dirName.length()>path.length())
1047 {
1048 if (dirName.left(l)!=path) // dirName does not start with path
1049 {
1050 i = l>=2 ? path.rfind('/',l-2) : DString::npos;
1051 if (i==DString::npos) // 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 break;
1060 }
1061 }
1062 }
1063 else // dir is shorter than path -> take path of dir as new start
1064 {
1065 path=dir->name();
1066 l = path.length();
1067 i = l>=2 ? path.rfind('/',l-2) : DString::npos;
1068 if (i==DString::npos) // no unique prefix -> stop
1069 {
1070 path="";
1071 done=true;
1072 }
1073 else // restart with shorter path
1074 {
1075 path=path.left(i+1);
1076 }
1077 break;
1078 }
1079 count++;
1080 }
1081 if (count==Doxygen::dirLinkedMap->size())
1082 // path matches for all directories -> found the common prefix
1083 {
1084 done=true;
1085 }
1086 }
1087 }
1088 }
1089 for (const auto &dir : *Doxygen::dirLinkedMap)
1090 {
1091 DString diskName = dir->name().right(dir->name().length()-path.length());
1092 dir->setDiskName(diskName);
1093 AUTO_TRACE_ADD("set disk name: {} -> {}",dir->name(),diskName);
1094 }
1095}
DString right(size_t len) const
Definition dstring.h:311
iterator begin()
Definition linkedmap.h:201
DString removeLongPathMarker(const DString &path)
Definition portable.cpp:656

References AUTO_TRACE, AUTO_TRACE_ADD, LinkedMap< T, Hash, KeyEqual, Map >::begin(), Doxygen::dirLinkedMap, DString::left(), DString::length(), DString::npos, Portable::removeLongPathMarker(), DString::rfind(), and DString::right().

Referenced by buildDirectories().

◆ computeDirDependencies()

void computeDirDependencies ( )

Definition at line 1171 of file dirdef.cpp.

1172{
1173 AUTO_TRACE();
1174 // compute nesting level for each directory
1175 for (const auto &dir : *Doxygen::dirLinkedMap)
1176 {
1177 dir->setLevel();
1178 }
1179
1180 // compute uses dependencies between directories
1181 for (const auto &dir : *Doxygen::dirLinkedMap)
1182 {
1183 AUTO_TRACE_ADD("computeDependencies for {}: #dirs={}",dir->name(),Doxygen::dirLinkedMap->size());
1184 dir->computeDependencies();
1185 }
1186}
size_t size() const
Definition linkedmap.h:210

References AUTO_TRACE, AUTO_TRACE_ADD, Doxygen::dirLinkedMap, and LinkedMap< T, Hash, KeyEqual, Map >::size().

Referenced by parseInput().

◆ createDirDef()

DirDef * createDirDef ( const DString & path)

Definition at line 115 of file dirdef.cpp.

116{
117 return new DirDefImpl(path);
118}

Referenced by DirDefImpl::createNewDir().

◆ encodeDirName()

DString encodeDirName ( const DString & anchor)
static

Definition at line 195 of file dirdef.cpp.

196{
197 AUTO_TRACE();
198 // convert to md5 hash
199 DString sigStr = md5str(anchor.view());
200 AUTO_TRACE_EXIT("result={}",sigStr);
201 return sigStr;
202}
std::string_view view() const
Definition dstring.h:162
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:55
DString md5str(const std::string_view &str)
Definition md5hash.h:33

References AUTO_TRACE, AUTO_TRACE_EXIT, md5str(), and DString::view().

Referenced by DirDefImpl::getOutputFileBase().

◆ generateDirDocs()

void generateDirDocs ( OutputList & ol)

Definition at line 1188 of file dirdef.cpp.

1189{
1190 AUTO_TRACE();
1191 for (const auto &dir : *Doxygen::dirLinkedMap)
1192 {
1193 ol.pushGeneratorState();
1194 if (!dir->hasDocumentation())
1195 {
1197 }
1198 dir->writeDocumentation(ol);
1199 ol.popGeneratorState();
1200 }
1201 //if (Config_getBool(DIRECTORY_GRAPH))
1202 {
1203 for (const auto &dr : Doxygen::dirRelations)
1204 {
1205 dr->writeDocumentation(ol);
1206 }
1207 }
1208}
static DirRelationLinkedMap dirRelations
Definition doxygen.h:121
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 1230 of file dirdef.cpp.

1231{
1232 if (d==nullptr) return nullptr;
1233 if (d && typeid(*d)==typeid(DirDefImpl))
1234 {
1235 return static_cast<const DirDef*>(d);
1236 }
1237 else
1238 {
1239 return nullptr;
1240 }
1241}

◆ toDirDef() [2/2]

DirDef * toDirDef ( Definition * d)

Definition at line 1217 of file dirdef.cpp.

1218{
1219 if (d==nullptr) return nullptr;
1220 if (d && typeid(*d)==typeid(DirDefImpl))
1221 {
1222 return static_cast<DirDef*>(d);
1223 }
1224 else
1225 {
1226 return nullptr;
1227 }
1228}

◆ writePartialDirPath()

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

Definition at line 932 of file dirdef.cpp.

933{
934 if (target->parent()!=root)
935 {
936 writePartialDirPath(ol,root,target->parent());
937 ol.writeString("&#160;/&#160;");
938 }
939 ol.writeObjectLink(target->getReference(),target->getOutputFileBase(),DString(),target->shortName());
940}
virtual DString getReference() const =0
virtual DString getOutputFileBase() const =0
virtual DirDef * parent() const =0
void writeObjectLink(const DString &ref, const DString &file, const DString &anchor, const DString &name)
Definition outputlist.h:435
void writeString(const DString &text)
Definition outputlist.h:407
static void writePartialDirPath(OutputList &ol, const DirDef *root, const DirDef *target)
Definition dirdef.cpp:932

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

943{
944 if (fd->getDirDef() && fd->getDirDef()!=root)
945 {
946 writePartialDirPath(ol,root,fd->getDirDef());
947 ol.writeString("&#160;/&#160;");
948 }
949 if (fd->isLinkable())
950 {
952 }
953 else
954 {
955 ol.startBold();
956 ol.docify(fd->name());
957 ol.endBold();
958 }
959}
virtual bool isLinkable() const =0
virtual DirDef * getDirDef() const =0
void docify(const DString &s)
Definition outputlist.h:433
void startBold()
Definition outputlist.h:557
void endBold()
Definition outputlist.h:559

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