summaryrefslogtreecommitdiffstats
path: root/src/Common/ConfigManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common/ConfigManager.cpp')
-rw-r--r--src/Common/ConfigManager.cpp52
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> > &section) {
+ 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;
}
}