13 #include "knowrob/URI.h"
14 #include "knowrob/Logger.h"
25 : path_(std::move(path)),
26 protocol_(std::move(protocol)),
27 host_(std::move(host)),
32 URI::URI(
const boost::property_tree::ptree &property_tree) {
34 path_ = property_tree.get(
"path",
"/");
36 port_ = property_tree.get_optional<
int>(
"port");
55 auto env_drive = getenv(
"HOMEDRIVE");
56 auto env_path = getenv(
"HOMEPATH");
57 if (env_drive && env_path) {
60 KB_WARN(
"Could not determine home directory");
64 auto env_home = getenv(
"HOME");
68 struct passwd *pw = getpwuid(getuid());
72 KB_WARN(
"Could not determine home directory");
80 static std::filesystem::path projectPath(KNOWROB_SOURCE_DIR);
81 static std::filesystem::path installPath(KNOWROB_INSTALL_PREFIX);
82 static std::optional<std::string> homePath(
getHomePath());
84 std::filesystem::path filePath(uriString);
85 if (!exists(filePath)) {
86 std::vector<std::filesystem::path> possiblePaths;
88 possiblePaths.push_back(projectPath / filePath);
89 possiblePaths.push_back(projectPath /
"src" / filePath);
92 possiblePaths.push_back(std::filesystem::path(homePath.value()) /
".knowrob" / filePath);
95 possiblePaths.push_back(installPath /
"share" /
"knowrob" / filePath);
96 possiblePaths.push_back(installPath /
"lib" /
"knowrob" / filePath);
98 for (
const auto &p: possiblePaths) {
99 if (exists(p))
return p.u8string();
boost::optional< int > port_
static std::optional< std::string > getHomePath(void)
boost::optional< std::string > host_
boost::optional< std::string > protocol_
static std::string resolve(const std::string_view &uriString)
URI(std::string_view path)