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

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

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

Referenced by parseInput().

◆ compareDirDefs()

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

Definition at line 1212 of file dirdef.cpp.

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

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

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

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

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

◆ toDirDef() [2/2]

DirDef * toDirDef ( Definition * d)

Definition at line 1219 of file dirdef.cpp.

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

◆ writePartialDirPath()

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

Definition at line 934 of file dirdef.cpp.

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

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

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