From: Mikko Rasa Date: Wed, 19 Oct 2022 08:07:44 +0000 (+0300) Subject: Make the parent handle in Owned templated X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b644c89c81d89f60a0d82fe208fc76ce1c278a4c;p=libs%2Fgame.git Make the parent handle in Owned templated It may be useful for some components designed to be used with certain entity types. --- diff --git a/source/game/owned.h b/source/game/owned.h index 19daa7e..e20ff77 100644 --- a/source/game/owned.h +++ b/source/game/owned.h @@ -16,11 +16,11 @@ class Owned: public Handle public: Owned() = default; - template - Owned(Handle, Args &&...); + template + Owned(Handle

, Args &&...); - template - Owned(Entity &parent, Args &&... args): Owned(Handle::from_object(&parent), std::forward(args)...) { } + template + Owned(P &parent, Args &&... args): Owned(Handle

::from_object(&parent), std::forward(args)...) { } Owned(Owned &&other): Handle(other) { other.ptr = nullptr; } Owned &operator=(Owned &&other); @@ -35,21 +35,18 @@ private: template -template -Owned::Owned(Handle parent, Args &&... args) +template +Owned::Owned(Handle

parent, Args &&... args) { if(!parent) throw std::invalid_argument("Owned::Owned"); - using DependentEntity = std::conditional_t; - Handle dparent = parent; - - Pool &pool = get_stage(*dparent).get_pools().template get_pool(); + Pool &pool = get_stage(*parent).get_pools().template get_pool(); this->ptr = pool.create(parent, std::forward(args)...); if constexpr(std::is_base_of_v) - dparent->add_component(*this); + parent->add_component(*this); else - dparent->add_child(*this); + parent->add_child(*this); } template