mirror of https://github.com/AxioDL/metaforce.git
CParticleElectricDataFactory: Make GetGeneratorDesc() return a unique_ptr
Same behavior, but with safer memory management.
This commit is contained in:
parent
59bbbdf41c
commit
1f42b9be93
|
@ -13,20 +13,24 @@ static logvisor::Module Log("urde::CParticleElectricDataFactory");
|
||||||
|
|
||||||
using CPF = CParticleDataFactory;
|
using CPF = CParticleDataFactory;
|
||||||
|
|
||||||
CElectricDescription* CParticleElectricDataFactory::GetGeneratorDesc(CInputStream& in, CSimplePool* resPool) {
|
std::unique_ptr<CElectricDescription> CParticleElectricDataFactory::GetGeneratorDesc(CInputStream& in,
|
||||||
|
CSimplePool* resPool) {
|
||||||
return CreateElectricDescription(in, resPool);
|
return CreateElectricDescription(in, resPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
CElectricDescription* CParticleElectricDataFactory::CreateElectricDescription(CInputStream& in, CSimplePool* resPool) {
|
std::unique_ptr<CElectricDescription> CParticleElectricDataFactory::CreateElectricDescription(CInputStream& in,
|
||||||
FourCC cid = CPF::GetClassID(in);
|
CSimplePool* resPool) {
|
||||||
if (cid == FOURCC('ELSM')) {
|
const FourCC cid = CPF::GetClassID(in);
|
||||||
CElectricDescription* desc = new CElectricDescription;
|
|
||||||
CreateELSM(desc, in, resPool);
|
if (cid != FOURCC('ELSM')) {
|
||||||
LoadELSMTokens(desc);
|
return nullptr;
|
||||||
return desc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
auto desc = std::make_unique<CElectricDescription>();
|
||||||
|
CreateELSM(desc.get(), in, resPool);
|
||||||
|
LoadELSMTokens(desc.get());
|
||||||
|
return desc;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CParticleElectricDataFactory::CreateELSM(CElectricDescription* desc, CInputStream& in, CSimplePool* resPool) {
|
bool CParticleElectricDataFactory::CreateELSM(CElectricDescription* desc, CInputStream& in, CSimplePool* resPool) {
|
||||||
|
@ -124,7 +128,6 @@ void CParticleElectricDataFactory::LoadELSMTokens(CElectricDescription* desc) {
|
||||||
CFactoryFnReturn FParticleElectricDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,
|
CFactoryFnReturn FParticleElectricDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,
|
||||||
CObjectReference*) {
|
CObjectReference*) {
|
||||||
CSimplePool* sp = vparms.GetOwnedObj<CSimplePool*>();
|
CSimplePool* sp = vparms.GetOwnedObj<CSimplePool*>();
|
||||||
return TToken<CElectricDescription>::GetIObjObjectFor(
|
return TToken<CElectricDescription>::GetIObjObjectFor(CParticleElectricDataFactory::GetGeneratorDesc(in, sp));
|
||||||
std::unique_ptr<CElectricDescription>(CParticleElectricDataFactory::GetGeneratorDesc(in, sp)));
|
|
||||||
}
|
}
|
||||||
} // namespace urde
|
} // namespace urde
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "Runtime/CFactoryMgr.hpp"
|
#include "Runtime/CFactoryMgr.hpp"
|
||||||
#include "Runtime/CToken.hpp"
|
#include "Runtime/CToken.hpp"
|
||||||
#include "Runtime/IOStreams.hpp"
|
#include "Runtime/IOStreams.hpp"
|
||||||
|
@ -10,12 +12,12 @@ namespace urde {
|
||||||
class CElectricDescription;
|
class CElectricDescription;
|
||||||
class CSimplePool;
|
class CSimplePool;
|
||||||
class CParticleElectricDataFactory {
|
class CParticleElectricDataFactory {
|
||||||
static CElectricDescription* CreateElectricDescription(CInputStream& in, CSimplePool* resPool);
|
static std::unique_ptr<CElectricDescription> CreateElectricDescription(CInputStream& in, CSimplePool* resPool);
|
||||||
static bool CreateELSM(CElectricDescription* desc, CInputStream& in, CSimplePool* resPool);
|
static bool CreateELSM(CElectricDescription* desc, CInputStream& in, CSimplePool* resPool);
|
||||||
static void LoadELSMTokens(CElectricDescription* desc);
|
static void LoadELSMTokens(CElectricDescription* desc);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static CElectricDescription* GetGeneratorDesc(CInputStream& in, CSimplePool* resPool);
|
static std::unique_ptr<CElectricDescription> GetGeneratorDesc(CInputStream& in, CSimplePool* resPool);
|
||||||
};
|
};
|
||||||
|
|
||||||
CFactoryFnReturn FParticleElectricDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,
|
CFactoryFnReturn FParticleElectricDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,
|
||||||
|
|
Loading…
Reference in New Issue