1 #ifndef MSP_GAME_HANDLE_H_
2 #define MSP_GAME_HANDLE_H_
9 class invalid_handle: public std::logic_error
12 invalid_handle(const std::type_info &);
29 requires std::is_base_of_v<T, U>
30 Handle(const Handle<U> &other): ptr(other.ptr) { }
32 static Handle from_object(T *o) { Handle h; h.ptr = o; return h; }
34 T *get() const { return ptr; }
35 T &operator*() const { return *ptr; }
36 T *operator->() const { return ptr; }
37 explicit operator bool() const { return ptr; }
39 bool operator==(const Handle &other) const = default;
42 template<typename T, typename U>
43 requires std::is_base_of_v<U, T>
44 Handle<T> dynamic_handle_cast(Handle<U> h)
46 return Handle<T>::from_object(dynamic_cast<T *>(h.get()));
49 } // namespace Msp::Game