added check to make sure that config file has been loaded before any config variables are accessed
44 lines
892 B
C++
44 lines
892 B
C++
#include <string>
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#include <sstream>
|
|
#include <vector>
|
|
#include <map>
|
|
|
|
#include "yaml-cpp/yaml.h"
|
|
|
|
#include "config.h"
|
|
|
|
Config::Config() {}
|
|
|
|
Config::~Config() {}
|
|
|
|
Config& Config::getInstance() {
|
|
static Config instance;
|
|
return instance;
|
|
}
|
|
|
|
bool Config::loadConfig(const std::string& configFile) {
|
|
configFilePath = configFile;
|
|
try {
|
|
yamlRoot = YAML::LoadFile(configFile);
|
|
} catch (YAML::BadFile& e) {
|
|
std::cerr << "Error: " << e.what() << std::endl;
|
|
return false;
|
|
}
|
|
loaded = true;
|
|
return true;
|
|
}
|
|
|
|
bool Config::isKeyInCache(const std::string &key) {
|
|
return configMap.find(key) != configMap.end();
|
|
}
|
|
|
|
void Config::addToCache(const std::string &key, const YAML::Node &node) {
|
|
configMap[key] = node;
|
|
}
|
|
|
|
void Config::registerUnknownKey(const std::string &key) {
|
|
unknownKeys.push_back(key);
|
|
}
|