5 namespace fs = std::filesystem;
9 const std::filesystem::path& potential_base,
10 const std::filesystem::path& path)
12 if (path.is_absolute()) {
16 const fs::path root_abs = fs::absolute(potential_base);
18 if (!fs::is_directory(root_abs)) {
23 const fs::path resolved_path = fs::weakly_canonical(potential_base / path);
25 return {resolved_path, fs::exists(resolved_path)};
38 std::pair<std::filesystem::path, bool>
resolve(
const std::filesystem::path& path)
const
42 const auto& [new_path, succeeded] = res;
51 std::vector<std::filesystem::path>
m_paths;
87 const std::filesystem::path& path)
const
89 return m_impl->resolve(path);
99 nlohmann_json_j = nlohmann_json_t.m_impl->m_paths;
103 nlohmann_json_t.m_impl->m_paths.clear();
104 if (nlohmann_json_j.is_string()) {
105 nlohmann_json_t.add_path(nlohmann_json_j.get<std::filesystem::path>());
106 }
else if (nlohmann_json_j.is_array()) {
107 for (
const auto& p : nlohmann_json_j) {
108 nlohmann_json_t.add_path(nlohmann_json_j.get<std::filesystem::path>());
void add_path(const std::filesystem::path &path)
std::unique_ptr< Impl > m_impl
static std::pair< std::filesystem::path, bool > try_resolving_path(const std::filesystem::path &potential_base, const std::filesystem::path &path)
std::vector< std::filesystem::path > get_paths() const
std::pair< std::filesystem::path, bool > resolve(const std::filesystem::path &path) const
PathResolver & operator=(PathResolver &&)
WMTK_NLOHMANN_JSON_FRIEND_TO_JSON_PROTOTYPE(PathResolver)
WMTK_NLOHMANN_JSON_FRIEND_FROM_JSON_PROTOTYPE(PathResolver)
std::vector< Simplex > make_unique(const Mesh &m, const std::vector< Simplex > &s)
std::pair< std::filesystem::path, bool > resolve(const std::filesystem::path &path) const
Impl & operator=(Impl &&)=default
std::vector< std::filesystem::path > m_paths
Impl & operator=(const Impl &)=default
Impl(const Impl &)=default
void add_path(const std::filesystem::path &path)