Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made sure uint8_t is properly handled by YAML; #270 #311

Merged
merged 2 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions include/rfl/yaml/Reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down
13 changes: 12 additions & 1 deletion include/rfl/yaml/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
}

Expand Down
2 changes: 1 addition & 1 deletion tests/yaml/test_snake_case_to_pascal_case.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"};

Expand Down
Loading