Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
FileResolver Class Reference

Encapsulate the logic that QDoc uses to find files whose path is provided by the user and that are relative to the current configuration. More...

#include <fileresolver.h>

+ Collaboration diagram for FileResolver:

Public Member Functions

 FileResolver (std::vector< DirectoryPath > &&search_directories)
 Constructs an instance of FileResolver with the directories in search_directories as root directories for searching.
 
std::optional< ResolvedFileresolve (QString filename) const
 Returns a ResolvedFile if query can be resolved or std::nullopt otherwise.
 
const std::vector< DirectoryPath > & get_search_directories () const
 Returns a const-reference to a collection of root search directories that this instance will use during the resolution of files.
 

Detailed Description

Encapsulate the logic that QDoc uses to find files whose path is provided by the user and that are relative to the current configuration.

A FileResolver instance is configured during creation, defining the root directories that the search should be performed on.

Afterwards, it can be used to resolve paths relative to those directories, by querying through the resolve() method.

Queries are resolved through a linear search through root directories, finding at most one file each time. A file is considered to be resolved if, from any root directory, the query represents an existing file.

For example, consider the following directory structure on some filesystem:

\badcode foo/ | |-bar/ |-| | |-anotherfile.txt |-file.txt

And consider an instance of FileResolver tha considers {foo/} to be a root directory for search.

Then, queries such as {bar/anotherfile.txt} and {file.txt} will be resolved.

Instead, queries such as {foobar.cpp}, {bar}, and {foo/bar/anotherfile.txt} will not be resolved, as they do not represent any file reachable from a root directory for search.

It is important to note that FileResolver always searches its root directories in an order that is based on the lexicographic ordering of the path of its root directories.

For example, consider the following directory structure on some filesystem:

\badcode foo/ | |-bar/ |-| | |-file.txt |-foobar/ |-| | |-file.txt

And consider an instance of FileResolver that considers {foo/bar/} and {foo/foobar/} to be root directories for search.

Then, when the query {file.txt} is resolved, it will always resolve to the file in {bar}, as {bar} will be searched before {foobar}.

We say that {foobar/file.txt} is shadowed by {bar/file.txt}.

Currently, if this is an issue, it is possible to resolve it by using a common ancestor as a root directory instead of using multiples directories.

In the previous example, if {foo} is instead chosen as the root directory for search, then queries {bar/file.txt} and {foobar/file.txt} can be used to uniquely resolve the two files, removing the shadowing.

Definition at line 14 of file fileresolver.h.

Constructor & Destructor Documentation

◆ FileResolver()

FileResolver::FileResolver ( std::vector< DirectoryPath > && search_directories)

Constructs an instance of FileResolver with the directories in search_directories as root directories for searching.

Duplicates in search_directories do not affect the resolution of files for the instance.

For example, if search_directories contains some directory D more than once, the constructed instance will resolve files equivalently to an instance constructed with a single appearance of D.

The order of search_directories does not affect the resolution of files for an instance.

For example, if search_directories contains a permutation of directories D1, D2, ..., Dn, then the constructed instance will resolve files equivalently to an instance constructed from a difference permutation of the same directories.

Definition at line 109 of file fileresolver.cpp.

References FileResolver().

Referenced by FileResolver().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Function Documentation

◆ get_search_directories()

const std::vector< DirectoryPath > & FileResolver::get_search_directories ( ) const
inlinenodiscard

Returns a const-reference to a collection of root search directories that this instance will use during the resolution of files.

Definition at line 20 of file fileresolver.h.

◆ resolve()

std::optional< ResolvedFile > FileResolver::resolve ( QString query) const
nodiscard

Returns a ResolvedFile if query can be resolved or std::nullopt otherwise.

The returned ResolvedFile, if any, will contain the provided query and the path that the query was resolved to.

Definition at line 146 of file fileresolver.cpp.


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