38 Config& Config::getInstance() {
39 static Config instance;
43 bool Config::loadConfig(
const std::string& configFile) {
44 configFilePath = configFile;
46 yamlRoot = YAML::LoadFile(configFile);
47 }
catch (YAML::BadFile& e) {
48 std::cerr <<
"Error: " << e.what() << std::endl;
55 bool Config::isKeyInCache(
const std::string &key) {
56 return configMap.find(key) != configMap.end();
59 void Config::addToCache(
const std::string &key,
const YAML::Node &node) {
60 configMap[key] = node;
63 void Config::registerUnknownKey(
const std::string &key) {
64 unknownKeys.push_back(key);
67 bool Config::has(
const std::string &key) {
69 throw std::runtime_error(
"Error! Config file not loaded");
71 if (isKeyInCache(key)) {
return true; }
73 YAML::Node node = YAML::Clone(yamlRoot);
74 std::istringstream keyStream(key);
76 while (std::getline(keyStream, subKey,
':')) {
78 registerUnknownKey(key);
85 addToCache(key, node);
89 void recurse_keys(
const YAML::Node& node, std::vector<std::string>& keyList,
const std::string& path =
"") {
91 for (
const auto& it : node) {
92 auto key = it.first.as<std::string>();
93 auto new_path = path.empty() ? key : path +
":" + key;
97 keyList.push_back(path);
102 std::vector<std::string> Config::keys()
const {
103 std::vector<std::string> keyList;
104 YAML::Node node = YAML::Clone(yamlRoot);