From 2963d9a25b47c8496e757f48694bcac223cf68b0 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Fri, 5 Jun 2020 19:43:23 +0900 Subject: [PATCH] feat: add std::filesystem::path support --- toml/parser.hpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/toml/parser.hpp b/toml/parser.hpp index 80fe704..62900ee 100644 --- a/toml/parser.hpp +++ b/toml/parser.hpp @@ -12,6 +12,13 @@ #include #include +#if __cplusplus >= 201703L +#if __has_include() +#define TOML11_HAS_STD_FILESYSTEM +#include +#endif // has_include() +#endif // cplusplus >= C++17 + namespace toml { namespace detail @@ -2094,5 +2101,21 @@ basic_value parse(const std::string& fname) return parse(ifs, fname); } +#ifdef TOML11_HAS_STD_FILESYSTEM +template class Table = std::unordered_map, + template class Array = std::vector> +basic_value parse(const std::filesystem::path& fpath) +{ + std::ifstream ifs(fpath, std::ios_base::binary); + if(!ifs.good()) + { + throw std::runtime_error("toml::parse: file open error -> " + + fpath.string()); + } + return parse(ifs, fname); +} +#endif // TOML11_HAS_STD_FILESYSTEM + } // toml #endif// TOML11_PARSER_HPP