1 #ifndef DATAIO_FILESYSTEM_HH
2 #define DATAIO_FILESYSTEM_HH
8 #include "../core/exceptions.hh"
9 #include "../core/types.hh"
43 using namespace std::string_literals;
45 if (path.empty() or path.substr(0, 1) !=
"~"s) {
49 const std::string HOME = std::getenv(
"HOME");
51 throw std::invalid_argument(
52 "Cannot expand path because the environment variable 'HOME' was "
53 "not set! Use an absolute path to specify the given path: "
57 return HOME + path.substr(1, std::string::npos);
74 using std::filesystem::path;
75 using std::filesystem::current_path;
77 const path filename =
expanduser(get_as<std::string>(
"filename", cfg));
79 path p = current_path();
80 if (cfg[
"base_dir"]) {
84 p.append(
expanduser(get_as<std::string>(
"base_dir", cfg)));
YAML::Node Config
Type of a variadic dictionary-like data structure used throughout Utopia.
Definition: types.hh:71
std::string expanduser(const std::string &path)
Expands a path with a leading ~ character into an absolute path.
Definition: filesystem.hh:42
std::string get_abs_filepath(const Config &cfg)
Extracts an absolute file path from a configuration.
Definition: filesystem.hh:73