Doxygen
Loading...
Searching...
No Matches
FileNameLinkedMap Class Referencefinal

Ordered dictionary of FileName objects. More...

#include <src/filename.h>

Inheritance diagram for FileNameLinkedMap:
Collaboration diagram for FileNameLinkedMap:

Public Member Functions

FileDeffindFileDef (const DString &n, bool &ambig) const
 Returns the file definition in fnMap that matches the file name n.
DString showFileDefMatches (const DString &n) const
 Returns a list of file definitions in fnMap that match the file name n.
Public Member Functions inherited from LinkedMap< FileName, FileNameFn, FileNameFn, std::unordered_multimap< std::string, FileName *, FileNameFn, FileNameFn > >
const FileNamefind (const std::string &key) const
FileNameadd (const char *k, Args &&... args)
FileNameprepend (const char *k, Args &&... args)
bool del (const DString &key)
Ptroperator[] (size_t pos)
iterator begin ()
iterator end ()
reverse_iterator rbegin ()
reverse_iterator rend ()
bool empty () const
size_t size () const
void clear ()

Additional Inherited Members

Public Types inherited from LinkedMap< FileName, FileNameFn, FileNameFn, std::unordered_multimap< std::string, FileName *, FileNameFn, FileNameFn > >
using Ptr
using Vec
using iterator
using const_iterator
using reverse_iterator
using const_reverse_iterator

Detailed Description

Ordered dictionary of FileName objects.

Definition at line 68 of file filename.h.

Member Function Documentation

◆ findFileDef()

FileDef * FileNameLinkedMap::findFileDef ( const DString & n,
bool & ambig ) const

Returns the file definition in fnMap that matches the file name n.

If there are multiple matches, ambig is set to true and the first match is returned. If there are no matches, ambig is set to false and nullptr is returned.

Definition at line 36 of file filename.cpp.

37{
38 ambig=false;
39 if (n.empty()) return nullptr;
40
41
42 const int maxAddrSize = 20;
43 char addr[maxAddrSize];
44 snprintf(addr,maxAddrSize,"%p:",reinterpret_cast<const void*>(this));
45 DString key = addr;
46 key+=n;
47
48 std::lock_guard<std::mutex> lock(g_findFileDefMutex);
49 FindFileCacheElem *cachedResult = g_findFileDefCache.find(key.str());
50 //printf("key=%s cachedResult=%p\n",qPrint(key),cachedResult);
51 if (cachedResult)
52 {
53 ambig = cachedResult->isAmbig;
54 //printf("cached: fileDef=%p\n",cachedResult->fileDef);
55 return cachedResult->fileDef;
56 }
57 else
58 {
59 cachedResult = g_findFileDefCache.insert(key.str(),FindFileCacheElem(nullptr,false));
60 }
61
62 DString name=Dir::cleanDirPath(n.str());
63 DString path;
64 if (name.empty()) return nullptr;
65 size_t sp0 = name.rfind('/');
66 size_t sp1 = name.rfind('\\');
67 size_t slashPos = sp0!=DString::npos && sp1!=DString::npos ? std::max(sp0,sp1) :
68 sp0!=DString::npos ? sp0 : sp1;
69 if (slashPos!=DString::npos)
70 {
71 path=Portable::removeLongPathMarker(name.left(slashPos+1));
72 name=name.mid(slashPos+1);
73 }
74 if (name.empty()) return nullptr;
75 const FileName *fn = this->find(name);
76 if (fn)
77 {
78 //printf("fn->size()=%zu\n",fn->size());
79 if (fn->size()==1)
80 {
81 const std::unique_ptr<FileDef> &fd = fn->front();
82 bool isSamePath = Portable::fileSystemIsCaseSensitive() ?
83 fd->getPath().right(path.length())==path :
84 fd->getPath().right(path.length()).lower()==path.lower();
85 if (path.empty() || isSamePath)
86 {
87 cachedResult->fileDef = fd.get();
88 return fd.get();
89 }
90 }
91 else // file name alone is ambiguous
92 {
93 int count=0;
94 FileDef *lastMatch=nullptr;
95 DString pathStripped = stripFromIncludePath(path);
96 for (const auto &fd_p : *fn)
97 {
98 FileDef *fd = fd_p.get();
99 DString fdStripPath = stripFromIncludePath(fd->getPath());
100 if (fdStripPath == pathStripped)
101 {
102 // if the stripped paths are equal, we have a perfect match
103 count = 1;
104 lastMatch=fd;
105 break;
106 }
107 if (path.empty() ||
108 (!pathStripped.empty() && fdStripPath.endsWith(pathStripped)) ||
109 (pathStripped.empty() && fdStripPath.empty()))
110 {
111 count++;
112 lastMatch=fd;
113 }
114 }
115
116 ambig=(count>1);
117 cachedResult->isAmbig = ambig;
118 cachedResult->fileDef = lastMatch;
119 return lastMatch;
120 }
121 }
122 else
123 {
124 //printf("not found!\n");
125 }
126 return nullptr;
127}
size_t rfind(char c, size_t pos=npos) const
Definition dstring.h:248
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:322
DString lower() const
Definition dstring.h:330
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:152
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 right(size_t len) const
Definition dstring.h:315
DString left(size_t len) const
Definition dstring.h:310
const std::string & str() const
Definition dstring.h:649
bool endsWith(const char *s) const
Definition dstring.h:621
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:155
static std::string cleanDirPath(const std::string &path)
Definition dir.cpp:358
virtual DString getPath() const =0
static Cache< std::string, FindFileCacheElem > g_findFileDefCache(5000)
static std::mutex g_findFileDefMutex
Definition filename.cpp:34
DString removeLongPathMarker(const DString &path)
Definition portable.cpp:640
bool fileSystemIsCaseSensitive()
Definition portable.cpp:470
FileDef * fileDef
Definition filename.cpp:28
DString stripFromIncludePath(const DString &path)
Definition util.cpp:229

References Dir::cleanDirPath(), DString::empty(), DString::endsWith(), FindFileCacheElem::fileDef, Portable::fileSystemIsCaseSensitive(), LinkedMap< FileName, FileNameFn, FileNameFn, std::unordered_multimap< std::string, FileName *, FileNameFn, FileNameFn > >::find(), g_findFileDefCache, g_findFileDefMutex, FileDef::getPath(), FindFileCacheElem::isAmbig, DString::left(), DString::length(), DString::lower(), DString::mid(), DString::npos, Portable::removeLongPathMarker(), DString::rfind(), DString::right(), DString::str(), and stripFromIncludePath().

Referenced by addIncludeFile(), buildFileList(), DocParser::findAndCopyImage(), DocParser::findDocsForMemberOrCompound(), findExampleFilePath(), findFile(), generateFileSources(), DocParser::handleLinkedWord(), DocbookDocVisitor::operator()(), XmlDocVisitor::operator()(), DocDiaFile::parse(), DocDotFile::parse(), DocMermaidFile::parse(), DocMscFile::parse(), DocPlantUmlFile::parse(), parseFilesMultiThreading(), parseFilesSingleThreading(), Markdown::Private::processLink(), readIncludeFile(), readTextFileByName(), ModuleManager::resolveImports(), ModuleManager::resolvePartitions(), resolveRef(), and setFileName().

◆ showFileDefMatches()

DString FileNameLinkedMap::showFileDefMatches ( const DString & n) const

Returns a list of file definitions in fnMap that match the file name n.

The list is returned as a string with each file definition separated by a newline character. Used for error messages.

Definition at line 129 of file filename.cpp.

130{
131 DString result;
132 DString name=Dir::cleanDirPath(n.str());
133 DString path;
134 size_t sp0 = name.rfind('/');
135 size_t sp1 = name.rfind('\\');
136 size_t slashPos = sp0!=DString::npos && sp1!=DString::npos ? std::max(sp0,sp1) :
137 sp0!=DString::npos ? sp0 : sp1;
138 if (slashPos!=DString::npos)
139 {
140 path=Portable::removeLongPathMarker(name.left(slashPos+1));
141 name=name.mid(slashPos+1);
142 }
143 const FileName *fn=this->find(name);
144 if (fn)
145 {
146 bool first = true;
147 DString pathStripped = stripFromIncludePath(path);
148 for (const auto &fd_p : *fn)
149 {
150 FileDef *fd = fd_p.get();
151 DString fdStripPath = stripFromIncludePath(fd->getPath());
152 if (path.empty() ||
153 (!pathStripped.empty() && fdStripPath.endsWith(pathStripped)) ||
154 (pathStripped.empty() && fdStripPath.empty()))
155 {
156 if (!first) result += "\n";
157 else first = false;
158 result+=" "+fd->absFilePath();
159 }
160 }
161
162 }
163 return result;
164}
virtual DString absFilePath() const =0

References FileDef::absFilePath(), Dir::cleanDirPath(), DString::empty(), DString::endsWith(), LinkedMap< FileName, FileNameFn, FileNameFn, std::unordered_multimap< std::string, FileName *, FileNameFn, FileNameFn > >::find(), FileDef::getPath(), DString::left(), DString::mid(), DString::npos, Portable::removeLongPathMarker(), DString::rfind(), DString::str(), and stripFromIncludePath().

Referenced by addIncludeFile(), buildFileList(), DocParser::findAndCopyImage(), DocDiaFile::parse(), DocDotFile::parse(), DocMermaidFile::parse(), DocMscFile::parse(), DocPlantUmlFile::parse(), readIncludeFile(), and DocParser::readTextFileByName().


The documentation for this class was generated from the following files: