summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-08-06 18:17:23 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-08-06 18:17:23 +0100
commit841503f320d4cd3d3f139af1ba0caf3c5fa8af99 (patch)
treea40138ffe7f2de7b670e6455810295c7356f6930
parentModernize set up of class name/ref maps (diff)
downloadslicer-841503f320d4cd3d3f139af1ba0caf3c5fa8af99.tar.bz2
slicer-841503f320d4cd3d3f139af1ba0caf3c5fa8af99.tar.xz
slicer-841503f320d4cd3d3f139af1ba0caf3c5fa8af99.zip
Single call point for DocumentTreeIterate::visit
-rw-r--r--slicer/json/serializer.cpp33
1 files changed, 14 insertions, 19 deletions
diff --git a/slicer/json/serializer.cpp b/slicer/json/serializer.cpp
index db77607..449e0b4 100644
--- a/slicer/json/serializer.cpp
+++ b/slicer/json/serializer.cpp
@@ -149,7 +149,11 @@ namespace Slicer {
class DocumentTreeIterate {
public:
- explicit DocumentTreeIterate(ModelPartPtr & mp) : modelPart(mp) { }
+ static void
+ visit(ModelPartPtr && mp, const json::Value & v)
+ {
+ std::visit(DocumentTreeIterate {std::move(mp)}, v);
+ }
template<typename SimpleT>
void
@@ -181,19 +185,17 @@ namespace Slicer {
auto emp = modelPart->GetAnonChild();
emp->Create();
auto key = emp->GetChild(keyName);
- auto value = emp->GetChild(valueName);
key->Create();
key->SetValue(JsonValueSource(element.first));
key->Complete();
- std::visit(DocumentTreeIterate(value), element.second);
+ visit(emp->GetChild(valueName), element.second);
emp->Complete();
}
}
else {
for (const auto & element : o) {
- auto emp = modelPart->GetChild(element.first);
- if (emp) {
- std::visit(DocumentTreeIterate(emp), element.second);
+ if (auto emp = modelPart->GetChild(element.first)) {
+ visit(std::move(emp), element.second);
emp->Complete();
}
}
@@ -206,18 +208,16 @@ namespace Slicer {
{
modelPart->Create();
for (const auto & element : a) {
- auto emp = modelPart->GetAnonChild();
- if (emp) {
+ if (auto emp = modelPart->GetAnonChild()) {
emp->Create();
- std::visit(DocumentTreeIterate(emp), element);
+ visit(std::move(emp), element);
emp->Complete();
}
}
modelPart->Complete();
}
- private:
- ModelPartPtr & modelPart;
+ ModelPartPtr && modelPart;
};
void
@@ -372,9 +372,7 @@ namespace Slicer {
void
JsonStreamDeserializer::Deserialize(ModelPartForRootParam modelRoot)
{
- json::Value obj = json::parseValue(strm);
- auto mp = modelRoot->GetAnonChild();
- std::visit(DocumentTreeIterate(mp), obj);
+ DocumentTreeIterate::visit(modelRoot->GetAnonChild(), json::parseValue(strm));
}
void
@@ -392,9 +390,7 @@ namespace Slicer {
JsonFileDeserializer::Deserialize(ModelPartForRootParam modelRoot)
{
std::ifstream inFile(path);
- json::Value obj = json::parseValue(inFile);
- auto mp = modelRoot->GetAnonChild();
- std::visit(DocumentTreeIterate(mp), obj);
+ DocumentTreeIterate::visit(modelRoot->GetAnonChild(), json::parseValue(inFile));
}
JsonValueDeserializer::JsonValueDeserializer(const json::Value & v) : value(v) { }
@@ -402,8 +398,7 @@ namespace Slicer {
void
JsonValueDeserializer::Deserialize(ModelPartForRootParam modelRoot)
{
- auto mp = modelRoot->GetAnonChild();
- std::visit(DocumentTreeIterate(mp), value);
+ DocumentTreeIterate::visit(modelRoot->GetAnonChild(), value);
}
void