mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-02 16:16:19 +08:00
@@ -61,9 +61,10 @@ struct Reader {
|
||||
try {
|
||||
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_integral<std::remove_cvref_t<T>>()) {
|
||||
std::is_floating_point<std::remove_cvref_t<T>>()) {
|
||||
return _var.node_.as<std::remove_cvref_t<T>>();
|
||||
} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
|
||||
return static_cast<T>(_var.node_.as<std::remove_cvref_t<int64_t>>());
|
||||
} else {
|
||||
static_assert(rfl::always_false_v<T>, "Unsupported type.");
|
||||
}
|
||||
|
||||
@@ -86,7 +86,18 @@ class Writer {
|
||||
template <class T>
|
||||
OutputVarType insert_value(const std::string_view& _name,
|
||||
const T& _var) const noexcept {
|
||||
(*out_) << YAML::Key << _name.data() << YAML::Value << _var;
|
||||
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_integral<std::remove_cvref_t<T>>()) {
|
||||
(*out_) << YAML::Key << _name.data() << YAML::Value
|
||||
<< static_cast<int64_t>(_var);
|
||||
} else {
|
||||
static_assert(rfl::always_false_v<T>, "Unsupported type.");
|
||||
}
|
||||
return OutputVarType{};
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ struct Person {
|
||||
std::vector<Person> children;
|
||||
};
|
||||
|
||||
TEST(bson, test_snake_case_to_pascal_case) {
|
||||
TEST(yaml, test_snake_case_to_pascal_case) {
|
||||
const auto bart = Person{
|
||||
.first_name = "Bart", .last_name = "Simpson", .birthday = "1987-04-19"};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user