Avoided creating blank attributes when doing complete copies.
This commit is contained in:
parent
56be6e4513
commit
0bf604f20e
2 changed files with 14 additions and 7 deletions
|
@ -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_children(cfg);
|
||||||
append(cfg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
config::config(const std::string& child) : values(), children(), ordered_children()
|
config::config(const std::string& child) : values(), children(), ordered_children()
|
||||||
|
@ -206,10 +205,9 @@ config& config::operator=(const config& cfg)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
check_valid(cfg);
|
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
append(cfg);
|
append_children(cfg);
|
||||||
|
values.insert(cfg.values.begin(), cfg.values.end());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,14 +237,18 @@ void config::remove_attribute(const std::string &key)
|
||||||
values.erase(key);
|
values.erase(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void config::append(const config& cfg)
|
void config::append_children(const config &cfg)
|
||||||
{
|
{
|
||||||
check_valid(cfg);
|
check_valid(cfg);
|
||||||
|
|
||||||
foreach (const any_child &value, cfg.all_children_range()) {
|
foreach (const any_child &value, cfg.all_children_range()) {
|
||||||
add_child(value.key, value.cfg);
|
add_child(value.key, value.cfg);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void config::append(const config &cfg)
|
||||||
|
{
|
||||||
|
append_children(cfg);
|
||||||
foreach (const attribute &v, cfg.values) {
|
foreach (const attribute &v, cfg.values) {
|
||||||
values[v.first] = v.second;
|
values[v.first] = v.second;
|
||||||
}
|
}
|
||||||
|
|
|
@ -431,6 +431,11 @@ public:
|
||||||
*/
|
*/
|
||||||
void append(const config& cfg);
|
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
|
* All children with the given key will be merged
|
||||||
* into the first element with that key.
|
* into the first element with that key.
|
||||||
|
|
Loading…
Add table
Reference in a new issue