config vconfig::get_parsed_config() const { // Keeps track of insert_tag variables. static std::set<std::string> vconfig_recursion; config res; BOOST_FOREACH(const config::attribute &i, cfg_->attribute_range()) { res[i.first] = expand(i.first); } BOOST_FOREACH(const config::any_child &child, cfg_->all_children_range()) { if (child.key == "insert_tag") { vconfig insert_cfg(child.cfg); const t_string& name = insert_cfg["name"]; const t_string& vname = insert_cfg["variable"]; if(!vconfig_recursion.insert(vname).second) { throw recursion_error("vconfig::get_parsed_config() infinite recursion detected, aborting"); } try { variable_info vinfo(vname, false, variable_info::TYPE_CONTAINER); if(!vinfo.is_valid) { res.add_child(name); //add empty tag } else if(vinfo.explicit_index) { res.add_child(name, vconfig(vinfo.as_container()).get_parsed_config()); } else { variable_info::array_range range = vinfo.as_array(); if(range.first == range.second) { res.add_child(name); //add empty tag } while(range.first != range.second) { res.add_child(name, vconfig(*range.first++).get_parsed_config()); } } vconfig_recursion.erase(vname); } catch(recursion_error &err) { vconfig_recursion.erase(vname); WRN_NG << err.message << std::endl; if(vconfig_recursion.empty()) { res.add_child("insert_tag", insert_cfg.get_config()); } else { // throw to the top [insert_tag] which started the recursion throw; } } } else { res.add_child(child.key, vconfig(child.cfg).get_parsed_config()); } } return res; }
config vconfig::get_parsed_config() const { // Keeps track of insert_tag variables. static std::set<std::string> vconfig_recursion; config res; for (const config::attribute &i : cfg_->attribute_range()) { res[i.first] = expand(i.first); } for (const config::any_child &child : cfg_->all_children_range()) { if (child.key == "insert_tag") { vconfig insert_cfg(child.cfg); const t_string& name = insert_cfg["name"]; const t_string& vname = insert_cfg["variable"]; if(!vconfig_recursion.insert(vname).second) { throw recursion_error("vconfig::get_parsed_config() infinite recursion detected, aborting"); } try { config::const_child_itors range = as_nonempty_range(vname); for (const config& child : range) { res.add_child(name, vconfig(child).get_parsed_config()); } } catch(const invalid_variablename_exception&) { res.add_child(name); } catch(recursion_error &err) { vconfig_recursion.erase(vname); WRN_NG << err.message << std::endl; if(vconfig_recursion.empty()) { res.add_child("insert_tag", insert_cfg.get_config()); } else { // throw to the top [insert_tag] which started the recursion throw; } } vconfig_recursion.erase(vname); } else { res.add_child(child.key, vconfig(child.cfg).get_parsed_config()); } } return res; }