5namespace fs = std::filesystem;
8std::pair<std::filesystem::path, bool> PathResolver::try_resolving_path(
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;
55PathResolver::PathResolver()
59PathResolver::PathResolver(
const std::filesystem::path& path)
60 : m_impl(
std::make_unique<
Impl>())
66 : m_impl(
std::make_unique<
Impl>(*o.m_impl))
74PathResolver::~PathResolver() =
default;
77void PathResolver::clear_paths()
81void PathResolver::add_path(
const std::filesystem::path& path)
86std::pair<std::filesystem::path, bool> PathResolver::resolve(
87 const std::filesystem::path& path)
const
89 return m_impl->resolve(path);
92std::vector<std::filesystem::path> PathResolver::get_paths()
const
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>());
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)
#define WMTK_NLOHMANN_JSON_FRIEND_TO_JSON_PROTOTYPE(Type)
#define WMTK_NLOHMANN_JSON_FRIEND_FROM_JSON_PROTOTYPE(Type)
std::vector< std::filesystem::path > m_paths
Impl(const Impl &)=default
Impl & operator=(const Impl &)=default
Impl & operator=(Impl &&)=default
void add_path(const std::filesystem::path &path)
std::pair< std::filesystem::path, bool > resolve(const std::filesystem::path &path) const