From 58483211c90f4841801b64ef8aa34b6ba839f3cd Mon Sep 17 00:00:00 2001 From: robojumper Date: Tue, 25 Jun 2024 20:11:44 +0200 Subject: [PATCH] Move actor ref header somewhere more appropriate --- include/d/a/d_a_base.h | 35 +++++++++++++++++++++++++++++++++++ include/f/f_list_nd.h | 27 --------------------------- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/include/d/a/d_a_base.h b/include/d/a/d_a_base.h index 346c68a4..46072cb0 100644 --- a/include/d/a/d_a_base.h +++ b/include/d/a/d_a_base.h @@ -25,6 +25,41 @@ struct SoundInfo { SoundInfo *prev; }; +/** + * A list node that will automatically unlink upon destruction. + */ +class dAcRefBase_c : public fLiNdBa_c { +public: + dAcRefBase_c(fBase_c *owner) : fLiNdBa_c(owner) {} + ~dAcRefBase_c() { + unlink(); + } +}; + +/** + * A type-safe list node that can hold a specific actor reference. + * Unlinks upon destruction. This setup is inferred from + * double null checks in inline dtors and instantiated ctors/dtors + * for arrays of these nodes in classes. + */ +template +class dAcRef_c : dAcRefBase_c { +public: + dAcRef_c(T *owner) : dAcRefBase_c(owner) {} + dAcRef_c() : dAcRefBase_c(nullptr) {} + ~dAcRef_c() {} + + void link(T *ref) { + fLiNdBa_c::link(ref); + } + void unlink() { + fLiNdBa_c::unlink(); + } + T *get() { + return static_cast(p_owner); + } +}; + template struct TList { T *GetOffset() { diff --git a/include/f/f_list_nd.h b/include/f/f_list_nd.h index c685f982..4ef42769 100644 --- a/include/f/f_list_nd.h +++ b/include/f/f_list_nd.h @@ -28,31 +28,4 @@ public: fBase_c *p_owner; }; -// TODO unofficial, move these to a more appropriate place -class fLiNdBaAutoUnlink_c : public fLiNdBa_c { -public: - fLiNdBaAutoUnlink_c(fBase_c *owner) : fLiNdBa_c(owner) {} - ~fLiNdBaAutoUnlink_c() { - unlink(); - } -}; - -template -class dAcRef_c : fLiNdBaAutoUnlink_c { -public: - dAcRef_c(T *owner) : fLiNdBaAutoUnlink_c(owner) {} - dAcRef_c() : fLiNdBaAutoUnlink_c(nullptr) {} - ~dAcRef_c() {} - - void link(T *ref) { - p_owner = ref; - } - void unlink() { - fLiNdBa_c::unlink(); - } - T *get() { - return static_cast(p_owner); - } -}; - #endif