diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2008-10-19 20:35:52 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2008-10-19 20:35:52 +0200 |
commit | 96b6f07a32cb02ae5d907bacd81f62fc25fdc278 (patch) | |
tree | 5f820da31f7e26dc6dba1db0d0347ee5190a6f0e /src/Common/ConfigManager.cpp | |
parent | fa0a978ae129f0f04b9d336e9a3d71489fe519e8 (diff) | |
download | mad-96b6f07a32cb02ae5d907bacd81f62fc25fdc278.tar mad-96b6f07a32cb02ae5d907bacd81f62fc25fdc278.zip |
Neuen ConfigManager angefangen & alten Code daran angepasst
Diffstat (limited to 'src/Common/ConfigManager.cpp')
-rw-r--r-- | src/Common/ConfigManager.cpp | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/src/Common/ConfigManager.cpp b/src/Common/ConfigManager.cpp index 6afeeef..fbd73ea 100644 --- a/src/Common/ConfigManager.cpp +++ b/src/Common/ConfigManager.cpp @@ -18,9 +18,9 @@ */ #include "ConfigManager.h" +#include "Configurable.h" +#include "Logger.h" #include "Util.h" -#include "Backends/SystemBackendProc.h" -#include "Backends/SystemBackendPosix.h" #include <fstream> #include <stdexcept> @@ -28,13 +28,26 @@ namespace Mad { namespace Common { -std::auto_ptr<ConfigManager> ConfigManager::configManager; +ConfigManager ConfigManager::configManager; -bool ConfigManager::loadFile(const std::string &filename) { +void ConfigManager::handleConfigEntry(const std::vector<std::string> &entry, const std::vector<std::vector<std::string> > §ion) { + bool handled = false; + + for(std::set<Configurable*>::iterator c = configurables.begin(); c != configurables.end(); ++c) { + if((*c)->handleConfigEntry(entry, section)) + handled = true; + } + + if(!handled) + Logger::logf(Logger::WARNING, "Unknown config option '%s'.", entry.front().c_str()); +} + +bool ConfigManager::loadFile(const std::string &filename, bool finish) { std::ifstream file(filename.c_str()); - std::vector<std::string> section; - std::string line, key; + std::vector<std::vector<std::string> > section; + std::vector<std::string> entry; + std::string line; if(!file.good()) return false; @@ -48,7 +61,7 @@ bool ConfigManager::loadFile(const std::string &filename) { size_t pos = line.find_first_of('#'); if(pos != std::string::npos) - line[pos] = 0; + line = line.substr(0, pos); line = Util::trim(line); @@ -70,19 +83,24 @@ bool ConfigManager::loadFile(const std::string &filename) { if(!line.empty()) { pos = line.find_first_of(" \t"); + entry.clear(); + if(pos == std::string::npos) { - key = line; - parseLine(section, key); + entry.push_back(line); + + handleConfigEntry(entry, section); } else { - key = line.substr(0, pos); - parseLine(section, key, Util::trim(line.substr(pos))); + entry.push_back(line.substr(0, pos)); + entry.push_back(Util::trim(line.substr(pos))); + + handleConfigEntry(entry, section); } } switch(bracket) { case '{': - section.push_back(key); + section.push_back(entry); break; case '}': section.pop_back(); @@ -93,12 +111,12 @@ bool ConfigManager::loadFile(const std::string &filename) { // TODO Depth check - return true; -} + if(finish) { + for(std::set<Configurable*>::iterator c = configurables.begin(); c != configurables.end(); ++c) + (*c)->configFinished(); + } -void ConfigManager::initBackends() { - Backends::SystemBackendProc::registerBackend(); - Backends::SystemBackendPosix::registerBackend(); + return true; } } |