From ca31f0e300d49e52c1ab354bd901be0f0c066614 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 5 Oct 2016 16:41:38 +0100 Subject: Implement class model part creation in a real function, not a machine built lambda --- slicer/slicer/modelPartsTypes.h | 2 ++ slicer/slicer/modelPartsTypes.impl.h | 6 ++++++ slicer/tool/parser.cpp | 3 +-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index 5dae7bf..886dcb0 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -168,6 +168,8 @@ namespace Slicer { virtual IceUtil::Optional GetTypeIdProperty() const override; static const std::string typeIdProperty; + + static ModelPartPtr CreateModelPart(void *); }; template diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index c34b482..2ed8996 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -298,6 +298,12 @@ namespace Slicer { return typeIdProperty; } + template + ModelPartPtr ModelPartForClass::CreateModelPart(void * p) + { + return new ModelPartForClass(*static_cast(p)); + } + // ModelPartForStruct template ModelPartForStruct::ModelPartForStruct(T & o) : diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index 7613ab6..50f7408 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -197,9 +197,8 @@ namespace Slicer { auto typeName = metaDataValue("slicer:typename:", c->getMetaData()); fprintbf(cpp, "static void registerClass_%u() __attribute__ ((constructor(210)));\n", classNo); fprintbf(cpp, "static void registerClass_%u()\n{\n", classNo); - fprintbf(cpp, "\tSlicer::classRefMap()->insert({ \"%s\", [](void * p){ return new ModelPartForClass< %s >(*static_cast< %s *>(p)); } });\n", + fprintbf(cpp, "\tSlicer::classRefMap()->insert({ \"%s\", &ModelPartForClass< %s >::CreateModelPart });\n", c->scoped(), - typeToString(decl), typeToString(decl)); if (typeName) { fprintbf(cpp, "\tSlicer::classNameMap()->insert({ \"%s\", \"%s\" });\n", -- cgit v1.2.3