Commit d8284603 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Move ConfigManager & ConfigReader to std::filesystem

parent 7b01c10f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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
+2 −1
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@
#ifndef ALLPIX_CONFIG_MANAGER_H
#define ALLPIX_CONFIG_MANAGER_H

#include <filesystem>
#include <set>
#include <string>
#include <vector>
@@ -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"});
        /**
+2 −2
Original line number Diff line number Diff line
@@ -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));
}

@@ -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)
+3 −2
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@
#ifndef ALLPIX_CONFIG_READER_H
#define ALLPIX_CONFIG_READER_H

#include <filesystem>
#include <istream>
#include <list>
#include <map>
@@ -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
@@ -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
+2 −1
Original line number Diff line number Diff line
@@ -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