mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-03 16:56:17 +08:00
For a long time, tomlplusplus did generate a config.cmake file, which made it difficult to use on vcpkg. As a fix, we switched to toml11. But this has now finally been added to vcpkg, and since tomlplusplus is faster than toml11 in terms of compile time and runtime, we are changing back.
53 lines
1.4 KiB
C++
53 lines
1.4 KiB
C++
#ifndef RFL_TOML_READ_HPP_
|
|
#define RFL_TOML_READ_HPP_
|
|
|
|
#include <istream>
|
|
#include <string>
|
|
#include <toml++/toml.hpp>
|
|
|
|
#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 <class T, class... Ps>
|
|
auto read(InputVarType _var) {
|
|
const auto r = Reader();
|
|
using ProcessorsType = Processors<Ps...>;
|
|
static_assert(!ProcessorsType::no_field_names_,
|
|
"The NoFieldNames processor is not supported for BSON, XML, "
|
|
"TOML, or YAML.");
|
|
return Parser<T, ProcessorsType>::read(r, _var);
|
|
}
|
|
|
|
/// Reads a TOML string.
|
|
template <class T, class... Ps>
|
|
Result<internal::wrap_in_rfl_array_t<T>> read(const std::string& _toml_str) {
|
|
auto table = ::toml::parse(_toml_str);
|
|
return read<T, Ps...>(&table);
|
|
}
|
|
|
|
/// Reads a TOML string.
|
|
template <class T, class... Ps>
|
|
Result<internal::wrap_in_rfl_array_t<T>> read(
|
|
const std::string_view _toml_str) {
|
|
return read<T, Ps...>(std::string(_toml_str));
|
|
}
|
|
|
|
/// Parses an object from a stringstream.
|
|
template <class T, class... Ps>
|
|
auto read(std::istream& _stream) {
|
|
const auto toml_str = std::string(std::istreambuf_iterator<char>(_stream),
|
|
std::istreambuf_iterator<char>());
|
|
return read<T, Ps...>(toml_str);
|
|
}
|
|
|
|
} // namespace rfl::toml
|
|
|
|
#endif
|