summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-08-05 12:19:35 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-08-05 12:19:35 +0100
commit8235ae6999b4fe148805651bd7be6ee667cbb8c2 (patch)
tree72e3cc606c0cbdcbfddcb554bd2682269ba4c0ad
parentReformat with new clang-format (diff)
downloadslicer-8235ae6999b4fe148805651bd7be6ee667cbb8c2.tar.bz2
slicer-8235ae6999b4fe148805651bd7be6ee667cbb8c2.tar.xz
slicer-8235ae6999b4fe148805651bd7be6ee667cbb8c2.zip
Refactor JsonSerializer::ModelTreeIterate with no pointer copy
-rw-r--r--slicer/json/serializer.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/slicer/json/serializer.cpp b/slicer/json/serializer.cpp
index 227f3c9..0c993c4 100644
--- a/slicer/json/serializer.cpp
+++ b/slicer/json/serializer.cpp
@@ -267,17 +267,20 @@ namespace Slicer {
}
case ModelPartType::Complex:
if (mp->HasValue()) {
- json::Object nn;
+ auto oec = [n, &name](const auto & lmp) {
+ auto & obj = std::get<json::Object>(*n).emplace(name, json::Object {}).first->second;
+ lmp->OnEachChild([&obj](auto && PH1, auto && PH2, auto &&) {
+ return JsonSerializer::ModelTreeIterate(&obj, PH1, PH2);
+ });
+ return &std::get<json::Object>(obj);
+ };
if (auto typeIdName = mp->GetTypeIdProperty()) {
if (auto typeId = mp->GetTypeId()) {
- nn.insert({*typeIdName, *typeId});
- mp = mp->GetSubclassModelPart(*typeId);
+ oec(mp->GetSubclassModelPart(*typeId))->emplace(*typeIdName, *typeId);
+ return;
}
}
- mp->OnEachChild([capture0 = &std::get<json::Object>(*n).insert({name, nn}).first->second](
- auto && PH1, auto && PH2, auto &&) {
- return JsonSerializer::ModelTreeIterate(capture0, PH1, PH2);
- });
+ oec(mp);
}
break;
case ModelPartType::Sequence: