Can now unload a Config by config:unload()

This commit is contained in:
BenDol 2014-04-02 02:34:12 +13:00
parent 2d84fae2c8
commit 8b3f3b11f0
4 changed files with 11 additions and 2 deletions

View File

@ -22,6 +22,7 @@
#include "config.h" #include "config.h"
#include "resourcemanager.h" #include "resourcemanager.h"
#include "configmanager.h"
#include <framework/otml/otml.h> #include <framework/otml/otml.h>
@ -54,6 +55,7 @@ bool Config::unload()
if(isLoaded()) { if(isLoaded()) {
m_confsDoc = nullptr; m_confsDoc = nullptr;
m_fileName = ""; m_fileName = "";
g_configs.remove(this);
return true; return true;
} }
return false; return false;
@ -148,7 +150,7 @@ OTMLNodePtr Config::getNode(const std::string& key)
bool Config::isLoaded() bool Config::isLoaded()
{ {
return !m_fileName.empty(); return !m_fileName.empty() && m_confsDoc;
} }
std::string Config::getFileName() std::string Config::getFileName()

View File

@ -117,9 +117,13 @@ bool ConfigManager::unload(const std::string& file)
ConfigPtr config = get(file); ConfigPtr config = get(file);
if(config) { if(config) {
config->unload(); config->unload();
m_configs.remove(config);
config = nullptr; config = nullptr;
return true; return true;
} }
return false; return false;
} }
void ConfigManager::remove(const ConfigPtr config)
{
m_configs.remove(config);
}

View File

@ -38,7 +38,9 @@ public:
ConfigPtr create(const std::string& file); ConfigPtr create(const std::string& file);
ConfigPtr loadSettings(const std::string file); ConfigPtr loadSettings(const std::string file);
ConfigPtr load(const std::string& file); ConfigPtr load(const std::string& file);
bool unload(const std::string& file); bool unload(const std::string& file);
void remove(const ConfigPtr config);
protected: protected:
ConfigPtr m_settings; ConfigPtr m_settings;

View File

@ -194,6 +194,7 @@ void Application::registerLuaFunctions()
// Config // Config
g_lua.registerClass<Config>(); g_lua.registerClass<Config>();
g_lua.bindClassMemberFunction<Config>("save", &Config::save); g_lua.bindClassMemberFunction<Config>("save", &Config::save);
g_lua.bindClassMemberFunction<Config>("unload", &Config::unload);
g_lua.bindClassMemberFunction<Config>("setValue", &Config::setValue); g_lua.bindClassMemberFunction<Config>("setValue", &Config::setValue);
g_lua.bindClassMemberFunction<Config>("setList", &Config::setList); g_lua.bindClassMemberFunction<Config>("setList", &Config::setList);
g_lua.bindClassMemberFunction<Config>("getValue", &Config::getValue); g_lua.bindClassMemberFunction<Config>("getValue", &Config::getValue);