29template <Uu
idIdentifiable T>
class TypedUuidReference
34 TypedUuidReference () =
delete;
37 : ref_ (type_safe::get (
id), registry)
43 TypedUuidReference (
const TypedUuidReference &other) =
default;
44 TypedUuidReference &operator= (
const TypedUuidReference &other) =
default;
45 TypedUuidReference (TypedUuidReference &&other)
noexcept =
default;
46 TypedUuidReference &operator= (TypedUuidReference &&other)
noexcept =
default;
48 template <Uu
idIdentifiable U>
49 requires std::derived_from<U, T>
50 TypedUuidReference (
const TypedUuidReference<U> &other)
51 : ref_ (other.as_untyped ())
57 void set_id (
const UuidType &
id) { ref_.set_id (type_safe::get (
id)); }
61 auto * base = ref_.get ();
62 return qobject_cast<T *> (base);
65 template <
typename DerivedT>
66 requires std::derived_from<DerivedT, T>
67 DerivedT * get_object_as ()
const
69 return qobject_cast<DerivedT *> (get ());
74 T * get_or_throw ()
const
79 throw std::runtime_error (
80 fmt::format (
"TypedUuidReference: object not found or wrong type"));
85 bool has_value ()
const {
return ref_.has_value (); }
91 friend void to_json (nlohmann::json &j,
const TypedUuidReference &ref)
93 to_json (j, ref.ref_);
95 friend void from_json (
const nlohmann::json &j, TypedUuidReference &ref)
97 from_json (j, ref.ref_);
100 friend auto format_as (
const TypedUuidReference &ref)
102 return type_safe::get (ref.id ());