Re:Plywood: A New Cross-Platform Open Source C++ Framework
by jcranmer on Tuesday May 26, 2020 @03:38PM
(#23315529)
The standard serialization case is basically, I have this definition:
struct foo {
int a;
int b;
const char *c;
};
and I want to automatically generate this function: void serialize_foo(foo &obj, ostream &out) {
out.serialize_int(obj.a);
out.serialize_int(obj.b);
out.serialize_string(obj.c);
}
With some sort of reflection, you can automatically build that method with something like this: void emit_serialize_method(class_definition &clazz) {
emit("void serialize_foo(" + clazz.name + "&obj, ostream &out) {");
for (auto &field : clazz.fields) {
emit(" out.serialize_" + field.type + "(obj." + field.name + ");");
}
emit("}");
}
(syntax of course varies).
I've read simliar statements before but I don't think I understand how it helps.