Update the module create calls to return unique_ptrs

develop
Stoyan Gaydarov 2018-07-08 20:48:39 -07:00
parent 6f90273bb6
commit 38cccdb0f4
6 changed files with 17 additions and 20 deletions

@ -2300,10 +2300,6 @@ int Core::Shutdown ( void )
plug_mgr = 0;
}
// invalidate all modules
for(size_t i = 0 ; i < allModules.size(); i++)
{
delete allModules[i];
}
allModules.clear();
memset(&(s_mods), 0, sizeof(s_mods));
d.reset();
@ -2826,9 +2822,9 @@ TYPE * Core::get##TYPE() \
if(errorstate) return NULL;\
if(!s_mods.p##TYPE)\
{\
Module * mod = create##TYPE();\
s_mods.p##TYPE = (TYPE *) mod;\
allModules.push_back(mod);\
std::unique_ptr<Module> mod = create##TYPE();\
s_mods.p##TYPE = (TYPE *) mod.get();\
allModules.push_back(std::move(mod));\
}\
return s_mods.p##TYPE;\
}

@ -243,7 +243,7 @@ namespace DFHack
Notes * pNotes;
Graphic * pGraphic;
} s_mods;
std::vector <Module *> allModules;
std::vector<std::unique_ptr<Module>> allModules;
DFHack::PluginManager * plug_mgr;
std::vector<std::string> script_paths[2];

@ -27,13 +27,13 @@ distribution.
#ifndef MODULE_FACTORY_H_INCLUDED
#define MODULE_FACTORY_H_INCLUDED
#include <memory>
namespace DFHack
{
class Module;
Module* createGui();
Module* createWorld();
Module* createMaterials();
Module* createNotes();
Module* createGraphic();
std::unique_ptr<Module> createMaterials();
std::unique_ptr<Module> createNotes();
std::unique_ptr<Module> createGraphic();
}
#endif

@ -36,14 +36,15 @@ using namespace std;
#include "Error.h"
#include "VersionInfo.h"
#include "MemAccess.h"
#include "MiscUtils.h"
#include "ModuleFactory.h"
#include "Core.h"
using namespace DFHack;
Module* DFHack::createGraphic()
std::unique_ptr<Module> DFHack::createGraphic()
{
return new Graphic();
return dts::make_unique<Graphic>();
}
struct Graphic::Private

@ -592,12 +592,11 @@ bool DFHack::isStoneInorganic(int material)
return true;
}
Module* DFHack::createMaterials()
std::unique_ptr<Module> DFHack::createMaterials()
{
return new Materials();
return dts::make_unique<Materials>();
}
Materials::Materials()
{
}

@ -33,6 +33,7 @@ using namespace std;
#include "Types.h"
#include "Error.h"
#include "MemAccess.h"
#include "MiscUtils.h"
#include "ModuleFactory.h"
#include "Core.h"
#include "modules/Notes.h"
@ -40,9 +41,9 @@ using namespace std;
#include "df/ui.h"
using namespace DFHack;
Module* DFHack::createNotes()
std::unique_ptr<Module> DFHack::createNotes()
{
return new Notes();
return dts::make_unique<Notes>();
}
// FIXME: not even a wrapper now