From 7fe47a9d5b1727a61dc724523b530762f6d6ba19 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Thu, 30 Jun 2022 21:38:53 -0700 Subject: Restructure project --- app/source/Cplt/Utils/RTTI.hpp | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 app/source/Cplt/Utils/RTTI.hpp (limited to 'app/source/Cplt/Utils/RTTI.hpp') diff --git a/app/source/Cplt/Utils/RTTI.hpp b/app/source/Cplt/Utils/RTTI.hpp new file mode 100644 index 0000000..86b1e2c --- /dev/null +++ b/app/source/Cplt/Utils/RTTI.hpp @@ -0,0 +1,49 @@ +#pragma once + +#include + +template +bool is_a(TBase* t) +{ + assert(t != nullptr); + return T::IsInstance(t); +} + +template +bool is_a_nullable(TBase* t) +{ + if (t) { + return is_a(t); + } else { + return false; + } +} + +template +T* dyn_cast(TBase* t) +{ + assert(t != nullptr); + if (T::IsInstance(t)) { + return static_cast(t); + } else { + return nullptr; + } +} + +template +const T* dyn_cast(const TBase* t) +{ + assert(t != nullptr); + if (T::IsInstance(t)) { + return static_cast(t); + } else { + return nullptr; + } +} + +template +T* dyn_cast_nullable(TBase* t) +{ + if (!t) return nullptr; + return dyn_cast(t); +} -- cgit v1.2.3-70-g09d2