mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-07 03:06:18 +08:00
This commit is contained in:
@@ -88,10 +88,14 @@ class Writer {
|
||||
const T& _var) const noexcept {
|
||||
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>() ||
|
||||
std::is_same<std::remove_cvref_t<T>, bool>() ||
|
||||
std::is_floating_point<std::remove_cvref_t<T>>() ||
|
||||
std::is_same<std::remove_cvref_t<T>,
|
||||
std::remove_cvref_t<decltype(YAML::Null)>>()) {
|
||||
(*out_) << YAML::Key << _name.data() << YAML::Value << _var;
|
||||
} else if constexpr (std::is_floating_point<std::remove_cvref_t<T>>()) {
|
||||
// std::to_string is necessary to ensure that floating point values are
|
||||
// always written as floats.
|
||||
(*out_) << YAML::Key << _name.data() << YAML::Value
|
||||
<< std::to_string(_var);
|
||||
} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
|
||||
(*out_) << YAML::Key << _name.data() << YAML::Value
|
||||
<< static_cast<int64_t>(_var);
|
||||
@@ -103,7 +107,20 @@ class Writer {
|
||||
|
||||
template <class T>
|
||||
OutputVarType insert_value(const T& _var) const noexcept {
|
||||
(*out_) << _var;
|
||||
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>() ||
|
||||
std::is_same<std::remove_cvref_t<T>, bool>() ||
|
||||
std::is_same<std::remove_cvref_t<T>,
|
||||
std::remove_cvref_t<decltype(YAML::Null)>>()) {
|
||||
(*out_) << _var;
|
||||
} else if constexpr (std::is_floating_point<std::remove_cvref_t<T>>()) {
|
||||
// std::to_string is necessary to ensure that floating point values are
|
||||
// always written as floats.
|
||||
(*out_) << std::to_string(_var);
|
||||
} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
|
||||
(*out_) << static_cast<int64_t>(_var);
|
||||
} else {
|
||||
static_assert(rfl::always_false_v<T>, "Unsupported type.");
|
||||
}
|
||||
return OutputVarType{};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user