summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-08-05 12:33:31 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-08-05 12:33:31 +0100
commitb3f01efdec0a74dc353e14ce278e9bdabb51793f (patch)
tree0ad70be0913f3b18e9bd51db781956a40adab030
parentRefactor JsonSerializer::ModelTreeIterate with no pointer copy (diff)
downloadslicer-b3f01efdec0a74dc353e14ce278e9bdabb51793f.tar.bz2
slicer-b3f01efdec0a74dc353e14ce278e9bdabb51793f.tar.xz
slicer-b3f01efdec0a74dc353e14ce278e9bdabb51793f.zip
Refactor JsonSerializer::ModelTreeIterateRoot with no pointer copy
-rw-r--r--slicer/json/serializer.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/slicer/json/serializer.cpp b/slicer/json/serializer.cpp
index 0c993c4..728d174 100644
--- a/slicer/json/serializer.cpp
+++ b/slicer/json/serializer.cpp
@@ -324,18 +324,23 @@ namespace Slicer {
case ModelPartType::Simple:
mp->GetValue(JsonValueTarget(*n));
break;
- case ModelPartType::Complex:
- *n = json::Object();
+ case ModelPartType::Complex: {
+ auto oec = [n](const auto & lmp) {
+ *n = json::Object();
+ lmp->OnEachChild([n](auto && PH1, auto && PH2, auto &&) {
+ return JsonSerializer::ModelTreeIterate(n, PH1, PH2);
+ });
+ return &std::get<json::Object>(*n);
+ };
if (auto typeIdName = mp->GetTypeIdProperty()) {
if (auto typeId = mp->GetTypeId()) {
- std::get<json::Object>(*n).insert({*typeIdName, *typeId});
- mp = mp->GetSubclassModelPart(*typeId);
+ oec(mp->GetSubclassModelPart(*typeId))->emplace(*typeIdName, *typeId);
+ return;
}
}
- mp->OnEachChild([n](auto && PH1, auto && PH2, auto &&) {
- return JsonSerializer::ModelTreeIterate(n, PH1, PH2);
- });
+ oec(mp);
break;
+ }
case ModelPartType::Sequence:
*n = json::Array();
mp->OnEachChild([n](auto &&, auto && PH2, auto &&) {