From 254ae2d3a8defd5a15669e6d8e888a122cd69e2b Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Sun, 18 May 2025 11:08:15 -0700 Subject: [PATCH] Use template specialization solution --- CMakeLists.txt | 2 +- LEGO1/lego/legoomni/include/legoroimaplist.h | 17 +++++++++++++++++ LEGO1/omni/include/mxlist.h | 12 +----------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c113ad1..3b523183 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ include(CheckCXXSourceCompiles) include(CMakeDependentOption) include(CMakePushCheckState) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) diff --git a/LEGO1/lego/legoomni/include/legoroimaplist.h b/LEGO1/lego/legoomni/include/legoroimaplist.h index 697c2dd8..05a03b44 100644 --- a/LEGO1/lego/legoomni/include/legoroimaplist.h +++ b/LEGO1/lego/legoomni/include/legoroimaplist.h @@ -15,6 +15,23 @@ class LegoROI; // VTABLE: LEGO1 0x100d9248 // class MxPtrList +// Specialize MxPtrList for LegoROI* in order to fix Destroy. +// TODO: Change to using constexpr in MxPtrList::Destroy once C++17 standard works. +template <> +class MxPtrList : public MxList { +public: + MxPtrList(MxBool p_ownership) { SetOwnership(p_ownership); } + + static void Destroy(LegoROI** p_obj) { delete[] p_obj; } + + void SetOwnership(MxBool p_ownership) + { + MxCollection::SetDestroy( + p_ownership ? MxPtrList::Destroy : MxCollection::Destroy + ); + } +}; + // VTABLE: LEGO1 0x100d9260 // SIZE 0x18 class LegoROIMapList : public MxPtrList { diff --git a/LEGO1/omni/include/mxlist.h b/LEGO1/omni/include/mxlist.h index 6d46cb2a..f6954168 100644 --- a/LEGO1/omni/include/mxlist.h +++ b/LEGO1/omni/include/mxlist.h @@ -5,8 +5,6 @@ #include "mxcore.h" #include "mxtypes.h" -#include - template class MxList; template @@ -73,15 +71,7 @@ class MxPtrList : public MxList { public: MxPtrList(MxBool p_ownership) { SetOwnership(p_ownership); } - static void Destroy(T* p_obj) - { - if constexpr (std::is_pointer::value) { - delete[] p_obj; - } - else { - delete p_obj; - } - } + static void Destroy(T* p_obj) { delete p_obj; } void SetOwnership(MxBool p_ownership) {