From 16f48c313f4e29892a4730bbf5104ff6d5210492 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 21 Oct 2016 11:25:02 +0100 Subject: Reference classes by type not handle type in model parts --- slicer/slicer/modelPartsTypes.h | 8 ++++---- slicer/slicer/modelPartsTypes.impl.h | 10 +++++----- slicer/test/conversions.cpp | 4 ++-- slicer/test/conversions.h | 2 +- slicer/tool/parser.cpp | 17 ++++++++++++----- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index 363891d..d53be93 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -167,15 +167,15 @@ namespace Slicer { }; template - class DLL_PUBLIC ModelPartForClass : public ModelPartForComplex, protected ModelPartModel { + class DLL_PUBLIC ModelPartForClass : public ModelPartForComplex, protected ModelPartModel > { public: - typedef T element_type; + typedef IceInternal::Handle element_type; - ModelPartForClass(T & h); + ModelPartForClass(element_type & h); virtual void Create() override; - typename T::element_type * GetModel() override; + T * GetModel() override; virtual ModelPartPtr GetSubclassModelPart(const std::string & name) override; diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index 443b96b..b3abc2c 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -204,19 +204,19 @@ namespace Slicer { // ModelPartForClass template - ModelPartForClass::ModelPartForClass(T & h) : - ModelPartModel(h) + ModelPartForClass::ModelPartForClass(element_type & h) : + ModelPartModel(h) { } template void ModelPartForClass::Create() { - this->Model = new typename T::element_type(); + this->Model = new T(); } template - typename T::element_type * ModelPartForClass::GetModel() + T * ModelPartForClass::GetModel() { return this->Model.get(); } @@ -242,7 +242,7 @@ namespace Slicer { template ModelPartPtr ModelPartForClass::CreateModelPart(void * p) { - return new ModelPartForClass(*static_cast(p)); + return new ModelPartForClass(*static_cast(p)); } template diff --git a/slicer/test/conversions.cpp b/slicer/test/conversions.cpp index 8510089..63de1de 100644 --- a/slicer/test/conversions.cpp +++ b/slicer/test/conversions.cpp @@ -109,7 +109,7 @@ namespace TestModule { int completions = 0; AbValidator::AbValidator(ClassTypePtr & m) : - Slicer::ModelPartForClass(m) + Slicer::ModelPartForClass(m) { } @@ -121,7 +121,7 @@ namespace TestModule { throw std::runtime_error("Mock error"); // LCOV_EXCL_STOP } - Slicer::ModelPartForClass::Complete(); + Slicer::ModelPartForClass::Complete(); completions += 1; } diff --git a/slicer/test/conversions.h b/slicer/test/conversions.h index e33b670..62a9c4b 100644 --- a/slicer/test/conversions.h +++ b/slicer/test/conversions.h @@ -9,7 +9,7 @@ namespace TestModule { DLL_PUBLIC extern int completions; - class DLL_PUBLIC AbValidator : public Slicer::ModelPartForClass { + class DLL_PUBLIC AbValidator : public Slicer::ModelPartForClass { public: AbValidator(ClassTypePtr &); diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index 5aa5f5c..466f4dd 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -188,7 +188,7 @@ namespace Slicer { fprintbf(cpp, "template<> DLL_PUBLIC\n"); auto typeId = metaDataValue("slicer:typeid:", c->getMetaData()); fprintbf(cpp, "const std::string ModelPartForClass< %s >::typeIdProperty(\"%s\");\n\n", - typeToString(decl), + decl->typeId(), typeId ? *typeId : "slicer-typeid"); auto name = metaDataValue("slicer:root:", c->getMetaData()); @@ -197,10 +197,10 @@ namespace Slicer { auto typeName = metaDataValue("slicer:typename:", c->getMetaData()); fprintbf(cpp, "template<> DLL_PUBLIC\n"); fprintbf(cpp, "__attribute__ ((init_priority(209)))\nconst std::string ModelPartForClass< %s >::className(\"%s\");\n", - typeToString(decl), c->scoped()); + decl->typeId(), c->scoped()); fprintbf(cpp, "template<> DLL_PUBLIC\n"); fprintbf(cpp, "__attribute__ ((init_priority(209)))\nconst IceUtil::Optional ModelPartForClass< %s >::typeName", - typeToString(decl)); + decl->typeId()); if (typeName) { fprintbf(cpp, "(\"%s\")", *typeName); @@ -215,7 +215,14 @@ namespace Slicer { copyMetadata(c->getMetaData()); fprintbf(cpp, ";\n\n"); - defineMODELPART(stringbf("::IceInternal::Handle< %s >", c->scoped()), decl, c->getMetaData()); + if (auto cmp = metaDataValue("slicer:custommodelpart:", c->getMetaData())) { + fprintbf(cpp, "CUSTOMMODELPARTFOR(%s, %s< %s >, %s);\n\n", + Slice::typeToString(decl), getBasicModelPart(decl), c->scoped(), boost::algorithm::replace_all_copy(*cmp, ".", "::")); + } + else { + fprintbf(cpp, "CUSTOMMODELPARTFOR(%s, ModelPartForClass<%s>, ModelPartForClass<%s>);\n\n", + Slice::typeToString(decl), c->scoped(), c->scoped()); + } classNo += 1; @@ -471,7 +478,7 @@ namespace Slicer { } else { fprintbf(cpp, "%s< %s >", - getBasicModelPart(type), Slice::typeToString(type)); + getBasicModelPart(type), Slice::ClassDeclPtr::dynamicCast(type) ? type->typeId() : Slice::typeToString(type)); } } -- cgit v1.2.3