/ * Load configuration from file in YAML format * * \param [in] cfg_filename Yaml configuration filename ***********************************************************************/
| 82 | * \param [in] cfg_filename Yaml configuration filename |
| 83 | ***********************************************************************/ |
| 84 | void Config::load(const char *cfg_filename) { |
| 85 | |
| 86 | if (debug_general) |
| 87 | std::cout << "---| Loading configuration file |----------------------------- " << std::endl; |
| 88 | |
| 89 | try { |
| 90 | YAML::Node root = YAML::LoadFile(cfg_filename); |
| 91 | |
| 92 | /* |
| 93 | * Iterate through the root node objects - We expect only maps at the root level, skip others |
| 94 | */ |
| 95 | if (root.Type() == YAML::NodeType::Map) { |
| 96 | for (YAML::const_iterator it = root.begin(); it != root.end(); ++it) { |
| 97 | const YAML::Node &node = it->second; |
| 98 | const std::string &key = it->first.Scalar(); |
| 99 | |
| 100 | if (node.Type() == YAML::NodeType::Map) { |
| 101 | if (key.compare("base") == 0) |
| 102 | parseBase(node); |
| 103 | else if (key.compare("debug") == 0) |
| 104 | parseDebug(node); |
| 105 | else if (key.compare("kafka") == 0) |
| 106 | parseKafka(node); |
| 107 | else if (key.compare("mapping") == 0) |
| 108 | parseMapping(node); |
| 109 | |
| 110 | else if (debug_general) |
| 111 | std::cout << " Config: Key " << key << " Type " << node.Type() << std::endl; |
| 112 | } |
| 113 | else { |
| 114 | printWarning("configuration should only have maps at the root/base level found", node); |
| 115 | } |
| 116 | } |
| 117 | } else { |
| 118 | printWarning("configuration should only have maps at the root/base level found", root); |
| 119 | |
| 120 | } |
| 121 | |
| 122 | } catch (YAML::BadFile err) { |
| 123 | throw err.what(); |
| 124 | } catch (YAML::ParserException err) { |
| 125 | throw err.what(); |
| 126 | } catch (YAML::InvalidNode err) { |
| 127 | throw err.what(); |
| 128 | } |
| 129 | |
| 130 | if (debug_general) |
| 131 | std::cout << "---| Done Loading configuration file |------------------------- " << std::endl; |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Parse the base configuration |