summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-08-07 19:32:04 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-08-07 19:32:04 +0100
commit6de4a2c7a1721490726fd135d66bf4bd9ce29d77 (patch)
treea5e615285d5b9765b179ddad8ab5aced251e0186
parentImplement ModelTreeIterate as a wrapper around ModelTreeIterateRoot (diff)
downloadslicer-6de4a2c7a1721490726fd135d66bf4bd9ce29d77.tar.bz2
slicer-6de4a2c7a1721490726fd135d66bf4bd9ce29d77.tar.xz
slicer-6de4a2c7a1721490726fd135d66bf4bd9ce29d77.zip
Move ModelTreeIterate* into the anonymous namespace
Removes otherwise pointless base class
-rw-r--r--slicer/json/serializer.cpp176
-rw-r--r--slicer/json/serializer.h10
2 files changed, 90 insertions, 96 deletions
diff --git a/slicer/json/serializer.cpp b/slicer/json/serializer.cpp
index 1019602..9bbd508 100644
--- a/slicer/json/serializer.cpp
+++ b/slicer/json/serializer.cpp
@@ -220,104 +220,106 @@ namespace Slicer {
ModelPartPtr && modelPart;
};
- }
- void
- JsonSerializer::ModelTreeIterateSeq(json::Array & a, ModelPartParam mp)
- {
- if (!mp->HasValue()) {
- return;
- }
+ void ModelTreeIterateTo(const std::function<json::Value &()> &, ModelPartParam mp);
- ModelTreeIterateTo(
- [&a]() -> json::Value & {
- return a.emplace_back();
- },
- mp);
- }
+ void
+ ModelTreeIterateSeq(json::Array & a, ModelPartParam mp)
+ {
+ if (!mp->HasValue()) {
+ return;
+ }
- void
- JsonSerializer::ModelTreeIterateDictObj(json::Object & d, ModelPartParam mp)
- {
- if (!mp->HasValue()) {
- return;
+ ModelTreeIterateTo(
+ [&a]() -> json::Value & {
+ return a.emplace_back();
+ },
+ mp);
}
- ModelTreeIterateTo(
- [&d, mp]() -> json::Value & {
- json::Object::key_type k;
- json::Value kv;
- mp->GetChild(keyName)->GetValue(JsonValueTarget(kv));
- JsonValueSource(kv).set(k);
- return d[std::move(k)];
- },
- mp->GetChild(valueName));
- }
- void
- JsonSerializer::ModelTreeIterate(json::Object & o, const std::string & name, ModelPartParam mp)
- {
- if (name.empty()) {
- return;
+ void
+ ModelTreeIterateDictObj(json::Object & d, ModelPartParam mp)
+ {
+ if (!mp->HasValue()) {
+ return;
+ }
+ ModelTreeIterateTo(
+ [&d, mp]() -> json::Value & {
+ json::Object::key_type k;
+ json::Value kv;
+ mp->GetChild(keyName)->GetValue(JsonValueTarget(kv));
+ JsonValueSource(kv).set(k);
+ return d[std::move(k)];
+ },
+ mp->GetChild(valueName));
}
- ModelTreeIterateTo(
- [&o, &name]() -> json::Value & {
- return o[name];
- },
- mp);
- }
- void
- JsonSerializer::ModelTreeIterateTo(const std::function<json::Value &()> & n, ModelPartParam mp)
- {
- if (mp) {
- switch (mp->GetType()) {
- case ModelPartType::Null:
- n().emplace<json::Null>();
- break;
- case ModelPartType::Simple:
- if (json::Value v; mp->GetValue(JsonValueTarget(v))) {
- n() = std::move(v);
- }
- break;
- case ModelPartType::Complex:
- if (mp->HasValue()) {
- auto oec = [&n](const auto & lmp) {
- auto & obj = n().emplace<json::Object>();
- lmp->OnEachChild([&obj](auto && PH1, auto && PH2, auto &&) {
- return JsonSerializer::ModelTreeIterate(obj, PH1, PH2);
- });
- return &obj;
- };
- if (auto typeIdName = mp->GetTypeIdProperty()) {
- if (auto typeId = mp->GetTypeId()) {
- oec(mp->GetSubclassModelPart(*typeId))->emplace(*typeIdName, *typeId);
- return;
- }
+ void
+ ModelTreeIterate(json::Object & o, const std::string & name, ModelPartParam mp)
+ {
+ if (name.empty()) {
+ return;
+ }
+ ModelTreeIterateTo(
+ [&o, &name]() -> json::Value & {
+ return o[name];
+ },
+ mp);
+ }
+
+ void
+ ModelTreeIterateTo(const std::function<json::Value &()> & n, ModelPartParam mp)
+ {
+ if (mp) {
+ switch (mp->GetType()) {
+ case ModelPartType::Null:
+ n().emplace<json::Null>();
+ break;
+ case ModelPartType::Simple:
+ if (json::Value v; mp->GetValue(JsonValueTarget(v))) {
+ n() = std::move(v);
}
- oec(mp);
- }
- break;
- case ModelPartType::Sequence:
- if (mp->HasValue()) {
- mp->OnEachChild([&arr = n().emplace<json::Array>()](auto &&, auto && PH2, auto &&) {
- return JsonSerializer::ModelTreeIterateSeq(arr, PH2);
- });
- }
- break;
- case ModelPartType::Dictionary:
- if (mp->HasValue()) {
- if (mp->GetMetadata().flagSet(md_object)) {
- mp->OnEachChild([&obj = n().emplace<json::Object>()](auto &&, auto && PH2, auto &&) {
- return JsonSerializer::ModelTreeIterateDictObj(obj, PH2);
- });
+ break;
+ case ModelPartType::Complex:
+ if (mp->HasValue()) {
+ auto oec = [&n](const auto & lmp) {
+ auto & obj = n().emplace<json::Object>();
+ lmp->OnEachChild([&obj](auto && PH1, auto && PH2, auto &&) {
+ return ModelTreeIterate(obj, PH1, PH2);
+ });
+ return &obj;
+ };
+ if (auto typeIdName = mp->GetTypeIdProperty()) {
+ if (auto typeId = mp->GetTypeId()) {
+ oec(mp->GetSubclassModelPart(*typeId))->emplace(*typeIdName, *typeId);
+ return;
+ }
+ }
+ oec(mp);
}
- else {
+ break;
+ case ModelPartType::Sequence:
+ if (mp->HasValue()) {
mp->OnEachChild([&arr = n().emplace<json::Array>()](auto &&, auto && PH2, auto &&) {
- return JsonSerializer::ModelTreeIterateSeq(arr, PH2);
+ return ModelTreeIterateSeq(arr, PH2);
});
}
- }
- break;
+ break;
+ case ModelPartType::Dictionary:
+ if (mp->HasValue()) {
+ if (mp->GetMetadata().flagSet(md_object)) {
+ mp->OnEachChild([&obj = n().emplace<json::Object>()](auto &&, auto && PH2, auto &&) {
+ return ModelTreeIterateDictObj(obj, PH2);
+ });
+ }
+ else {
+ mp->OnEachChild([&arr = n().emplace<json::Array>()](auto &&, auto && PH2, auto &&) {
+ return ModelTreeIterateSeq(arr, PH2);
+ });
+ }
+ }
+ break;
+ }
}
}
}
@@ -362,7 +364,7 @@ namespace Slicer {
JsonValueSerializer::Serialize(ModelPartForRootParam modelRoot)
{
modelRoot->OnEachChild([this](auto &&, auto && PH2, auto &&) {
- return JsonSerializer::ModelTreeIterateTo(
+ return ModelTreeIterateTo(
[this]() -> json::Value & {
return value;
},
diff --git a/slicer/json/serializer.h b/slicer/json/serializer.h
index 923c37b..bba1486 100644
--- a/slicer/json/serializer.h
+++ b/slicer/json/serializer.h
@@ -11,15 +11,7 @@
#include <visibility.h>
namespace Slicer {
- class JsonSerializer : public Serializer {
- protected:
- static void ModelTreeIterate(json::Object &, const std::string &, ModelPartParam mp);
- static void ModelTreeIterateDictObj(json::Object &, ModelPartParam mp);
- static void ModelTreeIterateSeq(json::Array &, ModelPartParam mp);
- static void ModelTreeIterateTo(const std::function<json::Value &()> &, ModelPartParam mp);
- };
-
- class DLL_PUBLIC JsonValueSerializer : public JsonSerializer {
+ class DLL_PUBLIC JsonValueSerializer : public Serializer {
public:
void Serialize(ModelPartForRootParam) override;