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

Utils: add string conversion handler for filesystem paths

parent 6c262b7f
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -57,6 +57,13 @@ std::string allpix::from_string_impl(std::string str, type_tag<std::string>) {
    return from_string_helper(str);
}

/**
 * First parse as normal string and then constrcut path from it.
 */
std::filesystem::path allpix::from_string_impl(std::string str, type_tag<std::filesystem::path>) {
    return std::filesystem::path(from_string<std::string>(str));
}

/**
 * Both numerical (0, 1) and textual representations ("false", "true") are supported for booleans. No enclosing quotation
 * marks should be used.
+9 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#define ALLPIX_TEXT_H

#include <cctype>
#include <filesystem>
#include <sstream>
#include <string>
#include <type_traits>
@@ -71,6 +72,14 @@ namespace allpix {
     * @throws std::invalid_argument If string without enclosing quotation marks, but more data after whitespace is found
     */
    std::string from_string_impl(std::string str, type_tag<std::string>);
    /**
     * @ingroup StringConversions
     * @brief Conversion handler for filesystem paths
     * @throws std::invalid_argument If no closing quotation mark as last character after an opening quotation mark
     * @throws std::invalid_argument If string without enclosing quotation marks, but more data after whitespace is found
     */
    std::filesystem::path from_string_impl(std::string str, type_tag<std::filesystem::path>);

    /**
     * @ingroup StringConversions
     * @brief Conversion handler for booleans