mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-06 10:46:18 +08:00
Added more features to the automated field name retrieval
This commit is contained in:
+23
-22
@@ -7,32 +7,33 @@
|
||||
|
||||
#include "write_and_read.hpp"
|
||||
|
||||
void test_array() {
|
||||
std::cout << "test_array" << std::endl;
|
||||
namespace test_array {
|
||||
|
||||
struct Person {
|
||||
rfl::Field<"firstName", std::string> first_name;
|
||||
rfl::Field<"lastName", std::string> last_name = "Simpson";
|
||||
rfl::Field<"children", std::unique_ptr<std::array<Person, 3>>>
|
||||
children = rfl::default_value;
|
||||
};
|
||||
struct Person {
|
||||
rfl::Rename<"firstName", std::string> first_name;
|
||||
rfl::Rename<"lastName", std::string> last_name = "Simpson";
|
||||
std::unique_ptr<std::array<Person, 3>> children = nullptr;
|
||||
};
|
||||
|
||||
auto bart = Person{.first_name = "Bart"};
|
||||
void test() {
|
||||
std::cout << "test_array" << std::endl;
|
||||
|
||||
auto lisa = Person{.first_name = "Lisa"};
|
||||
auto bart = Person{.first_name = "Bart"};
|
||||
|
||||
auto maggie = Person{.first_name = "Maggie"};
|
||||
auto lisa = Person{.first_name = "Lisa"};
|
||||
|
||||
const auto homer = Person{
|
||||
.first_name = "Homer",
|
||||
.children =
|
||||
std::make_unique<std::array<Person, 3>>(std::array<Person, 3>{
|
||||
std::move(bart), std::move(lisa), std::move(maggie)})};
|
||||
auto maggie = Person{.first_name = "Maggie"};
|
||||
|
||||
write_and_read(
|
||||
homer,
|
||||
"{\"firstName\":\"Homer\",\"lastName\":\"Simpson\",\"children\":[{"
|
||||
"\"firstName\":\"Bart\",\"lastName\":\"Simpson\"},{"
|
||||
"\"firstName\":\"Lisa\",\"lastName\":\"Simpson\"},{"
|
||||
"\"firstName\":\"Maggie\",\"lastName\":\"Simpson\"}]}");
|
||||
const auto homer = Person{
|
||||
.first_name = "Homer",
|
||||
.children = std::make_unique<std::array<Person, 3>>(std::array<Person, 3>{
|
||||
std::move(bart), std::move(lisa), std::move(maggie)})};
|
||||
|
||||
write_and_read(
|
||||
homer,
|
||||
"{\"firstName\":\"Homer\",\"lastName\":\"Simpson\",\"children\":[{"
|
||||
"\"firstName\":\"Bart\",\"lastName\":\"Simpson\"},{"
|
||||
"\"firstName\":\"Lisa\",\"lastName\":\"Simpson\"},{"
|
||||
"\"firstName\":\"Maggie\",\"lastName\":\"Simpson\"}]}");
|
||||
}
|
||||
} // namespace test_array
|
||||
|
||||
Reference in New Issue
Block a user