// An absolute path is composed according to the table in [fs.op.absolute]. path absolute(const path& p, const path& base) { auto root_name = p.root_name(); auto root_dir = p.root_directory(); if (!root_name.empty() && !root_dir.empty()) return p; auto abs_base = base.is_absolute() ? base : absolute(base); /* !has_root_name && !has_root_dir */ if (root_name.empty() && root_dir.empty()) { return abs_base / p; } else if (!root_name.empty()) /* has_root_name && !has_root_dir */ { return root_name / abs_base.root_directory() / abs_base.relative_path() / p.relative_path(); } else /* !has_root_name && has_root_dir */ { if (abs_base.has_root_name()) return abs_base.root_name() / p; // else p is absolute, return outside of block } return p; }
path canonicalOrAbsolute(const path& p, const path& base = boost::filesystem::current_path()) { path result; if (p.is_absolute()){ result = p; } else { result = boost::filesystem::absolute(p, base); } if (exists(result)){ result = boost::filesystem::canonical(result); } return result; }
path path::operator/(const path & other) const { if(other.is_absolute() || empty() || (is_dot() && !other.empty())) { return other; } else if(other.empty() || other.is_dot()) { return *this; } else if(other.is_up()) { return resolve(*this, other); } else { path result = *this; if(result.pathstr[result.pathstr.length() - 1] != dir_sep) { result.pathstr += dir_sep; } result.pathstr += other.pathstr; return result; } }
path GetResourceAbspath(const path &relpath)const { if (relpath.is_absolute()) { return relpath; } for (const auto &dir : m_searchPaths) { const path abspath = absolute(relpath, dir); if (exists(abspath)) { return abspath; } } throw std::runtime_error("Resource not found: " + relpath.generic_string()); }