From 96b6f07a32cb02ae5d907bacd81f62fc25fdc278 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 19 Oct 2008 20:35:52 +0200 Subject: Neuen ConfigManager angefangen & alten Code daran angepasst --- src/Common/ConfigManager.cpp | 52 +++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 17 deletions(-) (limited to 'src/Common/ConfigManager.cpp') 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 #include @@ -28,13 +28,26 @@ namespace Mad { namespace Common { -std::auto_ptr ConfigManager::configManager; +ConfigManager ConfigManager::configManager; -bool ConfigManager::loadFile(const std::string &filename) { +void ConfigManager::handleConfigEntry(const std::vector &entry, const std::vector > §ion) { + bool handled = false; + + for(std::set::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 section; - std::string line, key; + std::vector > section; + std::vector 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::iterator c = configurables.begin(); c != configurables.end(); ++c) + (*c)->configFinished(); + } -void ConfigManager::initBackends() { - Backends::SystemBackendProc::registerBackend(); - Backends::SystemBackendPosix::registerBackend(); + return true; } } -- cgit v1.2.3