#ifndef RFL_TOML_READ_HPP_ #define RFL_TOML_READ_HPP_ #include #include #include #include #include "../Processors.hpp" #include "../internal/wrap_in_rfl_array_t.hpp" #include "Parser.hpp" #include "Reader.hpp" namespace rfl::toml { using InputVarType = typename Reader::InputVarType; /// Parses an object from a TOML var. template auto read(InputVarType _var) { const auto r = Reader(); using ProcessorsType = Processors; static_assert(!ProcessorsType::no_field_names_, "The NoFieldNames processor is not supported for BSON, XML, " "TOML, or YAML."); return Parser::read(r, _var); } /// Reads a TOML string. template Result> read( const std::string_view _toml_str) noexcept { #if TOML_EXCEPTIONS try { auto table = ::toml::parse(_toml_str); return read(&table); } catch (const std::exception& e) { return error(e.what()); } #else auto result = ::toml::parse(_toml_str); if (!result) { return error(std::string(result.error().description())); } return read(&result.table()); #endif } /// Parses an object from a stringstream. template auto read(std::istream& _stream) { const auto toml_str = std::string(std::istreambuf_iterator(_stream), std::istreambuf_iterator()); return read(toml_str); } } // namespace rfl::toml #endif