mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-03 08:46:19 +08:00
add rfl::enum_to_string and rfl::string_to_enum
This commit is contained in:
@@ -25,6 +25,23 @@ void test() {
|
||||
const auto circle = Circle{.radius = 2.0, .color = Color::green};
|
||||
|
||||
write_and_read(circle, R"({"radius":2.0,"color":"green"})");
|
||||
|
||||
auto mutable_circle = Circle{.radius = 2.0, .color = Color::green};
|
||||
if (auto color = rfl::string_to_enum<Color>("red"); color) {
|
||||
mutable_circle.color = *color;
|
||||
}
|
||||
write_and_read(mutable_circle, R"({"radius":2.0,"color":"red"})");
|
||||
|
||||
if (auto color = rfl::string_to_enum<Color>("bart"); color) {
|
||||
mutable_circle.color = *color;
|
||||
}
|
||||
write_and_read(mutable_circle, R"({"radius":2.0,"color":"red"})");
|
||||
|
||||
if (auto color = rfl::string_to_enum<Color>(rfl::enum_to_string(Color::blue));
|
||||
color) {
|
||||
mutable_circle.color = *color;
|
||||
}
|
||||
write_and_read(mutable_circle, R"({"radius":2.0,"color":"blue"})");
|
||||
}
|
||||
|
||||
} // namespace test_enum
|
||||
|
||||
Reference in New Issue
Block a user