From ca9a42002d4d7ac82cc48f8afd3748df5db7ccd4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 21 Aug 2023 21:43:33 +0100 Subject: Create Optional ModelParts on the stack with std::optional Supercedes the previous change to unique_ptr and now all ModelParts are on the stack. --- slicer/slicer/modelParts.h | 1 - slicer/slicer/modelPartsTypes.h | 3 ++- slicer/slicer/modelPartsTypes.impl.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index de6e89f..8adc8f2 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -78,7 +78,6 @@ namespace Slicer { class ModelPartForRootBase; class HookCommon; - using ModelPartUPtr = std::unique_ptr; using ModelPartParam = any_ptr; using ModelPartForRootParam = any_ptr; using TypeId = std::optional; diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index f8a8814..2079195 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -113,7 +113,7 @@ namespace Slicer { protected: virtual bool hasModel() const = 0; - ModelPartUPtr modelPart; + ModelPart * modelPart; }; template @@ -129,6 +129,7 @@ namespace Slicer { protected: bool hasModel() const override; + std::optional modelPartOwner; }; class DLL_PUBLIC ModelPartForComplexBase : public ModelPart { diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index dc6ff07..ad1a90f 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -306,7 +306,7 @@ namespace Slicer { ModelPartModel>(h) { if (this->Model && *this->Model) { - modelPart = std::make_unique(&**this->Model); + modelPart = &modelPartOwner.emplace(&**this->Model); } } @@ -325,7 +325,7 @@ namespace Slicer { BOOST_ASSERT(this->Model); if (!*this->Model) { *this->Model = typename T::element_type(); - modelPart = std::make_unique(&**this->Model); + modelPart = &modelPartOwner.emplace(&**this->Model); modelPart->Create(); } } -- cgit v1.2.3