X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgame%2Fhandle.h;h=b08bcf8e4f903028894702e8085df47174ce640f;hb=c3ac50ad3e79b26d1d99bd222a7e43adb86c2c1e;hp=d384f35c3c1fae6f29b1871a4c955079078d3e75;hpb=248d62f7240d342982ade65a510be912b867fe49;p=libs%2Fgame.git diff --git a/source/game/handle.h b/source/game/handle.h index d384f35..b08bcf8 100644 --- a/source/game/handle.h +++ b/source/game/handle.h @@ -23,13 +23,14 @@ protected: public: Handle() = default; - - static Handle from_object(T *o) { Handle h; h.ptr = o; return h; } + Handle(nullptr_t) { } template requires std::is_base_of_v Handle(const Handle &other): ptr(other.ptr) { } + static Handle from_object(T *o) { Handle h; h.ptr = o; return h; } + T *get() const { return ptr; } T &operator*() const { return *ptr; } T *operator->() const { return ptr; } @@ -38,6 +39,13 @@ public: bool operator==(const Handle &other) const = default; }; +template + requires std::is_base_of_v +Handle dynamic_handle_cast(Handle h) +{ + return Handle::from_object(dynamic_cast(h.get())); +} + } // namespace Msp::Game #endif