diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-08-20 13:30:49 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-08-20 13:30:49 +0100 |
commit | 041637576884a1ad08c4e11912099d1d47510952 (patch) | |
tree | 1726b0c817019d77ad9500a5d49c1c95920ecb9e | |
parent | Create Optional ModelParts as unique_ptrs (diff) | |
download | slicer-041637576884a1ad08c4e11912099d1d47510952.tar.bz2 slicer-041637576884a1ad08c4e11912099d1d47510952.tar.xz slicer-041637576884a1ad08c4e11912099d1d47510952.zip |
Make ModelPartRoots on stack
-rw-r--r-- | slicer/slicer/modelParts.h | 4 | ||||
-rw-r--r-- | slicer/slicer/modelPartsTypes.impl.h | 23 | ||||
-rw-r--r-- | slicer/slicer/slicer.h | 8 |
3 files changed, 19 insertions, 16 deletions
diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index f521257..da929ba 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -80,13 +80,13 @@ namespace Slicer { using ModelPartPtr = std::shared_ptr<ModelPart>; using ModelPartUPtr = std::unique_ptr<ModelPart>; - using ModelPartForRootPtr = std::unique_ptr<ModelPartForRootBase>; using ModelPartParam = any_ptr<ModelPart>; using ModelPartForRootParam = any_ptr<ModelPartForRootBase>; using TypeId = std::optional<std::string>; using Metadata = MetaData<>; using ChildHandler = std::function<void(const std::string &, ModelPartParam, const HookCommon *)>; using ModelPartHandler = std::function<void(ModelPartParam)>; + using ModelPartRootHandler = std::function<void(ModelPartForRootParam)>; using SubPartHandler = std::function<void(ModelPartParam, const Metadata &)>; using ClassRef = std::function<void(void *, const ModelPartHandler &)>; using HookFilter = std::function<bool(const HookCommon *)>; @@ -142,7 +142,7 @@ namespace Slicer { template<typename MP> static ModelPartPtr Make(typename MP::element_type * t); template<typename T> static ModelPartPtr CreateFor(T & t); template<typename T> static ModelPartPtr CreateFor(Default<T> &&); - template<typename T> static ModelPartForRootPtr CreateRootFor(T & t); + template<typename T> static void OnRootFor(T & t, const ModelPartRootHandler &); virtual void OnEachChild(const ChildHandler &); virtual bool OnAnonChild(const SubPartHandler &, const HookFilter & = HookFilter()); diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index 3a4076e..393809f 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -67,21 +67,21 @@ namespace Ice { { \ return CreateFor(const_cast<Ice::optional<Type> &>(s)); \ } \ - template<> DLL_PUBLIC ModelPartForRootPtr ModelPart::CreateRootFor(Type & s) \ + template<> DLL_PUBLIC void ModelPart::OnRootFor(Type & s, const ModelPartRootHandler & h) \ { \ - return std::make_unique<ModelPartForRoot<Type>>(&s); \ + h(ModelPartForRoot<Type>(&s)); \ } \ - template<> DLL_PUBLIC ModelPartForRootPtr ModelPart::CreateRootFor(Ice::optional<Type> & s) \ + template<> DLL_PUBLIC void ModelPart::OnRootFor(Ice::optional<Type> & s, const ModelPartRootHandler & h) \ { \ - return std::make_unique<ModelPartForRoot<Ice::optional<Type>>>(&s); \ + h(ModelPartForRoot<Ice::optional<Type>>(&s)); \ } \ - template<> DLL_PUBLIC ModelPartForRootPtr ModelPart::CreateRootFor(const Type & s) \ + template<> DLL_PUBLIC void ModelPart::OnRootFor(const Type & s, const ModelPartRootHandler & h) \ { \ - return CreateRootFor(const_cast<Type &>(s)); \ + return OnRootFor(const_cast<Type &>(s), h); \ } \ - template<> DLL_PUBLIC ModelPartForRootPtr ModelPart::CreateRootFor(const Ice::optional<Type> & s) \ + template<> DLL_PUBLIC void ModelPart::OnRootFor(const Ice::optional<Type> & s, const ModelPartRootHandler & h) \ { \ - return CreateRootFor(const_cast<Ice::optional<Type> &>(s)); \ + return OnRootFor(const_cast<Ice::optional<Type> &>(s), h); \ } \ template class BaseModelPart; \ template class ModelPartForRoot<Type>; \ @@ -91,11 +91,10 @@ namespace Ice { #define MODELPARTFORSTREAM(StreamImpl) \ namespace Slicer { \ template<> \ - DLL_PUBLIC ModelPartForRootPtr \ - ModelPart::CreateRootFor(const StreamImpl & stream) \ + DLL_PUBLIC void \ + ModelPart::OnRootFor(const StreamImpl & stream, const ModelPartRootHandler & h) \ { \ - return std::make_unique<ModelPartForStreamRoot<typename StreamImpl::element_type>>( \ - const_cast<StreamImpl *>(&stream)); \ + h(ModelPartForStreamRoot<typename StreamImpl::element_type>(const_cast<StreamImpl *>(&stream))); \ } \ } diff --git a/slicer/slicer/slicer.h b/slicer/slicer/slicer.h index 66e4537..cb15af2 100644 --- a/slicer/slicer/slicer.h +++ b/slicer/slicer/slicer.h @@ -11,7 +11,9 @@ namespace Slicer { DeserializeAnyWith(any_ptr<Deserializer> deserializer) { Object object {}; - deserializer->Deserialize(ModelPart::CreateRootFor<Object>(object)); + ModelPart::OnRootFor<Object>(object, [deserializer](auto && mp) { + deserializer->Deserialize(mp); + }); return object; } @@ -26,7 +28,9 @@ namespace Slicer { void SerializeAnyWith(const Object & object, any_ptr<Serializer> serializer) { - serializer->Serialize(ModelPart::CreateRootFor<const Object>(object)); + ModelPart::OnRootFor<const Object>(object, [serializer](auto && mp) { + serializer->Serialize(mp); + }); } template<typename Serializer, typename Object, typename... SerializerParams> |