X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgame%2Fhandle.h;h=1808654f5e13ee4b60dd05ad633bab1b4249b75d;hb=b81c61ce06116727ebaef489f174fac6e0be6760;hp=d384f35c3c1fae6f29b1871a4c955079078d3e75;hpb=248d62f7240d342982ade65a510be912b867fe49;p=libs%2Fgame.git diff --git a/source/game/handle.h b/source/game/handle.h index d384f35..1808654 100644 --- a/source/game/handle.h +++ b/source/game/handle.h @@ -1,6 +1,7 @@ #ifndef MSP_GAME_HANDLE_H_ #define MSP_GAME_HANDLE_H_ +#include #include #include "pool.h" @@ -23,21 +24,30 @@ 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; } explicit operator bool() const { return ptr; } bool operator==(const Handle &other) const = default; + bool operator<(const Handle &other) const { return std::less()(ptr, other.ptr); } }; +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