Loading src/core/config/Configuration.cpp +7 −7 Original line number Diff line number Diff line Loading @@ -88,7 +88,7 @@ std::string Configuration::getText(const std::string& key, const std::string& de * For a relative path the absolute path of the configuration file is preprended. Absolute paths are not changed. */ // TODO [doc] Document canonicalizing behaviour std::string Configuration::getPath(const std::string& key, bool check_exists) const { std::filesystem::path Configuration::getPath(const std::string& key, bool check_exists) const { try { return path_to_absolute(get<std::string>(key), check_exists); } catch(std::invalid_argument& e) { Loading @@ -100,7 +100,7 @@ std::string Configuration::getPath(const std::string& key, bool check_exists) co * * For a relative path the absolute path of the configuration file is prepended. Absolute paths are not changed. */ std::string std::filesystem::path Configuration::getPathWithExtension(const std::string& key, const std::string& extension, bool check_exists) const { try { return path_to_absolute(std::filesystem::path(get<std::string>(key)).replace_extension(extension), check_exists); Loading @@ -114,13 +114,13 @@ Configuration::getPathWithExtension(const std::string& key, const std::string& e * For all relative paths the absolute path of the configuration file is preprended. Absolute paths are not changed. */ // TODO [doc] Document canonicalizing behaviour std::vector<std::string> Configuration::getPathArray(const std::string& key, bool check_exists) const { std::vector<std::string> path_array = getArray<std::string>(key); std::vector<std::filesystem::path> Configuration::getPathArray(const std::string& key, bool check_exists) const { std::vector<std::filesystem::path> path_array; // Convert all paths to absolute try { for(auto& path : path_array) { path = path_to_absolute(path, check_exists); for(auto& path : getArray<std::string>(key)) { path_array.emplace_back(path_to_absolute(path, check_exists)); } return path_array; } catch(std::invalid_argument& e) { Loading @@ -130,7 +130,7 @@ std::vector<std::string> Configuration::getPathArray(const std::string& key, boo /** * @throws std::invalid_argument If the path does not exists */ std::string Configuration::path_to_absolute(std::string path, bool canonicalize_path) const { std::filesystem::path Configuration::path_to_absolute(std::string path, bool canonicalize_path) const { // If not a absolute path, make it an absolute path if(path.front() != '/') { // Get base directory of config file Loading src/core/config/Configuration.hpp +6 −4 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ #define ALLPIX_CONFIGURATION_H #include <atomic> #include <filesystem> #include <map> #include <memory> #include <stdexcept> Loading Loading @@ -193,7 +194,7 @@ namespace allpix { * @param check_exists If the file should be checked for existence (if yes always returns a canonical path) * @return Absolute path to a file */ std::string getPath(const std::string& key, bool check_exists = false) const; std::filesystem::path getPath(const std::string& key, bool check_exists = false) const; /** * @brief Get absolute path to file with paths relative to the configuration Loading @@ -202,7 +203,8 @@ namespace allpix { * @param check_exists If the file should be checked for existence (if yes always returns a canonical path) * @return Absolute path to a file */ std::string getPathWithExtension(const std::string& key, const std::string& extension, bool check_exists) const; std::filesystem::path getPathWithExtension(const std::string& key, const std::string& extension, bool check_exists) const; /** * @brief Get array of absolute paths to files with paths relative to the configuration * @param key Key to get path of Loading @@ -210,7 +212,7 @@ namespace allpix { * @return List of absolute path to all the requested files */ // TODO [doc] Provide second template parameter to specify the vector type to return it in std::vector<std::string> getPathArray(const std::string& key, bool check_exists = false) const; std::vector<std::filesystem::path> getPathArray(const std::string& key, bool check_exists = false) const; /** * @brief Set value for a key in a given type Loading Loading @@ -322,7 +324,7 @@ namespace allpix { * @param path Path to make absolute (if it is not already absolute) * @param canonicalize_path If the path should be canonicalized (throws an error if the path does not exist) */ std::string path_to_absolute(std::string path, bool canonicalize_path) const; std::filesystem::path path_to_absolute(std::string path, bool canonicalize_path) const; /** * @brief Node in a parse tree Loading Loading
src/core/config/Configuration.cpp +7 −7 Original line number Diff line number Diff line Loading @@ -88,7 +88,7 @@ std::string Configuration::getText(const std::string& key, const std::string& de * For a relative path the absolute path of the configuration file is preprended. Absolute paths are not changed. */ // TODO [doc] Document canonicalizing behaviour std::string Configuration::getPath(const std::string& key, bool check_exists) const { std::filesystem::path Configuration::getPath(const std::string& key, bool check_exists) const { try { return path_to_absolute(get<std::string>(key), check_exists); } catch(std::invalid_argument& e) { Loading @@ -100,7 +100,7 @@ std::string Configuration::getPath(const std::string& key, bool check_exists) co * * For a relative path the absolute path of the configuration file is prepended. Absolute paths are not changed. */ std::string std::filesystem::path Configuration::getPathWithExtension(const std::string& key, const std::string& extension, bool check_exists) const { try { return path_to_absolute(std::filesystem::path(get<std::string>(key)).replace_extension(extension), check_exists); Loading @@ -114,13 +114,13 @@ Configuration::getPathWithExtension(const std::string& key, const std::string& e * For all relative paths the absolute path of the configuration file is preprended. Absolute paths are not changed. */ // TODO [doc] Document canonicalizing behaviour std::vector<std::string> Configuration::getPathArray(const std::string& key, bool check_exists) const { std::vector<std::string> path_array = getArray<std::string>(key); std::vector<std::filesystem::path> Configuration::getPathArray(const std::string& key, bool check_exists) const { std::vector<std::filesystem::path> path_array; // Convert all paths to absolute try { for(auto& path : path_array) { path = path_to_absolute(path, check_exists); for(auto& path : getArray<std::string>(key)) { path_array.emplace_back(path_to_absolute(path, check_exists)); } return path_array; } catch(std::invalid_argument& e) { Loading @@ -130,7 +130,7 @@ std::vector<std::string> Configuration::getPathArray(const std::string& key, boo /** * @throws std::invalid_argument If the path does not exists */ std::string Configuration::path_to_absolute(std::string path, bool canonicalize_path) const { std::filesystem::path Configuration::path_to_absolute(std::string path, bool canonicalize_path) const { // If not a absolute path, make it an absolute path if(path.front() != '/') { // Get base directory of config file Loading
src/core/config/Configuration.hpp +6 −4 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ #define ALLPIX_CONFIGURATION_H #include <atomic> #include <filesystem> #include <map> #include <memory> #include <stdexcept> Loading Loading @@ -193,7 +194,7 @@ namespace allpix { * @param check_exists If the file should be checked for existence (if yes always returns a canonical path) * @return Absolute path to a file */ std::string getPath(const std::string& key, bool check_exists = false) const; std::filesystem::path getPath(const std::string& key, bool check_exists = false) const; /** * @brief Get absolute path to file with paths relative to the configuration Loading @@ -202,7 +203,8 @@ namespace allpix { * @param check_exists If the file should be checked for existence (if yes always returns a canonical path) * @return Absolute path to a file */ std::string getPathWithExtension(const std::string& key, const std::string& extension, bool check_exists) const; std::filesystem::path getPathWithExtension(const std::string& key, const std::string& extension, bool check_exists) const; /** * @brief Get array of absolute paths to files with paths relative to the configuration * @param key Key to get path of Loading @@ -210,7 +212,7 @@ namespace allpix { * @return List of absolute path to all the requested files */ // TODO [doc] Provide second template parameter to specify the vector type to return it in std::vector<std::string> getPathArray(const std::string& key, bool check_exists = false) const; std::vector<std::filesystem::path> getPathArray(const std::string& key, bool check_exists = false) const; /** * @brief Set value for a key in a given type Loading Loading @@ -322,7 +324,7 @@ namespace allpix { * @param path Path to make absolute (if it is not already absolute) * @param canonicalize_path If the path should be canonicalized (throws an error if the path does not exist) */ std::string path_to_absolute(std::string path, bool canonicalize_path) const; std::filesystem::path path_to_absolute(std::string path, bool canonicalize_path) const; /** * @brief Node in a parse tree Loading