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

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

1099{
1100 AUTO_TRACE();
1101 // for each input file
1102 for (const auto &fn : *Doxygen::inputNameLinkedMap)
1103 {
1104 for (const auto &fd : *fn)
1105 {
1106 if (fd->getReference().empty())
1107 {
1108 DirDef *dir=Doxygen::dirLinkedMap->find(fd->getPath());
1109 if (dir==nullptr) // new directory
1110 {
1111 dir = DirDefImpl::mergeDirectoryInTree(fd->getPath());
1112 }
1113 if (dir && !fd->isDocumentationFile()) dir->addFile(fd.get());
1114 }
1115 else
1116 {
1117 // do something for file imported via tag files.
1118 }
1119 }
1120 }
1121
1122 // compute relations between directories => introduce container dirs.
1123 for (const auto &dir : *Doxygen::dirLinkedMap)
1124 {
1125 DString name = dir->name();
1126 size_t i = name.length()>=2 ? name.rfind('/',name.length()-2) : DString::npos;
1127 if (i!=DString::npos && i>0)
1128 {
1130 //if (parent==0) parent=root;
1131 if (parent)
1132 {
1133 parent->addSubDir(dir.get());
1134 AUTO_TRACE_ADD("DirDefImpl::addSubdir(): Adding subdir {} to {}",
1135 dir->displayName(), parent->displayName());
1136 }
1137 }
1138 }
1139
1140 // sort the directory contents
1141 for (const auto &dir : *Doxygen::dirLinkedMap)
1142 {
1143 dir->sort();
1144 }
1145
1146 // short the directories themselves
1147 std::stable_sort(Doxygen::dirLinkedMap->begin(),
1149 [](const auto &d1,const auto &d2)
1150 {
1151 DString s1 = d1->shortName(), s2 = d2->shortName();
1152 int i = dstricmp_sort(s1,s2);
1153 if (i==0) // if sort name are equal, sort on full path
1154 {
1155 DString n1 = d1->name(), n2 = d2->name();
1156 int n = dstricmp_sort(n1,n2);
1157 return n < 0;
1158 }
1159 return i < 0;
1160 });
1161
1162 // set the directory index identifier
1163 int dirIndex=0;
1164 for (const auto &dir : *Doxygen::dirLinkedMap)
1165 {
1166 dir->setDirIndex(dirIndex++);
1167 }
1168
1170}
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:897
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:1021
#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 1211 of file dirdef.cpp.

1212{
1213 return dstricmp_sort(item1->shortName(),item2->shortName()) < 0;
1214}
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 1021 of file dirdef.cpp.

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

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

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

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

◆ toDirDef() [2/2]

DirDef * toDirDef ( Definition * d)

Definition at line 1218 of file dirdef.cpp.

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

◆ writePartialDirPath()

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

Definition at line 933 of file dirdef.cpp.

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

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

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