From 7430b70b73e52fab9ad6b53585f8907ba492f854 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 11 Oct 2019 15:13:02 -0400 Subject: [PATCH] CParticleDataFactory: Use unique_ptr where applicable Same behavior, but makes the functions a little safer in terms of memory management. --- Runtime/Particle/CParticleDataFactory.cpp | 19 ++++++++++--------- Runtime/Particle/CParticleDataFactory.hpp | 6 +++--- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Runtime/Particle/CParticleDataFactory.cpp b/Runtime/Particle/CParticleDataFactory.cpp index df76addd0..d55a36c7f 100644 --- a/Runtime/Particle/CParticleDataFactory.cpp +++ b/Runtime/Particle/CParticleDataFactory.cpp @@ -700,21 +700,23 @@ std::unique_ptr CParticleDataFactory::GetIntElement(CInputStream& i return nullptr; } -CGenDescription* CParticleDataFactory::GetGeneratorDesc(CInputStream& in, CSimplePool* resPool) { +std::unique_ptr CParticleDataFactory::GetGeneratorDesc(CInputStream& in, CSimplePool* resPool) { std::vector tracker; tracker.reserve(8); return CreateGeneratorDescription(in, tracker, 0, resPool); } -CGenDescription* CParticleDataFactory::CreateGeneratorDescription(CInputStream& in, std::vector& tracker, - CAssetId resId, CSimplePool* resPool) { +std::unique_ptr CParticleDataFactory::CreateGeneratorDescription(CInputStream& in, + std::vector& tracker, + CAssetId resId, + CSimplePool* resPool) { if (std::count(tracker.cbegin(), tracker.cend(), resId) == 0) { tracker.push_back(resId); FourCC cid = GetClassID(in); if (cid == FOURCC('GPSM')) { - CGenDescription* ret = new CGenDescription; - CreateGPSM(ret, in, tracker, resPool); - LoadGPSMTokens(ret); + auto ret = std::make_unique(); + CreateGPSM(ret.get(), in, tracker, resPool); + LoadGPSMTokens(ret.get()); return ret; } } @@ -1027,9 +1029,8 @@ void CParticleDataFactory::LoadGPSMTokens(CGenDescription* desc) { CFactoryFnReturn FParticleFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms, CObjectReference* selfRef) { - CSimplePool* sp = vparms.GetOwnedObj(); - return TToken::GetIObjObjectFor( - std::unique_ptr(CParticleDataFactory::GetGeneratorDesc(in, sp))); + auto* const sp = vparms.GetOwnedObj(); + return TToken::GetIObjObjectFor(CParticleDataFactory::GetGeneratorDesc(in, sp)); } } // namespace urde diff --git a/Runtime/Particle/CParticleDataFactory.hpp b/Runtime/Particle/CParticleDataFactory.hpp index 281e6ff19..6b37cc4b2 100644 --- a/Runtime/Particle/CParticleDataFactory.hpp +++ b/Runtime/Particle/CParticleDataFactory.hpp @@ -86,14 +86,14 @@ class CParticleDataFactory { static s32 GetInt(CInputStream& in); static bool GetBool(CInputStream& in); static FourCC GetClassID(CInputStream& in); - static CGenDescription* CreateGeneratorDescription(CInputStream& in, std::vector& tracker, CAssetId resId, - CSimplePool* resPool); + static std::unique_ptr CreateGeneratorDescription(CInputStream& in, std::vector& tracker, + CAssetId resId, CSimplePool* resPool); static bool CreateGPSM(CGenDescription* fillDesc, CInputStream& in, std::vector& tracker, CSimplePool* resPool); static void LoadGPSMTokens(CGenDescription* desc); public: - static CGenDescription* GetGeneratorDesc(CInputStream& in, CSimplePool* resPool); + static std::unique_ptr GetGeneratorDesc(CInputStream& in, CSimplePool* resPool); }; CFactoryFnReturn FParticleFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,