bool config::matches(const config &filter) const { check_valid(filter); for (const attribute &i : filter.attribute_range()) { const attribute_value *v = get(i.first); if (!v || *v != i.second) return false; } for (const any_child &i : filter.all_children_range()) { if (i.key == "not") { if (matches(i.cfg)) return false; continue; } bool found = false; for (const config &j : child_range(i.key)) { if (j.matches(i.cfg)) { found = true; break; } } if(!found) return false; } return true; }
void config::merge_children(const std::string& key) { check_valid(); if (child_count(key) < 2) return; config merged_children; for (const config &cfg : child_range(key)) { merged_children.append(cfg); } clear_children(key); add_child(key,merged_children); }
void config::merge_children_by_attribute(const std::string& key, const std::string& attribute) { check_valid(); if (child_count(key) < 2) return; typedef std::map<std::string, config> config_map; config_map merged_children_map; for (const config &cfg : child_range(key)) { merged_children_map[cfg[attribute]].append(cfg); } clear_children(key); for (const config_map::value_type &i : merged_children_map) { add_child(key,i.second); } }
void config::merge_children_by_attribute(const std::string& key, const std::string& attribute) { check_valid(); if (child_count(key) < 2) return; typedef std::map<std::string, config> config_map; config_map merged_children_map; for (const config &cfg : child_range(key)) { const std::string &value = cfg[attribute]; config_map::iterator m = merged_children_map.find(value); if ( m!=merged_children_map.end() ) { m->second.append(cfg); } else { merged_children_map.insert(make_pair(value, cfg)); } } clear_children(key); for (const config_map::value_type &i : merged_children_map) { add_child(key,i.second); } }