From afdac1bb9ea2dfe08ed3c29270d35351f18ac51f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 9 Jan 2015 20:01:47 +0000 Subject: Name tweaks to restore compatibility with previous interface --- slicer/json/serializer.cpp | 6 +++--- slicer/slicer/modelParts.cpp | 4 ++-- slicer/slicer/modelParts.h | 20 ++++++++++---------- slicer/slicer/parser.cpp | 2 +- slicer/slicer/slicer.h | 18 ++++++++++++++++-- slicer/test/serializers.cpp | 10 +++++----- slicer/xml/serializer.cpp | 6 +++--- 7 files changed, 40 insertions(+), 26 deletions(-) diff --git a/slicer/json/serializer.cpp b/slicer/json/serializer.cpp index 0c704a5..f6e7415 100644 --- a/slicer/json/serializer.cpp +++ b/slicer/json/serializer.cpp @@ -149,7 +149,7 @@ namespace Slicer { { modelPart->Create(); for (const auto & element : a) { - auto emp = modelPart->GetChild(); + auto emp = modelPart->GetAnonChild(); if (emp) { emp->Create(); boost::apply_visitor(DocumentTreeIterate(emp), *element); @@ -256,7 +256,7 @@ namespace Slicer { Glib::ustring doc(buffer.str()); Glib::ustring::const_iterator itr = doc.begin(); json::Value obj = json::parseValue(itr); - auto mp = modelRoot->GetChild(); + auto mp = modelRoot->GetAnonChild(); boost::apply_visitor(DocumentTreeIterate(mp), obj); } @@ -282,7 +282,7 @@ namespace Slicer { void JsonValueDeserializer::Deserialize(ModelPartPtr modelRoot) { - auto mp = modelRoot->GetChild(); + auto mp = modelRoot->GetAnonChild(); boost::apply_visitor(DocumentTreeIterate(mp), value); } diff --git a/slicer/slicer/modelParts.cpp b/slicer/slicer/modelParts.cpp index b070bef..ede9d64 100644 --- a/slicer/slicer/modelParts.cpp +++ b/slicer/slicer/modelParts.cpp @@ -92,9 +92,9 @@ namespace Slicer { } ModelPartPtr - ModelPart::GetChild(const HookFilter & flt) + ModelPart::GetAnonChild(const HookFilter & flt) { - auto ref = GetChildRef(flt); + auto ref = GetAnonChildRef(flt); return ref ? ref->Child() : ModelPartPtr(NULL); } diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index 9027f92..deb32e1 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -173,9 +173,9 @@ namespace Slicer { virtual ~ModelPart() = default; virtual void OnEachChild(const ChildHandler &) = 0; - ModelPartPtr GetChild(const HookFilter & = HookFilter()); + ModelPartPtr GetAnonChild(const HookFilter & = HookFilter()); ModelPartPtr GetChild(const std::string & memberName, const HookFilter & = HookFilter()); - virtual ChildRefPtr GetChildRef(const HookFilter & = HookFilter()) = 0; + virtual ChildRefPtr GetAnonChildRef(const HookFilter & = HookFilter()) = 0; virtual ChildRefPtr GetChildRef(const std::string & memberName, const HookFilter & = HookFilter()) = 0; virtual ModelPartPtr GetSubclassModelPart(const std::string &); virtual TypeId GetTypeId() const; @@ -206,7 +206,7 @@ namespace Slicer { { } virtual void OnEachChild(const ChildHandler &) { } - virtual ChildRefPtr GetChildRef(const HookFilter &) override { return NULL; } + virtual ChildRefPtr GetAnonChildRef(const HookFilter &) override { return NULL; } virtual ChildRefPtr GetChildRef(const std::string &, const HookFilter &) override { return NULL; } virtual void SetValue(ValueSourcePtr s) override { s->set(Member); } virtual void GetValue(ValueTargetPtr s) override { s->get(Member); } @@ -231,7 +231,7 @@ namespace Slicer { { } virtual void OnEachChild(const ChildHandler &) { } - virtual ChildRefPtr GetChildRef(const HookFilter &) override { return NULL; } + virtual ChildRefPtr GetAnonChildRef(const HookFilter &) override { return NULL; } virtual ChildRefPtr GetChildRef(const std::string &, const HookFilter &) override { return NULL; } virtual void SetValue(ValueSourcePtr s) override; virtual void GetValue(ValueTargetPtr s) override; @@ -279,10 +279,10 @@ namespace Slicer { modelPart->Create(); } } - virtual ChildRefPtr GetChildRef(const HookFilter & flt) override + virtual ChildRefPtr GetAnonChildRef(const HookFilter & flt) override { if (OptionalMember) { - return modelPart->GetChildRef(flt); + return modelPart->GetAnonChildRef(flt); } return NULL; } @@ -373,7 +373,7 @@ namespace Slicer { } } - virtual ChildRefPtr GetChildRef(const HookFilter & flt) override + virtual ChildRefPtr GetAnonChildRef(const HookFilter & flt) override { for (const auto & h : hooks) { if (!flt || flt(h)) { @@ -504,7 +504,7 @@ namespace Slicer { } } - virtual ChildRefPtr GetChildRef(const HookFilter &) override + virtual ChildRefPtr GetAnonChildRef(const HookFilter &) override { mp->Create(); return new DirectChildRef(mp); @@ -565,7 +565,7 @@ namespace Slicer { } } - ChildRefPtr GetChildRef(const HookFilter &) override + ChildRefPtr GetAnonChildRef(const HookFilter &) override { sequence.push_back(typename element_type::value_type()); return new DirectChildRef(ModelPartFor(sequence.back())); @@ -647,7 +647,7 @@ namespace Slicer { } } - ChildRefPtr GetChildRef(const HookFilter &) override + ChildRefPtr GetAnonChildRef(const HookFilter &) override { return new DirectChildRef(new ModelPartForDictionaryElementInserter(dictionary)); } diff --git a/slicer/slicer/parser.cpp b/slicer/slicer/parser.cpp index 0e00dc1..d2d05a2 100644 --- a/slicer/slicer/parser.cpp +++ b/slicer/slicer/parser.cpp @@ -304,7 +304,7 @@ namespace Slicer { else { fprintf(cpp, "\t(void)name;\n"); } - fprintf(cpp, "\treturn GetChildRef(flt);\n}\n\n"); + fprintf(cpp, "\treturn GetAnonChildRef(flt);\n}\n\n"); fprintf(cpp, "template<>\n"); fprintf(cpp, "ModelPartPtr\n"); diff --git a/slicer/slicer/slicer.h b/slicer/slicer/slicer.h index ba0184c..c837913 100644 --- a/slicer/slicer/slicer.h +++ b/slicer/slicer/slicer.h @@ -8,7 +8,7 @@ namespace Slicer { template Object - Deserialize(SerializerParams & ... sp) + DeserializeAny(SerializerParams & ... sp) { IceUtil::Handle> root = new ModelPartForRoot(); DeserializerPtr deserializer = new Deserializer(sp ...); @@ -16,14 +16,28 @@ namespace Slicer { return root->GetModel(); } + template + Object + Deserialize(SerializerParams & ... sp) + { + return *DeserializeAny, SerializerParams...>(sp ...); + } + template void - Serialize(Object object, SerializerParams & ... sp) + SerializeAny(Object object, SerializerParams & ... sp) { IceUtil::Handle> root = new ModelPartForRoot(object); SerializerPtr serializer = new Serializer(sp ...); serializer->Serialize(root); } + + template + void + Serialize(IceInternal::Handle object, SerializerParams & ... sp) + { + SerializeAny(*object, sp ...); + } } #endif diff --git a/slicer/test/serializers.cpp b/slicer/test/serializers.cpp index f489af3..6151420 100644 --- a/slicer/test/serializers.cpp +++ b/slicer/test/serializers.cpp @@ -35,7 +35,7 @@ class FileBased : public FileStructure { const fs::path outputXml = tmpf / fs::change_extension(infile, "xml"); BOOST_TEST_CHECKPOINT("Deserialize: " << input); - T p = Slicer::Deserialize(input); + T p = Slicer::DeserializeAny(input); if (check) { BOOST_TEST_CHECKPOINT("Check1: " << input); @@ -43,10 +43,10 @@ class FileBased : public FileStructure { } BOOST_TEST_CHECKPOINT("Serialize " << input << " -> " << outputJson); - Slicer::Serialize(p, outputJson); + Slicer::SerializeAny(p, outputJson); BOOST_TEST_CHECKPOINT("Serialize " << input << " -> " << outputXml); - Slicer::Serialize(p, outputXml); + Slicer::SerializeAny(p, outputXml); if (check) { BOOST_TEST_CHECKPOINT("Check2: " << input); @@ -74,7 +74,7 @@ class FileBased : public FileStructure { Internal docRead = in(input); BOOST_TEST_CHECKPOINT("Deserialize: " << input); - T p = Slicer::Deserialize(docRead); + T p = Slicer::DeserializeAny(docRead); ifree(docRead); if (check) { @@ -84,7 +84,7 @@ class FileBased : public FileStructure { BOOST_TEST_CHECKPOINT("Serialize: " << input); Internal docWrite; - Slicer::Serialize(p, docWrite); + Slicer::SerializeAny(p, docWrite); if (check) { BOOST_TEST_CHECKPOINT("Check2: " << input); diff --git a/slicer/xml/serializer.cpp b/slicer/xml/serializer.cpp index e3482f2..225a1b3 100644 --- a/slicer/xml/serializer.cpp +++ b/slicer/xml/serializer.cpp @@ -177,7 +177,7 @@ namespace Slicer { if (smpr) { auto smp = smpr->Child(); if (metaDataFlagSet(smpr->ChildMetaData(), md_bare)) { - smp = smp->GetChild(); + smp = smp->GetAnonChild(); } if (smp) { if (auto typeIdPropName = smp->GetTypeIdProperty()) { @@ -207,8 +207,8 @@ namespace Slicer { else if (auto content = dynamic_cast(node)) { ModelPartPtr smp; if (!content->is_white_space()) { - smp = mp->GetChild(boost::bind(metaDataFlagSet, boost::bind(&Slicer::HookCommon::GetMetadata, _1), md_text)); - } + smp = mp->GetAnonChild(boost::bind(metaDataFlagSet, boost::bind(&Slicer::HookCommon::GetMetadata, _1), md_text)); + } if (smp) { smp->SetValue(new XmlContentValueSource(content)); } -- cgit v1.2.3