MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / writeSource

Function writeSource

tools/code_generators/gamestate_serialize_gen/main.cpp:46–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44}
45
46void writeSource(std::ofstream &out, const StateDefinition &state)
47{
48 out << "// GENERATED SOURCE - generated by GamestateSerializeGen - do not modify directly\n\n";
49 out << "#include \"framework/serialization/serialize.h\"\n";
50 out << "#include \"game/state/gamestate_serialize.h\"\n";
51 out << "#include \"game/state/gamestate_serialize_generated.h\"\n\n";
52
53 out << "namespace OpenApoc {\n\n";
54
55 for (auto &object : state.objects)
56 {
57 if (object.external == true)
58 continue;
59 out << "inline void serializeIn(const GameState *, SerializationNode* node, " << object.name
60 << " &obj);\n";
61 out << "inline void serializeOut(SerializationNode* node, const " << object.name
62 << " &obj, const " << object.name << " &ref);\n";
63 out << "inline bool operator==(const " << object.name << " &a, const " << object.name
64 << " &b);\n";
65 out << "inline bool operator!=(const " << object.name << " &a, const " << object.name
66 << " &b);\n\n";
67 }
68
69 for (auto &e : state.enums)
70 {
71 if (e.external == true)
72 continue;
73 out << "inline void serializeIn(const GameState *, SerializationNode* node, " << e.name
74 << " &val);\n";
75 out << "inline void serializeOut(SerializationNode* node, const " << e.name
76 << " &val, const " << e.name << " &ref);\n";
77 }
78 for (auto &object : state.objects)
79 {
80 if (object.external == false)
81 out << "inline\n";
82 out << "void serializeIn(const GameState *state [[maybe_unused]], SerializationNode* node, "
83 << object.name << " &obj [[maybe_unused]])\n{\n";
84
85 out << "\tif (!node) return;\n";
86
87 for (auto &member : object.members)
88 {
89 std::string serializeFn;
90 std::string newNodeFn;
91 switch (member.second.type)
92 {
93 case NodeType::Normal:
94 serializeFn = "serializeIn";
95 newNodeFn = "getNode";
96 break;
97 case NodeType::Section:
98 serializeFn = "serializeIn";
99 newNodeFn = "getSection";
100 break;
101 case NodeType::SectionMap:
102 serializeFn = "serializeInSectionMap";
103 newNodeFn = "getSection";

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected