From 7e4012ce070394de9871d05dec960a97e35b8bfd Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 6 Aug 2023 18:23:15 +0100 Subject: Move private stuff into anon namespace --- slicer/json/serializer.cpp | 320 +++++++++++++++++++++++---------------------- 1 file changed, 161 insertions(+), 159 deletions(-) diff --git a/slicer/json/serializer.cpp b/slicer/json/serializer.cpp index ce1b6e0..d9f7db8 100644 --- a/slicer/json/serializer.cpp +++ b/slicer/json/serializer.cpp @@ -26,199 +26,201 @@ NAMEDFACTORY("application/json", Slicer::JsonStreamSerializer, Slicer::StreamSer NAMEDFACTORY("application/json", Slicer::JsonStreamDeserializer, Slicer::StreamDeserializerFactory) namespace Slicer { - constexpr std::string_view md_object {"json:object"}; - constexpr std::string_view keyName {"key"}; - constexpr std::string_view valueName {"value"}; + namespace { + constexpr std::string_view md_object {"json:object"}; + constexpr std::string_view keyName {"key"}; + constexpr std::string_view valueName {"value"}; - using namespace std::placeholders; + using namespace std::placeholders; - class JsonValueSource : public ValueSource { - public: - explicit JsonValueSource(const json::Value & s) : value(s) { } + class JsonValueSource : public ValueSource { + public: + explicit JsonValueSource(const json::Value & s) : value(s) { } - void - set(bool & v) const override - { - v = std::get(value); - } - - void - set(Ice::Byte & v) const override - { - v = boost::numeric_cast(std::get(value)); - } + void + set(bool & v) const override + { + v = std::get(value); + } - void - set(Ice::Short & v) const override - { - v = boost::numeric_cast(std::get(value)); - } + void + set(Ice::Byte & v) const override + { + v = boost::numeric_cast(std::get(value)); + } - void - set(Ice::Int & v) const override - { - v = boost::numeric_cast(std::get(value)); - } + void + set(Ice::Short & v) const override + { + v = boost::numeric_cast(std::get(value)); + } - void - set(Ice::Long & v) const override - { - v = boost::numeric_cast(std::get(value)); - } + void + set(Ice::Int & v) const override + { + v = boost::numeric_cast(std::get(value)); + } - void - set(Ice::Float & v) const override - { - v = boost::numeric_cast(std::get(value)); - } + void + set(Ice::Long & v) const override + { + v = boost::numeric_cast(std::get(value)); + } - void - set(Ice::Double & v) const override - { - v = boost::numeric_cast(std::get(value)); - } + void + set(Ice::Float & v) const override + { + v = boost::numeric_cast(std::get(value)); + } - void - set(std::string & v) const override - { - v = std::get(value); - } + void + set(Ice::Double & v) const override + { + v = boost::numeric_cast(std::get(value)); + } - private: - const json::Value & value; - }; + void + set(std::string & v) const override + { + v = std::get(value); + } - class JsonValueTarget : public ValueTarget { - public: - explicit JsonValueTarget(json::Value & t) : target(t) - { - target = json::Null(); - } + private: + const json::Value & value; + }; - void - get(const bool & value) const override - { - target = value; - } + class JsonValueTarget : public ValueTarget { + public: + explicit JsonValueTarget(json::Value & t) : target(t) + { + target = json::Null(); + } - void - get(const Ice::Byte & value) const override - { - target = boost::numeric_cast(value); - } + void + get(const bool & value) const override + { + target = value; + } - void - get(const Ice::Short & value) const override - { - target = boost::numeric_cast(value); - } + void + get(const Ice::Byte & value) const override + { + target = boost::numeric_cast(value); + } - void - get(const Ice::Int & value) const override - { - target = boost::numeric_cast(value); - } + void + get(const Ice::Short & value) const override + { + target = boost::numeric_cast(value); + } - void - get(const Ice::Long & value) const override - { - target = boost::numeric_cast(value); - } + void + get(const Ice::Int & value) const override + { + target = boost::numeric_cast(value); + } - void - get(const Ice::Float & value) const override - { - target = boost::numeric_cast(value); - } + void + get(const Ice::Long & value) const override + { + target = boost::numeric_cast(value); + } - void - get(const Ice::Double & value) const override - { - target = boost::numeric_cast(value); - } + void + get(const Ice::Float & value) const override + { + target = boost::numeric_cast(value); + } - void - get(const std::string & value) const override - { - target = value; - } + void + get(const Ice::Double & value) const override + { + target = boost::numeric_cast(value); + } - private: - json::Value & target; - }; + void + get(const std::string & value) const override + { + target = value; + } - class DocumentTreeIterate { - public: - static void - visit(ModelPartPtr && mp, const json::Value & v) - { - std::visit(DocumentTreeIterate {std::move(mp)}, v); - } + private: + json::Value & target; + }; - template - void - operator()(const SimpleT & v) const - { - modelPart->Create(); - modelPart->SetValue(JsonValueSource(v)); - modelPart->Complete(); - } + class DocumentTreeIterate { + public: + static void + visit(ModelPartPtr && mp, const json::Value & v) + { + std::visit(DocumentTreeIterate {std::move(mp)}, v); + } - void - operator()(const json::Null &) const - { - modelPart->Complete(); - } + template + void + operator()(const SimpleT & v) const + { + modelPart->Create(); + modelPart->SetValue(JsonValueSource(v)); + modelPart->Complete(); + } - void - operator()(const json::Object & o) const - { - if (auto typeIdName = modelPart->GetTypeIdProperty()) { - auto typeAttrItr = o.find(*typeIdName); - if (typeAttrItr != o.end() && std::holds_alternative(typeAttrItr->second)) { - modelPart = modelPart->GetSubclassModelPart(std::get(typeAttrItr->second)); - } + void + operator()(const json::Null &) const + { + modelPart->Complete(); } - modelPart->Create(); - if (modelPart->GetMetadata().flagSet(md_object)) { - for (const auto & element : o) { - auto emp = modelPart->GetAnonChild(); - emp->Create(); - auto key = emp->GetChild(keyName); - key->Create(); - key->SetValue(JsonValueSource(element.first)); - key->Complete(); - visit(emp->GetChild(valueName), element.second); - emp->Complete(); + + void + operator()(const json::Object & o) const + { + if (auto typeIdName = modelPart->GetTypeIdProperty()) { + auto typeAttrItr = o.find(*typeIdName); + if (typeAttrItr != o.end() && std::holds_alternative(typeAttrItr->second)) { + modelPart = modelPart->GetSubclassModelPart(std::get(typeAttrItr->second)); + } } - } - else { - for (const auto & element : o) { - if (auto emp = modelPart->GetChild(element.first)) { - visit(std::move(emp), element.second); + modelPart->Create(); + if (modelPart->GetMetadata().flagSet(md_object)) { + for (const auto & element : o) { + auto emp = modelPart->GetAnonChild(); + emp->Create(); + auto key = emp->GetChild(keyName); + key->Create(); + key->SetValue(JsonValueSource(element.first)); + key->Complete(); + visit(emp->GetChild(valueName), element.second); emp->Complete(); } } - modelPart->Complete(); + else { + for (const auto & element : o) { + if (auto emp = modelPart->GetChild(element.first)) { + visit(std::move(emp), element.second); + emp->Complete(); + } + } + modelPart->Complete(); + } } - } - void - operator()(const json::Array & a) const - { - modelPart->Create(); - for (const auto & element : a) { - if (auto emp = modelPart->GetAnonChild()) { - emp->Create(); - visit(std::move(emp), element); - emp->Complete(); + void + operator()(const json::Array & a) const + { + modelPart->Create(); + for (const auto & element : a) { + if (auto emp = modelPart->GetAnonChild()) { + emp->Create(); + visit(std::move(emp), element); + emp->Complete(); + } } + modelPart->Complete(); } - modelPart->Complete(); - } - ModelPartPtr && modelPart; - }; + ModelPartPtr && modelPart; + }; + } void JsonSerializer::ModelTreeIterateSeq(json::Value * n, ModelPartParam mp) -- cgit v1.2.3