From 4b97b062f55f4e176ab844e0a339e7db77e05db3 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 2 Jan 2017 19:30:39 +0000 Subject: Fix support for model part types of optional converted --- slicer/slicer/modelPartsTypes.h | 4 ++-- slicer/slicer/modelPartsTypes.impl.h | 4 ++-- slicer/test/optionals.ice | 2 ++ slicer/tool/parser.cpp | 37 +++++++++++++++++++++++------------- slicer/tool/parser.h | 1 + 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index f159191..a27ad66 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -56,7 +56,7 @@ namespace Slicer { static const ModelPartType type; }; - template + template class DLL_PUBLIC ModelPartForConverted : public ModelPartForConvertedBase, protected ModelPartModel { public: typedef T element_type; @@ -66,7 +66,7 @@ namespace Slicer { virtual void SetValue(ValueSourcePtr s) override; virtual void GetValue(ValueTargetPtr s) override; }; - + class DLL_PUBLIC ModelPartForOptionalBase : public ModelPart { public: virtual void OnEachChild(const ChildHandler & ch) override; diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index b19f937..fe38863 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -150,8 +150,8 @@ namespace Slicer { } // ModelPartForConverted - template - ModelPartForConverted::ModelPartForConverted(T & h) : + template + ModelPartForConverted::ModelPartForConverted(T & h) : ModelPartModel(h) { } diff --git a/slicer/test/optionals.ice b/slicer/test/optionals.ice index 63476ad..720e7c3 100644 --- a/slicer/test/optionals.ice +++ b/slicer/test/optionals.ice @@ -12,6 +12,8 @@ module TestModule { optional(2) ClassType optClass; optional(3) Classes optSeq; optional(4) ClassMap optDict; + [ "slicer:conversion:boost.posix_time.ptime:boost.posix_time.to_iso_extended_string:boost.posix_time.time_from_string:nodeclare" ] + optional(5) string optConverted; }; }; diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index c2c98d0..818cd7e 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -51,11 +51,8 @@ namespace Slicer { } if (!conversions.empty()) { fprintbf(cpp, "template<> DLL_PUBLIC\nvoid\n"); - fprintbf(cpp, "ModelPartForConverted< %s, %s, &%s >::SetValue(ValueSourcePtr vsp)\n", - Slice::typeToString(type), - c->scoped(), - dm->scoped()); - fprintbf(cpp, "{\n"); + createModelPartForConverted(type, c->scoped(), dm); + fprintbf(cpp, "::SetValue(ValueSourcePtr vsp)\n{\n"); for (const auto & conversion : conversions) { fprintbf(cpp, "\tif (auto vspt = dynamic_cast *>(vsp.get())) {\n", @@ -82,11 +79,8 @@ namespace Slicer { fprintbf(cpp, "}\n\n"); fprintbf(cpp, "template<> DLL_PUBLIC\nvoid\n"); - fprintbf(cpp, "ModelPartForConverted< %s, %s, &%s >::GetValue(ValueTargetPtr vtp)\n", - Slice::typeToString(type), - c->scoped(), - dm->scoped()); - fprintbf(cpp, "{\n"); + createModelPartForConverted(type, c->scoped(), dm); + fprintbf(cpp, "::GetValue(ValueTargetPtr vtp)\n{\n"); for (const auto & conversion : conversions) { fprintbf(cpp, "\tif (auto vtpt = dynamic_cast *>(vtp.get())) {\n", @@ -462,15 +456,32 @@ namespace Slicer { } } + void + Slicer::createModelPartForConverted(const Slice::TypePtr & type, const std::string & container, const Slice::DataMemberPtr & dm) const + { + fprintbf(cpp, "ModelPartForConverted< %s, ", + Slice::typeToString(type)); + if (dm->optional()) { + fprintbf(cpp, "IceUtil::Optional< %s >", + Slice::typeToString(type)); + } + else { + fprintbf(cpp, "%s", + Slice::typeToString(type)); + } + fprintbf(cpp, ", %s, &%s >", + container, + dm->scoped()); + } + void Slicer::createNewModelPartPtrFor(const Slice::TypePtr & type, const Slice::DataMemberPtr & dm, const Slice::StringList & md) const { auto conversions = getConversions(md); if (dm && !conversions.empty()) { - fprintbf(cpp, "ModelPartForConverted< %s, %s, &%s >", - Slice::typeToString(type), + createModelPartForConverted(type, boost::algorithm::trim_right_copy_if(dm->container()->thisScope(), ispunct), - dm->scoped()); + dm); } else if (auto cmp = metaDataValue("slicer:custommodelpart:", md)) { fprintbf(cpp, "%s", diff --git a/slicer/tool/parser.h b/slicer/tool/parser.h index 9495607..02c7dfe 100644 --- a/slicer/tool/parser.h +++ b/slicer/tool/parser.h @@ -55,6 +55,7 @@ namespace Slicer { virtual void visitModuleEnd(const Slice::ModulePtr & m) override; private: + void createModelPartForConverted(const Slice::TypePtr & type, const std::string & container, const Slice::DataMemberPtr & dm) const; void createNewModelPartPtrFor(const Slice::TypePtr & type, const Slice::DataMemberPtr & dm = Slice::DataMemberPtr(), const Slice::StringList & md = Slice::StringList()) const; std::string getBasicModelPart(const Slice::TypePtr & type) const; void defineMODELPART(const std::string & type, const Slice::TypePtr & stype, const Slice::StringList & metadata) const; -- cgit v1.2.3