Doxygen
Loading...
Searching...
No Matches
dirdef.cpp File Reference
#include <algorithm>
#include "dirdef.h"
#include "md5hash.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 "portable.h"
Include dependency graph for dirdef.cpp:

Go to the source code of this file.

Classes

class  DirDefImpl

Functions

DirDefcreateDirDef (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)
DirDeftoDirDef (Definition *d)
const DirDeftoDirDef (const Definition *d)

Function Documentation

◆ buildDirectories()

void buildDirectories ( )

Definition at line 1095 of file dirdef.cpp.

1096{
1097 AUTO_TRACE();
1098 // for each input file
1099 for (const auto &fn : *Doxygen::inputNameLinkedMap)
1100 {
1101 for (const auto &fd : *fn)
1102 {
1103 if (fd->getReference().empty())
1104 {
1105 DirDef *dir=Doxygen::dirLinkedMap->find(fd->getPath());
1106 if (dir==nullptr) // new directory
1107 {
1108 dir = DirDefImpl::mergeDirectoryInTree(fd->getPath());
1109 }
1110 if (dir && !fd->isDocumentationFile()) dir->addFile(fd.get());
1111 }
1112 else
1113 {
1114 // do something for file imported via tag files.
1115 }
1116 }
1117 }
1118
1119 // compute relations between directories => introduce container dirs.
1120 for (const auto &dir : *Doxygen::dirLinkedMap)
1121 {
1122 DString name = dir->name();
1123 size_t i = name.length()>=2 ? name.rfind('/',name.length()-2) : DString::npos;
1124 if (i!=DString::npos && i>0)
1125 {
1127 //if (parent==0) parent=root;
1128 if (parent)
1129 {
1130 parent->addSubDir(dir.get());
1131 AUTO_TRACE_ADD("DirDefImpl::addSubdir(): Adding subdir {} to {}",
1132 dir->displayName(), parent->displayName());
1133 }
1134 }
1135 }
1136
1137 // sort the directory contents
1138 for (const auto &dir : *Doxygen::dirLinkedMap)
1139 {
1140 dir->sort();
1141 }
1142
1143 // short the directories themselves
1144 std::stable_sort(Doxygen::dirLinkedMap->begin(),
1146 [](const auto &d1,const auto &d2)
1147 {
1148 DString s1 = d1->shortName(), s2 = d2->shortName();
1149 int i = dstricmp_sort(s1,s2);
1150 if (i==0) // if sort name are equal, sort on full path
1151 {
1152 DString n1 = d1->name(), n2 = d2->name();
1153 int n = dstricmp_sort(n1,n2);
1154 return n < 0;
1155 }
1156 return i < 0;
1157 });
1158
1159 // set the directory index identifier
1160 int dirIndex=0;
1161 for (const auto &dir : *Doxygen::dirLinkedMap)
1162 {
1163 dir->setDirIndex(dirIndex++);
1164 }
1165
1167}
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:88
size_t rfind(char c, size_t pos=npos) const
Definition dstring.h:248
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:182
DString left(size_t len) const
Definition dstring.h:310
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:155
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:894
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:171
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:176
static void computeCommonDirPrefix()
In order to create stable, but unique directory names, we compute the common part of the path shared ...
Definition dirdef.cpp:1018
#define AUTO_TRACE_ADD(...)
Definition docnode.cpp:52
#define AUTO_TRACE(...)
Definition docnode.cpp:51
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:71

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

1209{
1210 return dstricmp_sort(item1->shortName(),item2->shortName()) < 0;
1211}
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 1018 of file dirdef.cpp.

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

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

1170{
1171 AUTO_TRACE();
1172 // compute nesting level for each directory
1173 for (const auto &dir : *Doxygen::dirLinkedMap)
1174 {
1175 dir->setLevel();
1176 }
1177
1178 // compute uses dependencies between directories
1179 for (const auto &dir : *Doxygen::dirLinkedMap)
1180 {
1181 AUTO_TRACE_ADD("computeDependencies for {}: #dirs={}",dir->name(),Doxygen::dirLinkedMap->size());
1182 dir->computeDependencies();
1183 }
1184}
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 112 of file dirdef.cpp.

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

Referenced by DirDefImpl::createNewDir().

◆ encodeDirName()

DString encodeDirName ( const DString & anchor)
static

Definition at line 192 of file dirdef.cpp.

193{
194 AUTO_TRACE();
195 // convert to md5 hash
196 DString sigStr = md5str(anchor.view());
197 AUTO_TRACE_EXIT("result={}",sigStr);
198 return sigStr;
199}
std::string_view view() const
Definition dstring.h:166
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:53
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 1186 of file dirdef.cpp.

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

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

◆ toDirDef() [2/2]

DirDef * toDirDef ( Definition * d)

Definition at line 1215 of file dirdef.cpp.

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

◆ writePartialDirPath()

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

Definition at line 930 of file dirdef.cpp.

931{
932 if (target->parent()!=root)
933 {
934 writePartialDirPath(ol,root,target->parent());
935 ol.writeString("&#160;/&#160;");
936 }
937 ol.writeObjectLink(target->getReference(),target->getOutputFileBase(),DString(),target->shortName());
938}
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:930

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

941{
942 if (fd->getDirDef() && fd->getDirDef()!=root)
943 {
944 writePartialDirPath(ol,root,fd->getDirDef());
945 ol.writeString("&#160;/&#160;");
946 }
947 if (fd->isLinkable())
948 {
950 }
951 else
952 {
953 ol.startBold();
954 ol.docify(fd->name());
955 ol.endBold();
956 }
957}
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().