17 #ifndef HEADER_SUPERTUX_UTIL_TYPED_UID_HPP 18 #define HEADER_SUPERTUX_UTIL_TYPED_UID_HPP 20 #include "util/uid.hpp" 22 #include "supertux/sector.hpp" 34 TypedUID(
const T*
object) :
UID() {
if (
object) *
this =
object->get_uid(); }
40 if (m_value == 0 || !Sector::current())
43 auto*
object =
Sector::get().get_object_by_uid<T>(*this);
56 inline TypedUID& operator=(
const T*
object)
58 *
this =
object ?
object->get_uid() :
UID();
64 UID::operator=(other);
68 inline T* operator->()
const 73 inline T& operator*()
const 77 throw std::runtime_error(
"Attempt to dereference invalid TypedUID");
82 inline bool operator==(
const T*
object)
const 84 return (!
object && m_value == 0) ||
object->get_uid() == *
this;
87 inline bool operator!=(
const T*
object)
const 89 return object ?
object->get_uid() != *this : m_value == 0;
92 inline operator bool()
const {
93 return m_value != 0 && Sector::current() &&
Sector::get().get_object_by_uid<T>(*this);
98 inline bool operator==(
const T*
object,
const TypedUID<T>& typed_uid) {
99 return typed_uid == object;
103 inline bool operator!=(
const T*
object,
const TypedUID<T>& typed_uid) {
104 return typed_uid != object;
Typed UIDs allows storing GameObjects as UID while offering to option to use the object either as if ...
Definition: typed_uid.hpp:30
static Sector & get()
get currently activated sector.
Definition: sector.hpp:74