| 32 | #include <array> |
| 33 | |
| 34 | bool Generators::DeepCopy(const GeneratorInfo &info, TemplateEngine &templateEngine) { |
| 35 | // Final stream |
| 36 | std::stringstream ss; |
| 37 | |
| 38 | // Handle all objects |
| 39 | for (auto&& object : info.deepCopy["objects"]) { |
| 40 | std::string name = object.get<std::string>(); |
| 41 | |
| 42 | std::string copyName = GetPrettyName(name) + "DeepCopy"; |
| 43 | |
| 44 | // Begin object |
| 45 | ss << "struct " << copyName << " {\n"; |
| 46 | |
| 47 | // Default constructor |
| 48 | ss << "\t" << copyName << "() = default;\n"; |
| 49 | |
| 50 | // Destructor |
| 51 | ss << "\t~" << copyName << "();\n\n"; |
| 52 | |
| 53 | // Deep copy constructor |
| 54 | ss << "\tvoid DeepCopy(const Allocators& allocators, const " << name << "& source);\n\n"; |
| 55 | |
| 56 | // Deep copy accessor |
| 57 | ss << "\t" << name << "* operator->() {\n"; |
| 58 | ss << "\t\tASSERT(valid, \"Object not created\");\n"; |
| 59 | ss << "\t\treturn &desc;\n"; |
| 60 | ss << "\t}\n\n"; |
| 61 | |
| 62 | // Creation info |
| 63 | ss << "\t" << name << " desc{};\n"; |
| 64 | |
| 65 | // Allocators |
| 66 | ss << "\tAllocators allocators;\n"; |
| 67 | |
| 68 | // Indirection blob |
| 69 | ss << "\tuint8_t* blob{nullptr};\n"; |
| 70 | |
| 71 | // Indirection size |
| 72 | ss << "\tuint64_t length{0u};\n"; |
| 73 | |
| 74 | // Copy validity |
| 75 | ss << "\tbool valid{false};\n"; |
| 76 | |
| 77 | // End object |
| 78 | ss << "};\n\n"; |
| 79 | } |
| 80 | |
| 81 | // Handle all serializers |
| 82 | for (auto&& object : info.deepCopy["serializers"]) { |
| 83 | std::string name = object.get<std::string>(); |
| 84 | ss << "size_t Serialize(const " << name << "& source, " << name << "& dest, void* blob);\n"; |
| 85 | } |
| 86 | |
| 87 | // Instantiate template |
| 88 | if (!templateEngine.Substitute("$OBJECTS", ss.str().c_str())) { |
| 89 | std::cerr << "Bad template, failed to substitute $OBJECTS" << std::endl; |
| 90 | return false; |
| 91 | } |
no test coverage detected