|
| file | glob.hpp |
| | Defines utilities for handling glob patterns.
|
| |
| file | path_location.hpp |
| | functions to locate files and directories.
|
| |
This module contains file handling utilities:
*_dir(), *_dirs(), *_file() for getting the configured paths of the system.
find_path() to find files in a set of directories.
glob_pattern, glob() to find files and directories based on a glob pattern.
URI and URL for managing URLs for local and remote resources.
Path locations
The path-locations functions are used to find files and directories based on the context of the operating system, the user account and application.
For example fonts are located in multiple places:
- the font-directory where a user can install their own fonts,
- the font-directory that is part of the application's resources, and
- the font-directory which is shared between all users of the operating system.
To iterate over all the font directories:
for (auto const &path : font_dirs()) {
}
To find the first matching file in one of the font directories:
if (
auto const &path :
hi::
find_path(font_dirs(),
"arial.ttf")) {
}
hi_inline std::optional< std::filesystem::path > find_path(Locations &&locations, std::filesystem::path const &ref) noexcept
Find a path.
Definition path_location_intf.hpp:40
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
glob
To find files based on a pattern using wild cards like * you can use the glob utilities.
The constructor of the glob_pattern object parses a string or std::filesystem::path which contain one or more of the following tokens:
| Token | Description |
| foo | Matches the text "foo". |
| ? | Matches any single character except '/'. |
| [abcd] | Matches a single character that is 'a', 'b', 'c' or 'd'. |
| [a-d] | Matches a single character that is 'a', 'b', 'c' or 'd'. |
| [-a-d] | Matches a single character that is '-', 'a', 'b', 'c' or 'd'. |
| {foo,bar,baz} | Matches the text "foo", "bar" or "baz". |
| * | Matches zero or more character except '/'. |
| /**/ | Matches one or more directories. A single slash or zero or more characters between two slashes. |
Then the glob() function will search for files and directories matching this pattern. glob() is also overloaded to directly parse a pattern and combine it with path_location.
For example to find all the files in the font directories:
for (
auto const &path :
hi::
glob(font_dirs(),
"**‍/‍
*.ttf ")) {
}
hi_export hi_inline generator< std::filesystem::path > glob(glob_pattern pattern) noexcept
Find paths on the filesystem that match the glob pattern.
Definition glob.hpp:880
URL / URI
The URI, URL and URN terms can be confusing, here is a short explanation.
- A URI (Unique Resource Identifier) is a specification for parsing and writing identifiers.
- A URL (Unique Resource Locator) is a type of URI which is used to address things.
- A URN (Unique Resource Name) is a type of URI which is used to name things.
HikoGUI currently implements dereferencing of the following types of URLs:
- relative path: A relative path does not start with a scheme and can be joined with a base URL to get an absolute URL.
- file-URL: A file accessible via the operating system. This scheme supports the following features:
- relative paths (can not be joined using URL joining),
- absolute path (relative to the current drive or file-share),
- relative path on a specific drive,
- absolute path on a specific drive and file-share,
- conversion of drive to a file-share name,
- the server name may be part of the double-slash "//" path or the authority.
- resource-URL: A relative path that converts into a file-path by searching for the first file in one of the directories of
resource_dirs().
Both file: and resource: URLs may be implicitly converted to a std::filesystem::path.
◆ data_dir()
| std::filesystem::path hi::v1::data_dir |
( |
| ) |
|
|
noexcept |
Get the full path to the directory where the application should store its data.
◆ executable_dir()
| hi_inline std::filesystem::path hi::v1::executable_dir |
( |
| ) |
|
|
noexcept |
Get the full path to the directory when this executable is located.
◆ executable_file()
| std::filesystem::path hi::v1::executable_file |
( |
| ) |
|
|
noexcept |
Get the full path to this executable.
◆ find_path()
template<path_range Locations>
| hi_inline std::optional< std::filesystem::path > hi::v1::find_path |
( |
Locations && | locations, |
|
|
std::filesystem::path const & | ref ) |
|
noexcept |
Find a path.
- Parameters
-
| locations | The locations to search for filesystem-object. |
| ref | A relative path to the filesystem-object. |
- Returns
- The the first full path to the filesystem-object found in the location. Or empty if the path is not found.
◆ font_files()
| hi_inline generator< std::filesystem::path > hi::v1::font_files |
( |
| ) |
|
|
noexcept |
The directories to search for font files of both the application and system.
◆ glob() [1/8]
| hi_export hi_inline generator< std::filesystem::path > hi::v1::glob |
( |
char const * | pattern | ) |
|
|
noexcept |
Find paths on the filesystem that match the glob pattern.
- Parameters
-
| pattern | The pattern to search the filesystem for. |
- Returns
- a generator yielding paths to objects on the filesystem that match the pattern.
◆ glob() [2/8]
template<path_range Locations>
| hi_export hi_inline generator< std::filesystem::path > hi::v1::glob |
( |
Locations && | locations, |
|
|
char const * | ref ) |
|
noexcept |
Find paths on the filesystem that match the glob pattern.
- Parameters
-
| locations | The path-locations to search files in |
| ref | A relative path pattern to search the path-location |
- Returns
- a generator yielding paths to objects in the path-location that match the pattern.
◆ glob() [3/8]
template<path_range Locations>
| hi_export hi_inline generator< std::filesystem::path > hi::v1::glob |
( |
Locations && | locations, |
|
|
std::filesystem::path | ref ) |
|
noexcept |
Find paths on the filesystem that match the glob pattern.
- Parameters
-
| locations | The path-locations to search files in |
| ref | A relative path pattern to search the path-location |
- Returns
- a generator yielding paths to objects in the path-location that match the pattern.
◆ glob() [4/8]
template<path_range Locations>
| hi_export hi_inline generator< std::filesystem::path > hi::v1::glob |
( |
Locations && | locations, |
|
|
std::string | ref ) |
|
noexcept |
Find paths on the filesystem that match the glob pattern.
- Parameters
-
| locations | The path-locations to search files in |
| ref | A relative path pattern to search the path-location |
- Returns
- a generator yielding paths to objects in the path-location that match the pattern.
◆ glob() [5/8]
template<path_range Locations>
| hi_export hi_inline generator< std::filesystem::path > hi::v1::glob |
( |
Locations && | locations, |
|
|
std::string_view | ref ) |
|
noexcept |
Find paths on the filesystem that match the glob pattern.
- Parameters
-
| locations | The path-locations to search files in |
| ref | A relative path pattern to search the path-location |
- Returns
- a generator yielding paths to objects in the path-location that match the pattern.
◆ glob() [6/8]
| hi_export hi_inline generator< std::filesystem::path > hi::v1::glob |
( |
std::filesystem::path | pattern | ) |
|
|
noexcept |
Find paths on the filesystem that match the glob pattern.
- Parameters
-
| pattern | The pattern to search the filesystem for. |
- Returns
- a generator yielding paths to objects on the filesystem that match the pattern.
◆ glob() [7/8]
| hi_export hi_inline generator< std::filesystem::path > hi::v1::glob |
( |
std::string | pattern | ) |
|
|
noexcept |
Find paths on the filesystem that match the glob pattern.
- Parameters
-
| pattern | The pattern to search the filesystem for. |
- Returns
- a generator yielding paths to objects on the filesystem that match the pattern.
◆ glob() [8/8]
| hi_export hi_inline generator< std::filesystem::path > hi::v1::glob |
( |
std::string_view | pattern | ) |
|
|
noexcept |
Find paths on the filesystem that match the glob pattern.
- Parameters
-
| pattern | The pattern to search the filesystem for. |
- Returns
- a generator yielding paths to objects on the filesystem that match the pattern.
◆ library_install_dir()
| hi_inline std::optional< std::filesystem::path > hi::v1::library_install_dir |
( |
| ) |
|
|
noexcept |
The full path where HikoGUI is installed during compilation of the application.
- Returns
- The full path to the install path of HikoGUI.
- Return values
-
| std::nullopt | The HikoGUI library is not installed and is located in its build dir. |
◆ log_dir()
| std::filesystem::path hi::v1::log_dir |
( |
| ) |
|
|
noexcept |
Get the full path to the directory where the application should store its log files.
◆ preferences_file()
| std::filesystem::path hi::v1::preferences_file |
( |
| ) |
|
|
noexcept |
Get the full path to application preferences file.
◆ resource_dirs()
| hi_inline generator< std::filesystem::path > hi::v1::resource_dirs |
( |
| ) |
|
|
noexcept |
The directories to search for resource files.
◆ source_dir()
| hi_inline std::optional< std::filesystem::path > hi::v1::source_dir |
( |
| ) |
|
|
noexcept |
Get the full path to source code of this executable.
- Returns
- The path to directory of the source code.
- Return values
-
| std::nullopt | The executable is not located in its build directory. |
◆ system_font_dirs()
| hi_inline generator< std::filesystem::path > hi::v1::system_font_dirs |
( |
| ) |
|
|
noexcept |
The directories to search for system font files.
◆ theme_files()
| hi_inline generator< std::filesystem::path > hi::v1::theme_files |
( |
| ) |
|
|
noexcept |
The directories to search for theme files of the application.