From 8e39d7988b483b9dc042b002dac51acacc7ab0e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Tue, 21 Sep 2021 16:29:22 +0200 Subject: [PATCH] Added RefCounted helpers --- GlitchyEngine/src/Helper.bf | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 GlitchyEngine/src/Helper.bf diff --git a/GlitchyEngine/src/Helper.bf b/GlitchyEngine/src/Helper.bf new file mode 100644 index 0000000..6e70ced --- /dev/null +++ b/GlitchyEngine/src/Helper.bf @@ -0,0 +1,23 @@ +using System; +using DirectX.Common; + +namespace GlitchyEngine +{ + static + { + /// Releases the reference to destination, writes newValue into it and adds a reference to newValue. + public static mixin SetReference(T destination, T newValue) where T: RefCounted + { + destination?.ReleaseRef(); + destination = newValue; + destination?.AddRef(); + } + + /// Releases the reference to value and nullifies it. + public static mixin ReleaseRefAndNullify(T value) where T: RefCounted + { + value?.ReleaseRef(); + value = null; + } + } +}