Skip to content

Commit

Permalink
#5200: ModuleRegistry takes the IApplicationContext ref in its constr…
Browse files Browse the repository at this point in the history
…uctor, to replace the unnecessary raw pointer.
  • Loading branch information
codereader committed Aug 22, 2020
1 parent aa95088 commit 87c62e8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
3 changes: 1 addition & 2 deletions radiantcore/Radiant.cpp
Expand Up @@ -31,8 +31,7 @@ Radiant::Radiant(IApplicationContext& context) :
// Attach the logfile to the logwriter
createLogFile();

_moduleRegistry.reset(new module::ModuleRegistry);
_moduleRegistry->setContext(_context);
_moduleRegistry.reset(new module::ModuleRegistry(_context));

_languageManager.reset(new language::LanguageManager);
#if 0
Expand Down
14 changes: 6 additions & 8 deletions radiantcore/modulesystem/ModuleRegistry.cpp
Expand Up @@ -12,10 +12,10 @@
namespace module
{

ModuleRegistry::ModuleRegistry() :
ModuleRegistry::ModuleRegistry(const IApplicationContext& ctx) :
_context(ctx),
_modulesInitialised(false),
_modulesShutdown(false),
_context(nullptr),
_loader(new ModuleLoader(*this))
{
rMessage() << "ModuleRegistry instantiated." << std::endl;
Expand Down Expand Up @@ -126,8 +126,7 @@ void ModuleRegistry::initialiseModuleRecursive(const std::string& name)
_progress);

// Initialise the module itself, now that the dependencies are ready
assert(_context);
module->initialiseModule(*_context);
module->initialiseModule(_context);
}

void ModuleRegistry::initialiseCoreModule()
Expand All @@ -145,7 +144,7 @@ void ModuleRegistry::initialiseCoreModule()
// We assume that the core module doesn't have any dependencies
assert(moduleIter->second->getDependencies().empty());

moduleIter->second->initialiseModule(*_context);
moduleIter->second->initialiseModule(_context);

_uninitialisedModules.erase(coreModuleName);
}
Expand All @@ -162,7 +161,7 @@ void ModuleRegistry::loadAndInitialiseModules()
rMessage() << "ModuleRegistry Compatibility Level is " << getCompatibilityLevel() << std::endl;

// Invoke the ModuleLoad routine to load the DLLs from modules/ and plugins/
_loader->loadModules(_context->getLibraryPath());
_loader->loadModules(_context.getLibraryPath());

_progress = 0.1f;
_sigModuleInitialisationProgress.emit(_("Initialising Modules"), _progress);
Expand Down Expand Up @@ -239,8 +238,7 @@ RegisterableModulePtr ModuleRegistry::getModule(const std::string& name) const {

const IApplicationContext& ModuleRegistry::getApplicationContext() const
{
assert(_context);
return *_context;
return _context;
}

applog::ILogWriter& ModuleRegistry::getApplicationLogWriter()
Expand Down
13 changes: 4 additions & 9 deletions radiantcore/modulesystem/ModuleRegistry.h
Expand Up @@ -20,6 +20,9 @@ class ModuleRegistry :
public IModuleRegistry
{
private:
// application context
const IApplicationContext& _context;

typedef std::map<std::string, RegisterableModulePtr> ModulesMap;

// This is where the uninitialised modules go after registration
Expand All @@ -34,9 +37,6 @@ class ModuleRegistry :
// Set to TRUE after all modules have been shutdown
bool _modulesShutdown;

// Pointer to the application context
IApplicationContext* _context;

// For progress meter in the splash screen
float _progress;

Expand All @@ -50,7 +50,7 @@ class ModuleRegistry :
std::unique_ptr<ModuleLoader> _loader;

public:
ModuleRegistry();
ModuleRegistry(const IApplicationContext& ctx);

~ModuleRegistry();

Expand Down Expand Up @@ -81,11 +81,6 @@ class ModuleRegistry :

std::size_t getCompatibilityLevel() const override;

void setContext(IApplicationContext& context)
{
_context = &context;
}

// Returns a list of modules
std::string getModuleList(const std::string& separator = "\n");

Expand Down

0 comments on commit 87c62e8

Please sign in to comment.