HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
path_location.hpp
Go to the documentation of this file.
1// Copyright Take Vos 2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
9#pragma once
10
11#include "../generator.hpp"
12#include "../exception.hpp"
13#include <filesystem>
14#include <ranges>
15
16namespace hi { inline namespace v1 {
17
21enum class path_location {
25
29
33
38
42
46
49 log_dir,
50
54
58
62
66};
67
74[[nodiscard]] generator<std::filesystem::path> get_paths(path_location location);
75
83[[nodiscard]] inline std::optional<std::filesystem::path> find_path(path_location location, std::filesystem::path const &ref) noexcept
84{
85 if (ref.is_absolute()) {
86 if (std::filesystem::exists(ref)) {
87 return ref;
88 } else {
89 return {};
90 }
91 } else {
92 for (hilet &base: get_paths(location)) {
93 auto path = base / ref;
94 if (std::filesystem::exists(path)) {
95 return path;
96 }
97 }
98 return {};
99 }
100}
101
109[[nodiscard]] inline std::filesystem::path get_path(path_location location)
110{
111 auto range = get_paths(location);
112 auto it = std::ranges::begin(range);
113 hilet last = std::ranges::end(range);
114
115 if (it == last) {
116 throw url_error("No path found.");
117 }
118
119 auto path = *it++;
120
121 if (it != last) {
122 throw url_error("More than one path found.");
123 }
124
125 return path;
126}
127
128
129}} // namespace hi::v1
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
std::optional< std::filesystem::path > find_path(path_location location, std::filesystem::path const &ref) noexcept
Find a path.
Definition path_location.hpp:83
path_location
File and Directory locations.
Definition path_location.hpp:21
generator< std::filesystem::path > get_paths(path_location location)
Get a set of paths.
std::filesystem::path get_path(path_location location)
Get the single and only path.
Definition path_location.hpp:109
@ data_dir
The single directory where the data for the application is stored for the current user account.
@ resource_dirs
The location of application resources.
@ executable_file
A single file where the current running executable is located.
@ theme_dirs
The directories where the themes are located.
@ library_dir
The single directory where the HikoGUI shared library is located.
@ preferences_file
A single file where to store or load the application preferences file for the current user account.
@ executable_dir
The directory where the executable is located.
@ library_file
A single file where the current running HikoGUI shared library is located.
@ log_dir
The single directory where to store the log files.
@ system_font_dirs
The directories where the system fonts are stored.
@ font_dirs
The directories where the fonts for the system and resource fonts are located.
DOXYGEN BUG.
Definition algorithm.hpp:15
The HikoGUI namespace.
Definition ascii.hpp:19
Definition exception.hpp:108