feat: add std::filesystem::path support

This commit is contained in:
ToruNiina 2020-06-05 19:43:23 +09:00
parent 4d0ed847f9
commit 2963d9a25b

View File

@ -12,6 +12,13 @@
#include <sstream>
#include <cstring>
#if __cplusplus >= 201703L
#if __has_include(<filesystem>)
#define TOML11_HAS_STD_FILESYSTEM
#include <filesystem>
#endif // has_include(<string_view>)
#endif // cplusplus >= C++17
namespace toml
{
namespace detail
@ -2094,5 +2101,21 @@ basic_value<Comment, Table, Array> parse(const std::string& fname)
return parse<Comment, Table, Array>(ifs, fname);
}
#ifdef TOML11_HAS_STD_FILESYSTEM
template<typename Comment = ::toml::discard_comments,
template<typename ...> class Table = std::unordered_map,
template<typename ...> class Array = std::vector>
basic_value<Comment, Table, Array> 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<Comment, Table, Array>(ifs, fname);
}
#endif // TOML11_HAS_STD_FILESYSTEM
} // toml
#endif// TOML11_PARSER_HPP