Avoided creating blank attributes when doing complete copies.

This commit is contained in:
Guillaume Melquiond 2010-08-06 20:24:59 +00:00
parent 56be6e4513
commit 0bf604f20e
2 changed files with 14 additions and 7 deletions

View file

@ -184,10 +184,9 @@ config::config() : values(), children(), ordered_children()
{
}
config::config(const config& cfg) : values(), children(), ordered_children()
config::config(const config& cfg) : values(cfg.values), children(), ordered_children()
{
cfg.check_valid();
append(cfg);
append_children(cfg);
}
config::config(const std::string& child) : values(), children(), ordered_children()
@ -206,10 +205,9 @@ config& config::operator=(const config& cfg)
return *this;
}
check_valid(cfg);
clear();
append(cfg);
append_children(cfg);
values.insert(cfg.values.begin(), cfg.values.end());
return *this;
}
@ -239,14 +237,18 @@ void config::remove_attribute(const std::string &key)
values.erase(key);
}
void config::append(const config& cfg)
void config::append_children(const config &cfg)
{
check_valid(cfg);
foreach (const any_child &value, cfg.all_children_range()) {
add_child(value.key, value.cfg);
}
}
void config::append(const config &cfg)
{
append_children(cfg);
foreach (const attribute &v, cfg.values) {
values[v.first] = v.second;
}

View file

@ -431,6 +431,11 @@ public:
*/
void append(const config& cfg);
/**
* Adds children from @a cfg.
*/
void append_children(const config &cfg);
/**
* All children with the given key will be merged
* into the first element with that key.