Loading src/core/config/ConfigManager.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ using namespace allpix; /** * @throws ConfigFileUnavailableError If the main configuration file cannot be accessed */ ConfigManager::ConfigManager(std::string file_name, ConfigManager::ConfigManager(std::filesystem::path file_name, std::initializer_list<std::string> global, std::initializer_list<std::string> ignore) { // Check if the file exists Loading src/core/config/ConfigManager.hpp +2 −1 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ #ifndef ALLPIX_CONFIG_MANAGER_H #define ALLPIX_CONFIG_MANAGER_H #include <filesystem> #include <set> #include <string> #include <vector> Loading Loading @@ -40,7 +41,7 @@ namespace allpix { * @param global List of sections representing the global configuration (excluding the empty header section) * @param ignore List of sections that should be ignored */ explicit ConfigManager(std::string file_name, explicit ConfigManager(std::filesystem::path file_name, std::initializer_list<std::string> global = {}, std::initializer_list<std::string> ignore = {"Ignore"}); /** Loading src/core/config/ConfigReader.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ using namespace allpix; ConfigReader::ConfigReader() = default; ConfigReader::ConfigReader(std::istream& stream, std::string file_name) : ConfigReader() { ConfigReader::ConfigReader(std::istream& stream, std::filesystem::path file_name) : ConfigReader() { add(stream, std::move(file_name)); } Loading Loading @@ -96,7 +96,7 @@ std::pair<std::string, std::string> ConfigReader::parseKeyValue(std::string line * * The configuration is immediately parsed and all of its configurations are available after the functions returns. */ void ConfigReader::add(std::istream& stream, std::string file_name) { void ConfigReader::add(std::istream& stream, std::filesystem::path file_name) { LOG(TRACE) << "Parsing configuration file " << file_name; // Convert file name to absolute path (if given) Loading src/core/config/ConfigReader.hpp +3 −2 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ #ifndef ALLPIX_CONFIG_READER_H #define ALLPIX_CONFIG_READER_H #include <filesystem> #include <istream> #include <list> #include <map> Loading Loading @@ -38,7 +39,7 @@ namespace allpix { * @param stream Stream to read configuration from * @param file_name Name of the file related to the stream or empty if not linked to a file */ explicit ConfigReader(std::istream& stream, std::string file_name = ""); explicit ConfigReader(std::istream& stream, std::filesystem::path file_name = ""); /** * @brief Parse a line as key-value pair Loading @@ -52,7 +53,7 @@ namespace allpix { * @param stream Stream to read configuration from * @param file_name Name of the file related to the stream or empty if not linked to a file */ void add(std::istream&, std::string file_name = ""); void add(std::istream&, std::filesystem::path file_name = ""); /** * @brief Directly add a configuration object to the reader Loading src/core/config/Configuration.cpp +14 −16 Original line number Diff line number Diff line Loading @@ -39,7 +39,8 @@ void Configuration::AccessMarker::registerMarker(const std::string& key) { markers_.emplace(std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple()); } Configuration::Configuration(std::string name, std::string path) : name_(std::move(name)), path_(std::move(path)) {} Configuration::Configuration(std::string name, std::filesystem::path path) : name_(std::move(name)), path_(std::move(path)) {} bool Configuration::has(const std::string& key) const { return config_.find(key) != config_.cend(); Loading @@ -62,7 +63,7 @@ unsigned int Configuration::count(std::initializer_list<std::string> keys) const std::string Configuration::getName() const { return name_; } std::string Configuration::getFilePath() const { std::filesystem::path Configuration::getFilePath() const { return path_; } Loading @@ -88,7 +89,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 +101,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 +115,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,14 +131,11 @@ 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::filesystem::path path, bool canonicalize_path) const { // If not a absolute path, make it an absolute path if(path.front() != '/') { // Get base directory of config file std::string directory = path_.substr(0, path_.find_last_of('/')); // Set new path path = directory + "/" + path; if(!path.is_absolute()) { // Get base directory of config file and append the relative path path = path_.parent_path() / path; } // Normalize path only if we have to check if it exists Loading @@ -146,7 +144,7 @@ std::string Configuration::path_to_absolute(std::string path, bool canonicalize_ try { path = std::filesystem::canonical(path); } catch(std::filesystem::filesystem_error&) { throw std::invalid_argument("path " + path + " not found"); throw std::invalid_argument("path " + path.string() + " not found"); } } return path; Loading Loading
src/core/config/ConfigManager.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ using namespace allpix; /** * @throws ConfigFileUnavailableError If the main configuration file cannot be accessed */ ConfigManager::ConfigManager(std::string file_name, ConfigManager::ConfigManager(std::filesystem::path file_name, std::initializer_list<std::string> global, std::initializer_list<std::string> ignore) { // Check if the file exists Loading
src/core/config/ConfigManager.hpp +2 −1 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ #ifndef ALLPIX_CONFIG_MANAGER_H #define ALLPIX_CONFIG_MANAGER_H #include <filesystem> #include <set> #include <string> #include <vector> Loading Loading @@ -40,7 +41,7 @@ namespace allpix { * @param global List of sections representing the global configuration (excluding the empty header section) * @param ignore List of sections that should be ignored */ explicit ConfigManager(std::string file_name, explicit ConfigManager(std::filesystem::path file_name, std::initializer_list<std::string> global = {}, std::initializer_list<std::string> ignore = {"Ignore"}); /** Loading
src/core/config/ConfigReader.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ using namespace allpix; ConfigReader::ConfigReader() = default; ConfigReader::ConfigReader(std::istream& stream, std::string file_name) : ConfigReader() { ConfigReader::ConfigReader(std::istream& stream, std::filesystem::path file_name) : ConfigReader() { add(stream, std::move(file_name)); } Loading Loading @@ -96,7 +96,7 @@ std::pair<std::string, std::string> ConfigReader::parseKeyValue(std::string line * * The configuration is immediately parsed and all of its configurations are available after the functions returns. */ void ConfigReader::add(std::istream& stream, std::string file_name) { void ConfigReader::add(std::istream& stream, std::filesystem::path file_name) { LOG(TRACE) << "Parsing configuration file " << file_name; // Convert file name to absolute path (if given) Loading
src/core/config/ConfigReader.hpp +3 −2 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ #ifndef ALLPIX_CONFIG_READER_H #define ALLPIX_CONFIG_READER_H #include <filesystem> #include <istream> #include <list> #include <map> Loading Loading @@ -38,7 +39,7 @@ namespace allpix { * @param stream Stream to read configuration from * @param file_name Name of the file related to the stream or empty if not linked to a file */ explicit ConfigReader(std::istream& stream, std::string file_name = ""); explicit ConfigReader(std::istream& stream, std::filesystem::path file_name = ""); /** * @brief Parse a line as key-value pair Loading @@ -52,7 +53,7 @@ namespace allpix { * @param stream Stream to read configuration from * @param file_name Name of the file related to the stream or empty if not linked to a file */ void add(std::istream&, std::string file_name = ""); void add(std::istream&, std::filesystem::path file_name = ""); /** * @brief Directly add a configuration object to the reader Loading
src/core/config/Configuration.cpp +14 −16 Original line number Diff line number Diff line Loading @@ -39,7 +39,8 @@ void Configuration::AccessMarker::registerMarker(const std::string& key) { markers_.emplace(std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple()); } Configuration::Configuration(std::string name, std::string path) : name_(std::move(name)), path_(std::move(path)) {} Configuration::Configuration(std::string name, std::filesystem::path path) : name_(std::move(name)), path_(std::move(path)) {} bool Configuration::has(const std::string& key) const { return config_.find(key) != config_.cend(); Loading @@ -62,7 +63,7 @@ unsigned int Configuration::count(std::initializer_list<std::string> keys) const std::string Configuration::getName() const { return name_; } std::string Configuration::getFilePath() const { std::filesystem::path Configuration::getFilePath() const { return path_; } Loading @@ -88,7 +89,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 +101,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 +115,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,14 +131,11 @@ 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::filesystem::path path, bool canonicalize_path) const { // If not a absolute path, make it an absolute path if(path.front() != '/') { // Get base directory of config file std::string directory = path_.substr(0, path_.find_last_of('/')); // Set new path path = directory + "/" + path; if(!path.is_absolute()) { // Get base directory of config file and append the relative path path = path_.parent_path() / path; } // Normalize path only if we have to check if it exists Loading @@ -146,7 +144,7 @@ std::string Configuration::path_to_absolute(std::string path, bool canonicalize_ try { path = std::filesystem::canonical(path); } catch(std::filesystem::filesystem_error&) { throw std::invalid_argument("path " + path + " not found"); throw std::invalid_argument("path " + path.string() + " not found"); } } return path; Loading